Cascading
This commit is contained in:
parent
d2eac68638
commit
038b83e530
2 changed files with 3 additions and 3 deletions
|
@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS posts (
|
||||||
content TEXT NOT NULL,
|
content TEXT NOT NULL,
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (user_id) REFERENCES users (id)
|
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Create a function to set created_at and updated_at on INSERT
|
-- Create a function to set created_at and updated_at on INSERT
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
CREATE TABLE IF NOT EXISTS engagements (
|
CREATE TABLE IF NOT EXISTS engagements (
|
||||||
user_id BIGINT NOT NULL,
|
user_id BIGINT NOT NULL,
|
||||||
post_id BIGINT NOT NULL,
|
post_id BIGINT NOT NULL,
|
||||||
FOREIGN KEY (user_id) REFERENCES users (id),
|
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
|
||||||
FOREIGN KEY (post_id) REFERENCES posts (id),
|
FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE,
|
||||||
PRIMARY KEY (user_id, post_id)
|
PRIMARY KEY (user_id, post_id)
|
||||||
);
|
);
|
Loading…
Reference in a new issue