From 3bbdbb832c975d0c9b3e5573fe2bd5ea66b11015 Mon Sep 17 00:00:00 2001 From: Jeremy Lin Date: Sat, 22 Aug 2020 17:14:05 -0700 Subject: [PATCH] Transfer favorite status for user-owned ciphers --- .../down.sql | 15 ++++++++++++--- .../2020-08-02-025025_add_favorites_table/up.sql | 7 +++++++ .../down.sql | 15 ++++++++++++--- .../2020-08-02-025025_add_favorites_table/up.sql | 7 +++++++ .../down.sql | 15 ++++++++++++--- .../2020-08-02-025025_add_favorites_table/up.sql | 7 +++++++ 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/migrations/mysql/2020-08-02-025025_add_favorites_table/down.sql b/migrations/mysql/2020-08-02-025025_add_favorites_table/down.sql index 9b79b636..25eb713b 100644 --- a/migrations/mysql/2020-08-02-025025_add_favorites_table/down.sql +++ b/migrations/mysql/2020-08-02-025025_add_favorites_table/down.sql @@ -1,4 +1,13 @@ -DROP TABLE favorites; - ALTER TABLE ciphers -ADD COLUMN favorite BOOLEAN NOT NULL; +ADD COLUMN favorite BOOLEAN NOT NULL DEFAULT FALSE; + +-- Transfer favorite status for user-owned ciphers. +UPDATE ciphers +SET favorite = TRUE +WHERE EXISTS ( + SELECT * FROM favorites + WHERE favorites.user_uuid = ciphers.user_uuid + AND favorites.cipher_uuid = ciphers.uuid +); + +DROP TABLE favorites; diff --git a/migrations/mysql/2020-08-02-025025_add_favorites_table/up.sql b/migrations/mysql/2020-08-02-025025_add_favorites_table/up.sql index 904c15ea..ebff7e3d 100644 --- a/migrations/mysql/2020-08-02-025025_add_favorites_table/up.sql +++ b/migrations/mysql/2020-08-02-025025_add_favorites_table/up.sql @@ -5,5 +5,12 @@ CREATE TABLE favorites ( PRIMARY KEY (user_uuid, cipher_uuid) ); +-- Transfer favorite status for user-owned ciphers. +INSERT INTO favorites(user_uuid, cipher_uuid) +SELECT user_uuid, uuid +FROM ciphers +WHERE favorite = TRUE + AND user_uuid IS NOT NULL; + ALTER TABLE ciphers DROP COLUMN favorite; diff --git a/migrations/postgresql/2020-08-02-025025_add_favorites_table/down.sql b/migrations/postgresql/2020-08-02-025025_add_favorites_table/down.sql index 9b79b636..25eb713b 100644 --- a/migrations/postgresql/2020-08-02-025025_add_favorites_table/down.sql +++ b/migrations/postgresql/2020-08-02-025025_add_favorites_table/down.sql @@ -1,4 +1,13 @@ -DROP TABLE favorites; - ALTER TABLE ciphers -ADD COLUMN favorite BOOLEAN NOT NULL; +ADD COLUMN favorite BOOLEAN NOT NULL DEFAULT FALSE; + +-- Transfer favorite status for user-owned ciphers. +UPDATE ciphers +SET favorite = TRUE +WHERE EXISTS ( + SELECT * FROM favorites + WHERE favorites.user_uuid = ciphers.user_uuid + AND favorites.cipher_uuid = ciphers.uuid +); + +DROP TABLE favorites; diff --git a/migrations/postgresql/2020-08-02-025025_add_favorites_table/up.sql b/migrations/postgresql/2020-08-02-025025_add_favorites_table/up.sql index 925eb2bc..9a8787f9 100644 --- a/migrations/postgresql/2020-08-02-025025_add_favorites_table/up.sql +++ b/migrations/postgresql/2020-08-02-025025_add_favorites_table/up.sql @@ -5,5 +5,12 @@ CREATE TABLE favorites ( PRIMARY KEY (user_uuid, cipher_uuid) ); +-- Transfer favorite status for user-owned ciphers. +INSERT INTO favorites(user_uuid, cipher_uuid) +SELECT user_uuid, uuid +FROM ciphers +WHERE favorite = TRUE + AND user_uuid IS NOT NULL; + ALTER TABLE ciphers DROP COLUMN favorite; diff --git a/migrations/sqlite/2020-08-02-025025_add_favorites_table/down.sql b/migrations/sqlite/2020-08-02-025025_add_favorites_table/down.sql index 9b79b636..6920b5f4 100644 --- a/migrations/sqlite/2020-08-02-025025_add_favorites_table/down.sql +++ b/migrations/sqlite/2020-08-02-025025_add_favorites_table/down.sql @@ -1,4 +1,13 @@ -DROP TABLE favorites; - ALTER TABLE ciphers -ADD COLUMN favorite BOOLEAN NOT NULL; +ADD COLUMN favorite BOOLEAN NOT NULL DEFAULT 0; -- FALSE + +-- Transfer favorite status for user-owned ciphers. +UPDATE ciphers +SET favorite = 1 +WHERE EXISTS ( + SELECT * FROM favorites + WHERE favorites.user_uuid = ciphers.user_uuid + AND favorites.cipher_uuid = ciphers.uuid +); + +DROP TABLE favorites; diff --git a/migrations/sqlite/2020-08-02-025025_add_favorites_table/up.sql b/migrations/sqlite/2020-08-02-025025_add_favorites_table/up.sql index c00a7900..48541142 100644 --- a/migrations/sqlite/2020-08-02-025025_add_favorites_table/up.sql +++ b/migrations/sqlite/2020-08-02-025025_add_favorites_table/up.sql @@ -5,6 +5,13 @@ CREATE TABLE favorites ( PRIMARY KEY (user_uuid, cipher_uuid) ); +-- Transfer favorite status for user-owned ciphers. +INSERT INTO favorites(user_uuid, cipher_uuid) +SELECT user_uuid, uuid +FROM ciphers +WHERE favorite = 1 + AND user_uuid IS NOT NULL; + -- Drop the `favorite` column from the `ciphers` table, using the 12-step -- procedure from . -- Note that some steps aren't applicable and are omitted.