Make factory name mandatory #4372
Labels
kind/bug
Outline of a bug - must adhere to the bug report template.
status/open-for-dev
An issue has had its specification reviewed and confirmed. Waiting for an engineer to take it.
The problem
For each factory e.g.
the combination of
factory.name
+factory.creator.userId
must be unique, so the factorymay be accepted as
/<namespace>/<factory-name>
where the namespace is the name of the user who is the creator of the factory.Those factories which don't have name, cannot be accepted in the format described above.
Right now multiple factories with the same name may exist, as the unique constraint is missing.
In this case the first factory returned from factory service will be used.
The actual problem here is that the unique constraint like this requires partial unique index, which is not a common feature of database systems. It could look like this:
While it works for PostgreSQL it doesn't for H2.
Proposed solution
Make factory name mandatory on database level + add a unique constraint on (user_id, name).
Each time factory service receives a factory without name it must set its name to some value e.g. factory id or generate a new factory name, so in this way clients are still not required to send factory name so everything works like before
For those factories in database that don't have name create a migration script that sets names equal to factory ids(or the values generated by the same principle as the values set by service) e.g:
⬇️ becomes ⬇️
For those factories in database that have duplicated name + user_id create a migration script that
leaves the very first factory with such a name as it is and modifies all the other factories in a way defined by the script from the previous statement. So the factories with such a name are accepted as they were(the first one) e.g:
⬇️ becomes ⬇️
The text was updated successfully, but these errors were encountered: