Feature request: dbm-gorm-diff support database cascading delete on foreign keys
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
grails 2.5.4
compile "org.grails.plugins:spring-security-core:2.0.0"
runtime ":database-migration:1.4.1"
compile ":postgresql-extensions:4.6.1"
postgres 9.4
ubuntu 14.04
java 8.77
Given the default User and UserRole created by spring security quickstart.
Given the inital user_role table generated by dbm-gorm-diff is:
CREATE TABLE user_role
(
user_id bigint NOT NULL,
role_id bigint NOT NULL,
date_created timestamp with time zone NOT NULL,
last_updated timestamp with time zone NOT NULL,
CONSTRAINT "user_rolePK" PRIMARY KEY (user_id, role_id),
CONSTRAINT "FK_apcc8lxk2xnug8377fatvbn04" FOREIGN KEY (user_id)
REFERENCES users (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "FK_it77eq964jhfqtu54081ebtio" FOREIGN KEY (role_id)
REFERENCES role (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE user_role
OWNER TO postgres;
I want UserRole to be deleted by cascade when user is deleted.
to UserRole.groovy, I added:
static belongsTo = [user: User]
to User.groovy, I added hasMany and an explicit cascade.
```
static hasMany = [userRoles:UserRole]
static mapping = {
table 'users'
password column: '`password`'
userRoles cascade: 'delete'
}
```
When I run dbm-gorm-diff after making those changes to the domain classes, I would like a way for the tool to optionally provide a migration to add the cascade to the foreign key constraint.
Contributor guide
Research direction
Start by locating the dbm-gorm-diff entry point that compares GORM domain mappings and generates migrations, then trace how PostgreSQL foreign-key constraints are emitted. Use the UserRole.groovy and User.groovy mappings and the shown user_role schema as the expected input and output; done means an optional migration can add the delete cascade.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, postgresql
- Domain
- databases, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100