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 0000000..68518e3 --- /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 0000000..09c5890 --- /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;