summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Chvanikov <chvanikoff@pm.me>2019-10-27 19:29:35 +0300
committerRoman Chvanikov <chvanikoff@pm.me>2019-10-27 19:29:35 +0300
commit0be9cb086b070858b041cd15ee149d1323952aab (patch)
tree2b876992cfa08243b91de5f3b4bf7d2270f4f70a
parent060adfd762a5183b3cc5f51e041819b24b8430d2 (diff)
downloadpleroma-0be9cb086b070858b041cd15ee149d1323952aab.tar.gz
pleroma-0be9cb086b070858b041cd15ee149d1323952aab.zip
Add migration
-rw-r--r--priv/repo/migrations/20191027143434_add_defaults_to_all_tables.exs52
1 files changed, 52 insertions, 0 deletions
diff --git a/priv/repo/migrations/20191027143434_add_defaults_to_all_tables.exs b/priv/repo/migrations/20191027143434_add_defaults_to_all_tables.exs
new file mode 100644
index 000000000..ab60f1313
--- /dev/null
+++ b/priv/repo/migrations/20191027143434_add_defaults_to_all_tables.exs
@@ -0,0 +1,52 @@
+defmodule Pleroma.Repo.Migrations.AddDefaultsToAllTables do
+ use Ecto.Migration
+
+ def up do
+ execute("ALTER TABLE activities
+ ALTER COLUMN recipients SET DEFAULT ARRAY[]::character varying[]")
+
+ execute("ALTER TABLE filters
+ ALTER COLUMN whole_word SET DEFAULT true")
+
+ execute("ALTER TABLE push_subscriptions
+ ALTER COLUMN data SET DEFAULT '{}'::jsonb")
+
+ execute(~s(ALTER TABLE users
+ ALTER COLUMN following SET DEFAULT ARRAY[]::character varying[],
+ ALTER COLUMN tags SET DEFAULT ARRAY[]::character varying[],
+ ALTER COLUMN notification_settings SET DEFAULT
+ '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb))
+
+ # irreversible updates
+
+ execute(
+ "UPDATE activities SET recipients = ARRAY[]::character varying[] WHERE recipients IS NULL"
+ )
+
+ execute("UPDATE filters SET whole_word = true WHERE whole_word IS NULL")
+
+ execute("UPDATE push_subscriptions SET data = '{}'::jsonb WHERE data IS NULL")
+
+ execute("UPDATE users SET following = ARRAY[]::character varying[] WHERE following IS NULL")
+ execute("UPDATE users SET tags = ARRAY[]::character varying[] WHERE tags IS NULL")
+ execute(~s(UPDATE users SET notification_settings =
+ '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb
+ WHERE notification_settings = '{}'::jsonb))
+ end
+
+ def down do
+ execute("ALTER TABLE activities
+ ALTER COLUMN recipients DROP DEFAULT")
+
+ execute("ALTER TABLE filters
+ ALTER COLUMN whole_word DROP DEFAULT")
+
+ execute("ALTER TABLE push_subscriptions
+ ALTER COLUMN data DROP DEFAULT")
+
+ execute("ALTER TABLE users
+ ALTER COLUMN following DROP DEFAULT,
+ ALTER COLUMN tags DROP DEFAULT,
+ ALTER COLUMN notification_settings SET DEFAULT '{}'::jsonb")
+ end
+end