d16ab19f9f1ecd35c80631e04f5ad77600ce1360
[akkoma] / priv / repo / migrations / 20191025143434_add_defaults_to_tables.exs
1 defmodule Pleroma.Repo.Migrations.AddDefaultsToTables do
2 use Ecto.Migration
3
4 def up do
5 execute("ALTER TABLE activities
6 ALTER COLUMN recipients SET DEFAULT ARRAY[]::character varying[]")
7
8 execute("ALTER TABLE filters
9 ALTER COLUMN whole_word SET DEFAULT true")
10
11 execute("ALTER TABLE push_subscriptions
12 ALTER COLUMN data SET DEFAULT '{}'::jsonb")
13
14 execute(~s(ALTER TABLE users
15 ALTER COLUMN following SET DEFAULT ARRAY[]::character varying[],
16 ALTER COLUMN tags SET DEFAULT ARRAY[]::character varying[],
17 ALTER COLUMN notification_settings SET DEFAULT
18 '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb))
19
20 # irreversible updates
21
22 execute(
23 "UPDATE activities SET recipients = ARRAY[]::character varying[] WHERE recipients IS NULL"
24 )
25
26 execute("UPDATE filters SET whole_word = true WHERE whole_word IS NULL")
27
28 execute("UPDATE push_subscriptions SET data = '{}'::jsonb WHERE data IS NULL")
29
30 execute("UPDATE users SET source_data = '{}'::jsonb where source_data IS NULL")
31 execute("UPDATE users SET note_count = 0 where note_count IS NULL")
32 execute("UPDATE users SET background = '{}'::jsonb where background IS NULL")
33 execute("UPDATE users SET follower_count = 0 where follower_count IS NULL")
34
35 execute(
36 "UPDATE users SET unread_conversation_count = 0 where unread_conversation_count IS NULL"
37 )
38
39 execute(
40 ~s(UPDATE users SET email_notifications = '{"digest": false}'::jsonb where email_notifications IS NULL)
41 )
42
43 execute("UPDATE users SET default_scope = 'public' where default_scope IS NULL")
44
45 execute(
46 "UPDATE users SET pleroma_settings_store = '{}'::jsonb where pleroma_settings_store IS NULL"
47 )
48
49 execute("UPDATE users SET following = ARRAY[]::character varying[] WHERE following IS NULL")
50 execute("UPDATE users SET tags = ARRAY[]::character varying[] WHERE tags IS NULL")
51 execute(~s(UPDATE users SET notification_settings =
52 '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb
53 WHERE notification_settings = '{}'::jsonb))
54 end
55
56 def down do
57 execute("ALTER TABLE activities
58 ALTER COLUMN recipients DROP DEFAULT")
59
60 execute("ALTER TABLE filters
61 ALTER COLUMN whole_word DROP DEFAULT")
62
63 execute("ALTER TABLE push_subscriptions
64 ALTER COLUMN data DROP DEFAULT")
65
66 execute("ALTER TABLE users
67 ALTER COLUMN following DROP DEFAULT,
68 ALTER COLUMN tags DROP DEFAULT,
69 ALTER COLUMN notification_settings SET DEFAULT '{}'::jsonb")
70 end
71 end