Open Aran30 opened 3 weeks ago
Beyond primary keys, there is currently no possibility to set attributes as unique (without them being a primary key). The question is, should B-UML support setting properties as unique, even setting combination of properties as unique?
UML and B-UML support the setting of attributes as "ID", yet there does not seem to be a differentiation between unique and Primary Key like in SQL. Should our DB generators just treat B-UML's "ID" as unique and always create an integer primary key? (Setting anything besides an integer as primary key does not seem to be best practice) @jcabot @ivan-alfonso any thoughts?
I can think of three solutions for dealing with unique fields in these generators, but I'm not sure which one is most efficient for this case:
context Person
inv UniqueDNI: Person.allInstances()->isUnique(dni)
Then the code generator would have to take as input the list of OCL constraints, and process them.
Another solution would be to add the boolean parameter is_unique
to the Property class of our B-UML metamodel. But I don't know if it is worth it just for this property that would be used by some code generators (the UML specification does not consider this attribute in the way we are describing it).
You could also send to the code generator a dictionary specifying which attributes are unique, and modify the code generator to process this dictionary when the user needs to define unique attributes in the DB.
Honestly, while I agree our solution is not ideal (as we can only indicate the pk and not other unique keys) , I think it's enough for now. This is one of those things that if there is anybody really interested they could easily contribute
Currently, the default primary key will always be an auto-generated ID. There is no possibility to set other attributes as primary key.