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

Support for ForeignKeyConstraint with ON UPDATE/DELETE CASCADE #126

Open
dr-rodriguez opened this issue Dec 17, 2024 · 2 comments
Open

Support for ForeignKeyConstraint with ON UPDATE/DELETE CASCADE #126

dr-rodriguez opened this issue Dec 17, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@dr-rodriguez
Copy link

While testing the design of some schemas, I noticed that any Foreign Keys get saved without UPDATE/DELETE CASCADE specifications. That's probably fine in most cases, but there are situations where having that can be useful.
Is that something that is supported but not documented? Or perhaps it's something that is beyond the scope of this package?

Example:

  - name: Names
    "@id": "#Names"
    description: "Additional identifiers for objects in Sources table"
    primaryKey:
    - "#Names.id"
    - "#Names.name"

    columns:
    - name: id
      "@id": "#Names.id"
      datatype: long
      description: Main identifier for an object; links to Sources table
      nullable: false
    - name: name
      "@id": "#Names.name"
      datatype: string
      length: 100
      description: Identifier for source
      nullable: false

    constraints:
      - name: Names_id_Sources_id
        "@type": "ForeignKey"
        "@id": "#FK_Names_id_Source_id"
        description: Link Names to Sources table
        columns:
        - "#Names.id"
        referencedColumns:
        - "#Sources.id"

produces Postgres sql of the form:

CREATE TABLE exomast."Names" (
	id BIGINT NOT NULL, 
	name VARCHAR(100) NOT NULL, 
	PRIMARY KEY (id, name), 
	CONSTRAINT "Names_id_Sources_id" FOREIGN KEY(id) REFERENCES exomast."Sources" (id)
)

;
COMMENT ON TABLE exomast."Names" IS 'Additional identifiers for objects in Sources table';
COMMENT ON COLUMN exomast."Names".id IS 'Main identfier for an object; links to Sources table';
COMMENT ON COLUMN exomast."Names".name IS 'Identifier for source';
COMMENT ON CONSTRAINT "Names_id_Sources_id" ON exomast."Names" IS 'Link Names to Sources table';

But I would have wanted the foreign key to be something like:

CONSTRAINT "Names_id_Sources_id" FOREIGN KEY(id) REFERENCES exomast."Sources" (id) ON DELETE CASCADE 

so that if I delete the entry from Sources all of its references in Names are deleted.

@JeremyMcCormick JeremyMcCormick self-assigned this Dec 18, 2024
@JeremyMcCormick JeremyMcCormick added the enhancement New feature or request label Dec 18, 2024
@JeremyMcCormick
Copy link
Collaborator

This seems like a feature that could be added for Postgres and MySQL backends. I will make a ticket in our Jira for it.

@JeremyMcCormick
Copy link
Collaborator

JeremyMcCormick commented Dec 18, 2024

Added DM-48204

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

2 participants