From f0d6b9d1e891885ee333158548987489b488022e Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Tue, 26 Mar 2019 08:57:46 +0100 Subject: [PATCH] Fix issue with sqlite migrations for comment_seers (#503) --- .../2019-03-25-205630_fix-comment-seers/down.sql | 15 +++++++++++++++ .../2019-03-25-205630_fix-comment-seers/up.sql | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 migrations/sqlite/2019-03-25-205630_fix-comment-seers/down.sql create mode 100644 migrations/sqlite/2019-03-25-205630_fix-comment-seers/up.sql diff --git a/migrations/sqlite/2019-03-25-205630_fix-comment-seers/down.sql b/migrations/sqlite/2019-03-25-205630_fix-comment-seers/down.sql new file mode 100644 index 00000000..68518e3a --- /dev/null +++ b/migrations/sqlite/2019-03-25-205630_fix-comment-seers/down.sql @@ -0,0 +1,15 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE comment_seers RENAME TO tmp_comment_seers; + +CREATE TABLE comment_seers ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + comment_id INTEGER REFERENCES comments(id) ON DELETE CASCADE NOT NULL, + user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL, + UNIQUE (comment_id, user_id) +); + +INSERT INTO comment_seers(id, comment_id, user_id) +SELECT id, comment_id, user_id +FROM tmp_comment_seers; + +DROP TABLE tmp_comment_seers; diff --git a/migrations/sqlite/2019-03-25-205630_fix-comment-seers/up.sql b/migrations/sqlite/2019-03-25-205630_fix-comment-seers/up.sql new file mode 100644 index 00000000..09c5890f --- /dev/null +++ b/migrations/sqlite/2019-03-25-205630_fix-comment-seers/up.sql @@ -0,0 +1,16 @@ +-- Your SQL goes here +ALTER TABLE comment_seers RENAME TO tmp_comment_seers; + +CREATE TABLE comment_seers ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + comment_id INTEGER REFERENCES comments(id) ON DELETE CASCADE NOT NULL, + user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL, + UNIQUE (comment_id, user_id) +); + +INSERT INTO comment_seers(id, comment_id, user_id) +SELECT id, comment_id, user_id +FROM tmp_comment_seers +WHERE id NOT NULL; + +DROP TABLE tmp_comment_seers;