Fix issue with sqlite migrations for comment_seers (#503)

This commit is contained in:
Valentin Brandl 2019-03-26 08:57:46 +01:00 committed by Igor Galić
parent 21cb0ef437
commit f0d6b9d1e8
2 changed files with 31 additions and 0 deletions

View File

@ -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;

View File

@ -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;