From aa72334dc6b15c97c156e2e2395112dccb04b912 Mon Sep 17 00:00:00 2001 From: fdb-hiroshima <35889323+fdb-hiroshima@users.noreply.github.com> Date: Sat, 5 Jan 2019 22:11:54 +0100 Subject: [PATCH] Allow for media cover deletion (#387) * Allow for media cover deletion Fix #356 * Fix sqlite migrations --- .../down.sql | 4 ++++ .../up.sql | 4 ++++ .../down.sql | 21 +++++++++++++++++++ .../up.sql | 21 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 migrations/postgres/2018-12-25-164502_media-cover-deletion/down.sql create mode 100644 migrations/postgres/2018-12-25-164502_media-cover-deletion/up.sql create mode 100644 migrations/sqlite/2018-12-25-164502_media-cover-deletion/down.sql create mode 100644 migrations/sqlite/2018-12-25-164502_media-cover-deletion/up.sql diff --git a/migrations/postgres/2018-12-25-164502_media-cover-deletion/down.sql b/migrations/postgres/2018-12-25-164502_media-cover-deletion/down.sql new file mode 100644 index 00000000..9189e206 --- /dev/null +++ b/migrations/postgres/2018-12-25-164502_media-cover-deletion/down.sql @@ -0,0 +1,4 @@ +-- This file should undo anything in `up.sql` + +ALTER TABLE posts DROP CONSTRAINT posts_cover_id_fkey; +ALTER TABLE posts ADD CONSTRAINT posts_cover_id_fkey FOREIGN KEY (cover_id) REFERENCES medias(id); diff --git a/migrations/postgres/2018-12-25-164502_media-cover-deletion/up.sql b/migrations/postgres/2018-12-25-164502_media-cover-deletion/up.sql new file mode 100644 index 00000000..414e92e6 --- /dev/null +++ b/migrations/postgres/2018-12-25-164502_media-cover-deletion/up.sql @@ -0,0 +1,4 @@ +-- Your SQL goes here + +ALTER TABLE posts DROP CONSTRAINT posts_cover_id_fkey; +ALTER TABLE posts ADD CONSTRAINT posts_cover_id_fkey FOREIGN KEY (cover_id) REFERENCES medias(id) ON DELETE SET NULL; diff --git a/migrations/sqlite/2018-12-25-164502_media-cover-deletion/down.sql b/migrations/sqlite/2018-12-25-164502_media-cover-deletion/down.sql new file mode 100644 index 00000000..9c86ec67 --- /dev/null +++ b/migrations/sqlite/2018-12-25-164502_media-cover-deletion/down.sql @@ -0,0 +1,21 @@ +-- This file should undo anything in `up.sql` + +CREATE TABLE posts2 ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + blog_id INTEGER REFERENCES blogs(id) ON DELETE CASCADE NOT NULL, + slug VARCHAR NOT NULL, + title VARCHAR NOT NULL, + content TEXT NOT NULL DEFAULT '', + published BOOLEAN NOT NULL DEFAULT 'f', + license VARCHAR NOT NULL DEFAULT 'CC-BY-SA', + creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + ap_url VARCHAR NOT NULL DEFAULT '' UNIQUE, + subtitle TEXT NOT NULL DEFAULT '', + source TEXT NOT NULL DEFAULT '', + cover_id INTEGER REFERENCES medias(id) DEFAULT NULL, + CONSTRAINT blog_authors_unique UNIQUE (blog_id, slug) +); + +INSERT INTO posts2 SELECT * from posts; +DROP TABLE posts; +ALTER TABLE posts2 RENAME TO posts; diff --git a/migrations/sqlite/2018-12-25-164502_media-cover-deletion/up.sql b/migrations/sqlite/2018-12-25-164502_media-cover-deletion/up.sql new file mode 100644 index 00000000..ca1398e5 --- /dev/null +++ b/migrations/sqlite/2018-12-25-164502_media-cover-deletion/up.sql @@ -0,0 +1,21 @@ +-- Your SQL goes here + +CREATE TABLE posts2 ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + blog_id INTEGER REFERENCES blogs(id) ON DELETE CASCADE NOT NULL, + slug VARCHAR NOT NULL, + title VARCHAR NOT NULL, + content TEXT NOT NULL DEFAULT '', + published BOOLEAN NOT NULL DEFAULT 'f', + license VARCHAR NOT NULL DEFAULT 'CC-BY-SA', + creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + ap_url VARCHAR NOT NULL DEFAULT '' UNIQUE, + subtitle TEXT NOT NULL DEFAULT '', + source TEXT NOT NULL DEFAULT '', + cover_id INTEGER REFERENCES medias(id) ON DELETE SET NULL DEFAULT NULL, + CONSTRAINT blog_authors_unique UNIQUE (blog_id, slug) +); + +INSERT INTO posts2 SELECT * from posts; +DROP TABLE posts; +ALTER TABLE posts2 RENAME TO posts;