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

DELETE CASCADE on Foreign Keys #4555

Open
hannosgit opened this issue Feb 25, 2024 · 6 comments
Open

DELETE CASCADE on Foreign Keys #4555

hannosgit opened this issue Feb 25, 2024 · 6 comments

Comments

@hannosgit
Copy link

hannosgit commented Feb 25, 2024

Current Behaviour

The current implementation to delete job instances or job executions issues a separate SQL statement for each metadata table. (see #4497)

Suggested Change

If we define the DELETE CASCADE option on each Foreign Key in the metadata table, we could remove all metadata by simply deleting the desired table row and the database will take care of the rest.
As far as I can see each supported database supports the DELETE CASCADE option

@mayleaf
Copy link

mayleaf commented May 5, 2024

I made a new PR! #4584
PTAL when you have time 🙇

@hannosgit
Copy link
Author

@mayleaf Are you sure that all databases support the DELETE CASCADE option? For example, I am not sure if Sybase does.

@mayleaf
Copy link

mayleaf commented May 7, 2024

As far as I had found, there was ON DELETE option. But I confused ASE and IQ. As you said, It seems doesn't support ON DELETE on sybase. Then how about add delete trigger for those DBMSs that doesn't support delete cascade? @hannosgit @fmbenhassine

@hannosgit
Copy link
Author

@mayleaf One option would be to create a new separate method in JobRepository that only deletes the job instance and lets the DB do the rest. Developers that use DBs that do not support ON DELETE CASCADE and developers that do not define the DELETE CASCADE can use the existing methods that delete the data on the Java side. All other developers can use the new method.

@mayleaf
Copy link

mayleaf commented May 9, 2024

@hannosgit There is already a JobRepository.deleteJobInstance() method. I thought the positive effect of this PR was that it simplifies the SimpleJobRepository implementation, not changes the JobRepository interface. There is no need to create a duplicated signature. If I misunderstood your opinion, please let me know 🙇

@hannosgit
Copy link
Author

Yeah that was the idea but if we cannot come up with a solution for these DBs, we have to live with some kind of workaround such as the one I suggested. I have no experience/access with e.g. Sybase, so I cannot help with this. I found this workaround of using triggers to simulate ON DELETE CASCADE but I cannot verify it.

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

3 participants