logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

20191025143434_add_defaults_to_tables.exs (2546B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.AddDefaultsToTables do
  5. use Ecto.Migration
  6. def up do
  7. execute("ALTER TABLE activities
  8. ALTER COLUMN recipients SET DEFAULT ARRAY[]::character varying[]")
  9. execute("ALTER TABLE filters
  10. ALTER COLUMN whole_word SET DEFAULT true")
  11. execute("ALTER TABLE push_subscriptions
  12. ALTER COLUMN data SET DEFAULT '{}'::jsonb")
  13. execute(~s(ALTER TABLE users
  14. ALTER COLUMN tags SET DEFAULT ARRAY[]::character varying[],
  15. ALTER COLUMN notification_settings SET DEFAULT
  16. '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb))
  17. # irreversible updates
  18. execute(
  19. "UPDATE activities SET recipients = ARRAY[]::character varying[] WHERE recipients IS NULL"
  20. )
  21. execute("UPDATE filters SET whole_word = true WHERE whole_word IS NULL")
  22. execute("UPDATE push_subscriptions SET data = '{}'::jsonb WHERE data IS NULL")
  23. execute("UPDATE users SET source_data = '{}'::jsonb where source_data IS NULL")
  24. execute("UPDATE users SET note_count = 0 where note_count IS NULL")
  25. execute("UPDATE users SET background = '{}'::jsonb where background IS NULL")
  26. execute("UPDATE users SET follower_count = 0 where follower_count IS NULL")
  27. execute(
  28. "UPDATE users SET unread_conversation_count = 0 where unread_conversation_count IS NULL"
  29. )
  30. execute(
  31. ~s(UPDATE users SET email_notifications = '{"digest": false}'::jsonb where email_notifications IS NULL)
  32. )
  33. execute("UPDATE users SET default_scope = 'public' where default_scope IS NULL")
  34. execute(
  35. "UPDATE users SET pleroma_settings_store = '{}'::jsonb where pleroma_settings_store IS NULL"
  36. )
  37. execute("UPDATE users SET tags = ARRAY[]::character varying[] WHERE tags IS NULL")
  38. execute(~s(UPDATE users SET notification_settings =
  39. '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb
  40. WHERE notification_settings = '{}'::jsonb))
  41. end
  42. def down do
  43. execute("ALTER TABLE activities
  44. ALTER COLUMN recipients DROP DEFAULT")
  45. execute("ALTER TABLE filters
  46. ALTER COLUMN whole_word DROP DEFAULT")
  47. execute("ALTER TABLE push_subscriptions
  48. ALTER COLUMN data DROP DEFAULT")
  49. execute("ALTER TABLE users
  50. ALTER COLUMN tags DROP DEFAULT,
  51. ALTER COLUMN notification_settings SET DEFAULT '{}'::jsonb")
  52. end
  53. end