Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define unique primary keys in SQL / SQLAlchemy generator #108

Open
Aran30 opened this issue Aug 26, 2024 · 4 comments
Open

Define unique primary keys in SQL / SQLAlchemy generator #108

Aran30 opened this issue Aug 26, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Aran30
Copy link
Collaborator

Aran30 commented Aug 26, 2024

Currently, the default primary key will always be an auto-generated ID. There is no possibility to set other attributes as primary key.

@Aran30 Aran30 added the enhancement New feature or request label Aug 26, 2024
@Aran30 Aran30 self-assigned this Aug 26, 2024
@Aran30
Copy link
Collaborator Author

Aran30 commented Aug 27, 2024

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?

@Aran30
Copy link
Collaborator Author

Aran30 commented Aug 27, 2024

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?

@ivan-alfonso
Copy link
Collaborator

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:

  1. Currently an OCL constraint could be written to specify the attributes that are unique to a class. For example,
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.

  1. 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).

  2. 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.

@jcabot
Copy link
Collaborator

jcabot commented Aug 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants