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

implement on-delete Attribute from models.yml in geneation of relational db-schema #2518

Open
r-peschke opened this issue Jul 10, 2024 · 0 comments

Comments

@r-peschke
Copy link
Member

r-peschke commented Jul 10, 2024

There exists the attribute on_delete in the models.yml. It's definition, extracted from models.yml:

 - on_delete: This fields determines what should happen with the foreign model if this model gets deleted. Possible values are:
      - SET_NULL (default): delete the id from the foreign key
      - PROTECT: if the foreign key is not empty, throw an error instead of deleting the object
      - CASCADE: also delete all models in this foreign key

The execution is implemented in the openslides-backend code. A relation without explicit on_delete use the default value SET_NULL.

Migration to the relational DB:

  1. Excecution will be done by the postgres-database
  2. On postgres the directive ON DELETE is used in a foreign key definition and it determines, what happens with the model itself if the referenced model gets deleted
  3. Possible values see https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-FK
  4. Default value is NO ACTION, preventing the deletion of the referenced model and allows the check to be deferred until later in the transaction

Decision to take:
Naming and positioning of the on delete in the models.yml.
Option 1: models.yml stay unchanged and we transform the value only in the generation of the sql schema
Option 2: we replace the on delete and use it with the postgres definition, including postgres default NO ACTION (correspond to old PROTECT)

IMO we should go with option 2. The postgres definition is more universal and documented than the openslides definition. Additionally there are more options available in the postgres definition.
Disadvantage: Think about and change a lot in the models.yml

10.07.24 13:45: Decision for option 2 taken by Raimund, Danny, Ralf

@r-peschke r-peschke added this to the 4.2 milestone Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant