Skip to content

Add support for ON DELETE SET DEFAULT #677

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

Merged
merged 2 commits into from
Jun 24, 2025

Conversation

makmn1
Copy link
Contributor

@makmn1 makmn1 commented Jun 22, 2025

Follow up to a discussion and pull requests #474 and #475

This pull request adds support for the SET DEFAULT action for ON DELETE on a foreign key constraint. It's similar to the current :nilify_all and {:nilify, columns} options, but for setting the column values to their default values. Additionally, database support is different between each of the three supported databases:

Database SET DEFAULT – all columns SET DEFAULT – partial columns
PostgreSQL ✔️ ✔️
MySQL / MariaDB ✖️ ✖️
SQL Server (MSSQL) ✔️ ✖️

Sources for SET DEFAULT behavior

@greg-rychlewski
Copy link
Member

@makmn1 Thanks very much for the PR. Would you be able to add default_all unit tests for TDS?

@makmn1 makmn1 force-pushed the on_delete_default branch from 6609d5d to d1a399c Compare June 24, 2025 03:27
@makmn1
Copy link
Contributor Author

makmn1 commented Jun 24, 2025

Good catch, I added those missing tests and also updated the PG unit test for testing default_all with a composite key

@warmwaffles
Copy link
Member

I didn't know this feature existed in postgres. I don't think it exists in sqlite. If this is added, I'll need to update the adapter to raise an error that is easy to understand.

@makmn1
Copy link
Contributor Author

makmn1 commented Jun 24, 2025

@warmwaffles It looks like it does exist in SQLite, but you can't choose columns (so similar to how MSSQL supports)

@greg-rychlewski greg-rychlewski merged commit 701c99e into elixir-ecto:master Jun 24, 2025
11 checks passed
@greg-rychlewski
Copy link
Member

Thanks for adding this :)

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

Successfully merging this pull request may close these issues.

4 participants