diff --git a/server/migrations/0002_posts_table.sql b/server/migrations/0002_posts_table.sql index 2ab5280..59edafa 100644 --- a/server/migrations/0002_posts_table.sql +++ b/server/migrations/0002_posts_table.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS posts ( content TEXT NOT NULL, created_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 diff --git a/server/migrations/0005_engagements_table.sql b/server/migrations/0005_engagements_table.sql index 9b65696..3e6960f 100644 --- a/server/migrations/0005_engagements_table.sql +++ b/server/migrations/0005_engagements_table.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS engagements ( user_id BIGINT NOT NULL, post_id BIGINT NOT NULL, - FOREIGN KEY (user_id) REFERENCES users (id), - FOREIGN KEY (post_id) REFERENCES posts (id), + FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE, + FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE, PRIMARY KEY (user_id, post_id) ); \ No newline at end of file