Skip to content

Feature request: dbm-gorm-diff support database cascading delete on foreign keys #14482

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

Open
edwardotis opened this issue Apr 26, 2016 · 0 comments

Comments

@edwardotis
Copy link

edwardotis commented Apr 26, 2016

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.

@edwardotis edwardotis changed the title dbm-gorm-diff not picking up addition of cascade delete Feature request: dbm-gorm-diff support database cascading delete on foreign keys May 18, 2016
@jameskleeh jameskleeh added the type: enhancement New feature or request label Jul 15, 2016
@jdaugherty jdaugherty transferred this issue from grails/grails-database-migration Feb 20, 2025
@jdaugherty jdaugherty removed the type: enhancement New feature or request label Feb 20, 2025
@jdaugherty jdaugherty transferred this issue from grails/grails-data-hibernate5 Mar 13, 2025
@jdaugherty jdaugherty transferred this issue from apache/grails-data-mapping Apr 22, 2025
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