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 25eb713b..c79a61de 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,13 +1 @@ -ALTER TABLE ciphers -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 9a8787f9..d5a02bfa 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 @@ -4,13 +4,3 @@ 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-025026_add_favorites_table_fix/down.sql b/migrations/postgresql/2020-08-02-025026_add_favorites_table_fix/down.sql new file mode 100644 index 00000000..af5669fa --- /dev/null +++ b/migrations/postgresql/2020-08-02-025026_add_favorites_table_fix/down.sql @@ -0,0 +1,11 @@ +ALTER TABLE ciphers +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 +); diff --git a/migrations/postgresql/2020-08-02-025026_add_favorites_table_fix/up.sql b/migrations/postgresql/2020-08-02-025026_add_favorites_table_fix/up.sql new file mode 100644 index 00000000..af67e7b5 --- /dev/null +++ b/migrations/postgresql/2020-08-02-025026_add_favorites_table_fix/up.sql @@ -0,0 +1,9 @@ +-- 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;