[
- inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
+ inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}", "priv/repo/migrations/*.exs"]
]
def change do
create_if_not_exists table(:users) do
- add :email, :string
- add :password_hash, :string
- add :name, :string
- add :nickname, :string
- add :bio, :string
+ add(:email, :string)
+ add(:password_hash, :string)
+ add(:name, :string)
+ add(:nickname, :string)
+ add(:bio, :string)
timestamps()
end
-
end
end
def change do
create_if_not_exists table(:activities) do
- add :data, :map
+ add(:data, :map)
timestamps()
end
- create_if_not_exists index(:activities, [:data], using: :gin)
-
+ create_if_not_exists(index(:activities, [:data], using: :gin))
end
end
def change do
create_if_not_exists table(:objects) do
- add :data, :map
+ add(:data, :map)
timestamps()
end
-
end
end
def change do
alter table(:users) do
- add :following, :map
+ add(:following, :map)
end
end
end
def change do
alter table(:users) do
- add :ap_id, :string
+ add(:ap_id, :string)
end
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:objects, [:data], using: :gin)
+ create_if_not_exists(index(:objects, [:data], using: :gin))
end
end
use Ecto.Migration
def change do
- create_if_not_exists unique_index(:users, [:email])
- create_if_not_exists unique_index(:users, [:nickname])
+ create_if_not_exists(unique_index(:users, [:email]))
+ create_if_not_exists(unique_index(:users, [:nickname]))
end
end
def change do
alter table(:users) do
- add :avatar, :map
+ add(:avatar, :map)
end
end
end
def change do
create_if_not_exists table(:websub_server_subscriptions) do
- add :topic, :string
- add :callback, :string
- add :secret, :string
- add :valid_until, :naive_datetime
- add :state, :string
+ add(:topic, :string)
+ add(:callback, :string)
+ add(:secret, :string)
+ add(:valid_until, :naive_datetime)
+ add(:state, :string)
timestamps()
end
def change do
alter table(:users) do
- add :local, :boolean, default: true
- add :info, :map
+ add(:local, :boolean, default: true)
+ add(:info, :map)
end
end
end
def change do
create_if_not_exists table(:websub_client_subscriptions) do
- add :topic, :string
- add :secret, :string
- add :valid_until, :naive_datetime_usec
- add :state, :string
- add :subscribers, :map
+ add(:topic, :string)
+ add(:secret, :string)
+ add(:valid_until, :naive_datetime_usec)
+ add(:state, :string)
+ add(:subscribers, :map)
timestamps()
end
def change do
alter table(:websub_client_subscriptions) do
- add :hub, :string
- add :user_id, references(:users)
+ add(:hub, :string)
+ add(:user_id, references(:users))
end
end
end
use Ecto.Migration
def up do
- drop_if_exists index(:objects, ["(data->>\"id\")"], name: :objects_unique_apid_index)
- drop_if_exists index(:activities, ["(data->>\"id\")"], name: :activities_unique_apid_index)
- create_if_not_exists unique_index(:objects, ["(data->>'id')"], name: :objects_unique_apid_index)
- create_if_not_exists unique_index(:activities, ["(data->>'id')"], name: :activities_unique_apid_index)
+ drop_if_exists(index(:objects, ["(data->>\"id\")"], name: :objects_unique_apid_index))
+ drop_if_exists(index(:activities, ["(data->>\"id\")"], name: :activities_unique_apid_index))
+
+ create_if_not_exists(
+ unique_index(:objects, ["(data->>'id')"], name: :objects_unique_apid_index)
+ )
+
+ create_if_not_exists(
+ unique_index(:activities, ["(data->>'id')"], name: :activities_unique_apid_index)
+ )
end
def down, do: :ok
def change do
alter table(:activities) do
- add :local, :boolean, default: true
+ add(:local, :boolean, default: true)
end
- create_if_not_exists index(:activities, [:local])
+ create_if_not_exists(index(:activities, [:local]))
end
end
use Ecto.Migration
def change do
- create_if_not_exists unique_index(:users, [:ap_id])
+ create_if_not_exists(unique_index(:users, [:ap_id]))
end
end
def up do
alter table(:users) do
- modify :bio, :text
+ modify(:bio, :text)
end
end
def down do
alter table(:users) do
- modify :bio, :string
+ modify(:bio, :string)
end
end
-
end
use Ecto.Migration
def change do
- drop_if_exists index(:activities, [:data])
+ drop_if_exists(index(:activities, [:data]))
end
end
use Ecto.Migration
def change do
- drop_if_exists index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
- create_if_not_exists index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
+ drop_if_exists(
+ index(:objects, ["(data->'object'->>'id')", "(data->>'type')"],
+ name: :activities_create_objects_index
+ )
+ )
+
+ create_if_not_exists(
+ index(:activities, ["(data->'object'->>'id')", "(data->>'type')"],
+ name: :activities_create_objects_index
+ )
+ )
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index)
+ create_if_not_exists(
+ index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index)
+ )
end
end
def up do
alter table(:users) do
- add :follower_address, :string, unique: true
+ add(:follower_address, :string, unique: true)
end
end
def down do
alter table(:users) do
- remove :follower_address
+ remove(:follower_address)
end
end
end
def change do
create_if_not_exists table(:apps) do
- add :client_name, :string
- add :redirect_uris, :string
- add :scopes, :string
- add :website, :string
- add :client_id, :string
- add :client_secret, :string
+ add(:client_name, :string)
+ add(:redirect_uris, :string)
+ add(:scopes, :string)
+ add(:website, :string)
+ add(:client_id, :string)
+ add(:client_secret, :string)
timestamps()
end
def change do
create_if_not_exists table(:oauth_authorizations) do
- add :app_id, references(:apps)
- add :user_id, references(:users)
- add :token, :string
- add :valid_until, :naive_datetime_usec
- add :used, :boolean, default: false
+ add(:app_id, references(:apps))
+ add(:user_id, references(:users))
+ add(:token, :string)
+ add(:valid_until, :naive_datetime_usec)
+ add(:used, :boolean, default: false)
timestamps()
end
def change do
create_if_not_exists table(:oauth_tokens) do
- add :app_id, references(:apps)
- add :user_id, references(:users)
- add :token, :string
- add :refresh_token, :string
- add :valid_until, :naive_datetime_usec
+ add(:app_id, references(:apps))
+ add(:user_id, references(:users))
+ add(:token, :string)
+ add(:refresh_token, :string)
+ add(:valid_until, :naive_datetime_usec)
timestamps()
end
def change do
create_if_not_exists table(:notifications) do
- add :user_id, references(:users, on_delete: :delete_all)
- add :activity_id, references(:activities, on_delete: :delete_all)
- add :seen, :boolean, default: false
+ add(:user_id, references(:users, on_delete: :delete_all))
+ add(:activity_id, references(:activities, on_delete: :delete_all))
+ add(:seen, :boolean, default: false)
timestamps()
end
- create_if_not_exists index(:notifications, [:user_id])
+ create_if_not_exists(index(:notifications, [:user_id]))
end
end
@disable_ddl_transaction true
def change do
- create index(:activities, ["(data->>'type')", "(data->>'context')"], name: :activities_context_index, concurrently: true)
+ create(
+ index(:activities, ["(data->>'type')", "(data->>'context')"],
+ name: :activities_context_index,
+ concurrently: true
+ )
+ )
end
end
@disable_ddl_transaction true
def change do
- create index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"], concurrently: true, using: :gin, name: :activities_fts)
+ create(
+ index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"],
+ concurrently: true,
+ using: :gin,
+ name: :activities_fts
+ )
+ )
end
end
@disable_ddl_transaction true
def change do
- create index(:activities, ["(data #> '{\"object\",\"tag\"}')"], concurrently: true, using: :gin, name: :activities_tags)
+ create(
+ index(:activities, ["(data #> '{\"object\",\"tag\"}')"],
+ concurrently: true,
+ using: :gin,
+ name: :activities_tags
+ )
+ )
end
end
def change do
create_if_not_exists table(:password_reset_tokens) do
- add :token, :string
- add :user_id, references(:users)
- add :used, :boolean, default: false
+ add(:token, :string)
+ add(:user_id, references(:users))
+ add(:used, :boolean, default: false)
timestamps()
end
@disable_ddl_transaction true
def change do
- drop_if_exists index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
- create index(:activities, ["(coalesce(data->'object'->>'id', data->>'object'))"], name: :activities_create_objects_index, concurrently: true)
+ drop_if_exists(
+ index(:activities, ["(data->'object'->>'id')", "(data->>'type')"],
+ name: :activities_create_objects_index
+ )
+ )
+
+ create(
+ index(:activities, ["(coalesce(data->'object'->>'id', data->>'object'))"],
+ name: :activities_create_objects_index,
+ concurrently: true
+ )
+ )
end
end
use Ecto.Migration
def change do
- drop_if_exists index(:objects, [:data], using: :gin)
+ drop_if_exists(index(:objects, [:data], using: :gin))
end
end
@disable_ddl_transaction true
def change do
- create index(:objects, ["(data->>'actor')", "(data->>'type')"], concurrently: true, name: :objects_actor_type)
+ create(
+ index(:objects, ["(data->>'actor')", "(data->>'type')"],
+ concurrently: true,
+ name: :objects_actor_type
+ )
+ )
end
end
def up do
alter table(:activities) do
- add :actor, :string
+ add(:actor, :string)
end
- create index(:activities, [:actor, "id DESC NULLS LAST"], concurrently: true)
+ create(index(:activities, [:actor, "id DESC NULLS LAST"], concurrently: true))
end
def down do
- drop_if_exists index(:activities, [:actor, "id DESC NULLS LAST"])
+ drop_if_exists(index(:activities, [:actor, "id DESC NULLS LAST"]))
+
alter table(:activities) do
- remove :actor
+ remove(:actor)
end
end
end
def up do
max = Repo.aggregate(Activity, :max, :id)
+
if max do
IO.puts("#{max} activities")
- chunks = 0..(round(max / 10_000))
+ chunks = 0..round(max / 10_000)
- Enum.each(chunks, fn (i) ->
+ Enum.each(chunks, fn i ->
min = i * 10_000
max = min + 10_000
+
execute("""
update activities set actor = data->>'actor' where id > #{min} and id <= #{max};
""")
- |> IO.inspect
+ |> IO.inspect()
end)
end
end
def down do
end
end
-
@disable_ddl_transaction true
def change do
- create index(:activities, ["id desc nulls last"], concurrently: true)
+ create(index(:activities, ["id desc nulls last"], concurrently: true))
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:users, [:local])
+ create_if_not_exists(index(:users, [:local]))
end
end
def change do
alter table(:activities) do
- add :recipients, {:array, :string}
+ add(:recipients, {:array, :string})
end
- create_if_not_exists index(:activities, [:recipients], using: :gin)
+ create_if_not_exists(index(:activities, [:recipients], using: :gin))
end
end
def up do
max = Repo.aggregate(Activity, :max, :id)
+
if max do
IO.puts("#{max} activities")
- chunks = 0..(round(max / 10_000))
+ chunks = 0..round(max / 10_000)
- Enum.each(chunks, fn (i) ->
+ Enum.each(chunks, fn i ->
min = i * 10_000
max = min + 10_000
+
execute("""
- update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{min} and id <= #{max};
+ update activities set recipients = array(select jsonb_array_elements_text(data->'to')) where id > #{
+ min
+ } and id <= #{max};
""")
- |> IO.inspect
+ |> IO.inspect()
end)
end
end
def up do
alter table(:users) do
- add :following_temp, {:array, :string}
+ add(:following_temp, {:array, :string})
end
- execute """
+ execute("""
update users set following_temp = array(select jsonb_array_elements_text(following));
- """
+ """)
alter table(:users) do
- remove :following
+ remove(:following)
end
- rename table(:users), :following_temp, to: :following
+
+ rename(table(:users), :following_temp, to: :following)
end
def down, do: :ok
@disable_ddl_transaction true
def change do
- create index(:users, [:follower_address], concurrently: true)
- create index(:users, [:following], concurrently: true, using: :gin)
+ create(index(:users, [:follower_address], concurrently: true))
+ create(index(:users, [:following], concurrently: true, using: :gin))
end
end
use Ecto.Migration
def change do
- drop_if_exists index(:users, [:local])
+ drop_if_exists(index(:users, [:local]))
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:users, [:local])
- drop_if_exists index("activities", :local)
+ create_if_not_exists(index(:users, [:local]))
+ drop_if_exists(index("activities", :local))
end
end
def change do
create_if_not_exists table(:lists) do
- add :user_id, references(:users, on_delete: :delete_all)
- add :title, :string
- add :following, {:array, :string}
+ add(:user_id, references(:users, on_delete: :delete_all))
+ add(:title, :string)
+ add(:following, {:array, :string})
timestamps()
end
- create_if_not_exists index(:lists, [:user_id])
+ create_if_not_exists(index(:lists, [:user_id]))
end
end
@disable_ddl_transaction true
def change do
- create index(:activities, ["id desc nulls last", "local"], concurrently: true)
- drop_if_exists index(:activities, ["id desc nulls last"])
+ create(index(:activities, ["id desc nulls last", "local"], concurrently: true))
+ drop_if_exists(index(:activities, ["id desc nulls last"]))
end
end
def up do
Logger.warn("ATTENTION ATTENTION ATTENTION\n")
- Logger.warn("This will try to create the pg_trgm extension on your database. If your database user does NOT have the necessary rights, you will have to do it manually and re-run the migrations.\nYou can probably do this by running the following:\n")
- Logger.warn("sudo -u postgres psql pleroma_dev -c \"create extension if not exists pg_trgm\"\n")
+
+ Logger.warn(
+ "This will try to create the pg_trgm extension on your database. If your database user does NOT have the necessary rights, you will have to do it manually and re-run the migrations.\nYou can probably do this by running the following:\n"
+ )
+
+ Logger.warn(
+ "sudo -u postgres psql pleroma_dev -c \"create extension if not exists pg_trgm\"\n"
+ )
+
execute("create extension if not exists pg_trgm")
end
use Ecto.Migration
def change do
- create_if_not_exists index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist)
+ create_if_not_exists(
+ index(:users, ["(nickname || name) gist_trgm_ops"], name: :users_trigram_index, using: :gist)
+ )
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:lists, [:following])
+ create_if_not_exists(index(:lists, [:following]))
end
end
@disable_ddl_transaction true
def change do
- create index(:activities, ["(split_part(actor, '/', 3))"], concurrently: true, name: :activities_hosts)
+ create(
+ index(:activities, ["(split_part(actor, '/', 3))"],
+ concurrently: true,
+ name: :activities_hosts
+ )
+ )
end
end
def change do
create_if_not_exists table(:user_invite_tokens) do
- add :token, :string
- add :used, :boolean, default: false
+ add(:token, :string)
+ add(:used, :boolean, default: false)
timestamps()
end
@disable_ddl_transaction true
def change do
- create index(:activities, ["(data->'object'->>'inReplyTo')"], concurrently: true, name: :activities_in_reply_to)
+ create(
+ index(:activities, ["(data->'object'->>'inReplyTo')"],
+ concurrently: true,
+ name: :activities_in_reply_to
+ )
+ )
end
end
def change do
create_if_not_exists table(:filters) do
- add :user_id, references(:users, on_delete: :delete_all)
- add :filter_id, :integer
- add :hide, :boolean
- add :phrase, :string
- add :context, {:array, :string}
- add :expires_at, :utc_datetime
- add :whole_word, :boolean
+ add(:user_id, references(:users, on_delete: :delete_all))
+ add(:filter_id, :integer)
+ add(:hide, :boolean)
+ add(:phrase, :string)
+ add(:context, {:array, :string})
+ add(:expires_at, :utc_datetime)
+ add(:whole_word, :boolean)
timestamps()
end
- create_if_not_exists index(:filters, [:user_id])
- create_if_not_exists index(:filters, [:phrase], where: "hide = true", name: :hided_phrases_index)
+ create_if_not_exists(index(:filters, [:user_id]))
+
+ create_if_not_exists(
+ index(:filters, [:phrase], where: "hide = true", name: :hided_phrases_index)
+ )
end
end
def change do
alter table(:activities) do
- add :recipients_to, {:array, :string}
- add :recipients_cc, {:array, :string}
+ add(:recipients_to, {:array, :string})
+ add(:recipients_cc, {:array, :string})
end
- create_if_not_exists index(:activities, [:recipients_to], using: :gin)
- create_if_not_exists index(:activities, [:recipients_cc], using: :gin)
+ create_if_not_exists(index(:activities, [:recipients_to], using: :gin))
+ create_if_not_exists(index(:activities, [:recipients_cc], using: :gin))
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:activities, ["(data->'to')"], name: :activities_to_index, using: :gin)
- create_if_not_exists index(:activities, ["(data->'cc')"], name: :activities_cc_index, using: :gin)
+ create_if_not_exists(
+ index(:activities, ["(data->'to')"], name: :activities_to_index, using: :gin)
+ )
+
+ create_if_not_exists(
+ index(:activities, ["(data->'cc')"], name: :activities_cc_index, using: :gin)
+ )
end
end
def up do
alter table(:activities) do
- remove :recipients_to
- remove :recipients_cc
+ remove(:recipients_to)
+ remove(:recipients_cc)
end
end
def down do
alter table(:activities) do
- add :recipients_to, {:array, :string}
- add :recipients_cc, {:array, :string}
+ add(:recipients_to, {:array, :string})
+ add(:recipients_cc, {:array, :string})
end
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:users, ["(info->'is_moderator')"], name: :users_is_moderator_index, using: :gin)
+ create_if_not_exists(
+ index(:users, ["(info->'is_moderator')"], name: :users_is_moderator_index, using: :gin)
+ )
end
end
def change do
create_if_not_exists table("push_subscriptions") do
- add :user_id, references("users", on_delete: :delete_all)
- add :token_id, references("oauth_tokens", on_delete: :delete_all)
- add :endpoint, :string
- add :key_p256dh, :string
- add :key_auth, :string
- add :data, :map
+ add(:user_id, references("users", on_delete: :delete_all))
+ add(:token_id, references("oauth_tokens", on_delete: :delete_all))
+ add(:endpoint, :string)
+ add(:key_p256dh, :string)
+ add(:key_auth, :string)
+ add(:data, :map)
timestamps()
end
- create_if_not_exists index("push_subscriptions", [:user_id, :token_id], unique: true)
+ create_if_not_exists(index("push_subscriptions", [:user_id, :token_id], unique: true))
end
end
def change do
alter table(:users) do
- add :last_refreshed_at, :naive_datetime_usec
+ add(:last_refreshed_at, :naive_datetime_usec)
end
end
end
def change do
alter table(:users) do
- add :tags, {:array, :string}
+ add(:tags, {:array, :string})
end
- create_if_not_exists index(:users, [:tags], using: :gin)
+ create_if_not_exists(index(:users, [:tags], using: :gin))
end
end
def change do
alter table(:users) do
- add :bookmarks, {:array, :string}, null: false, default: []
+ add(:bookmarks, {:array, :string}, null: false, default: [])
end
end
end
# Old serial int ids are transformed to 128bits with extra padding.
# The application (in `Pleroma.FlakeId`) handles theses IDs properly as integers; to keep compatibility
# with previously issued ids.
- #execute "update activities set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);"
- #execute "update users set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);"
+ # execute "update activities set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);"
+ # execute "update users set external_id = CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);"
clippy = start_clippy_heartbeats()
# Lock both tables to avoid a running server to meddling with our transaction
- execute "LOCK TABLE activities;"
- execute "LOCK TABLE users;"
+ execute("LOCK TABLE activities;")
+ execute("LOCK TABLE users;")
- execute """
+ execute("""
ALTER TABLE activities
DROP CONSTRAINT activities_pkey CASCADE,
ALTER COLUMN id DROP default,
ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid),
ADD PRIMARY KEY (id);
- """
+ """)
- execute """
+ execute("""
ALTER TABLE users
DROP CONSTRAINT users_pkey CASCADE,
ALTER COLUMN id DROP default,
ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid),
ADD PRIMARY KEY (id);
- """
+ """)
- execute "UPDATE users SET info = jsonb_set(info, '{pinned_activities}', array_to_json(ARRAY(select jsonb_array_elements_text(info->'pinned_activities')))::jsonb);"
+ execute(
+ "UPDATE users SET info = jsonb_set(info, '{pinned_activities}', array_to_json(ARRAY(select jsonb_array_elements_text(info->'pinned_activities')))::jsonb);"
+ )
# Fkeys:
# Activities - Referenced by:
# TABLE "push_subscriptions" CONSTRAINT "push_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
# TABLE "websub_client_subscriptions" CONSTRAINT "websub_client_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
- execute """
+ execute("""
ALTER TABLE notifications
ALTER COLUMN activity_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(activity_id), 32, '0' ) AS uuid),
ADD CONSTRAINT notifications_activity_id_fkey FOREIGN KEY (activity_id) REFERENCES activities(id) ON DELETE CASCADE;
- """
+ """)
- for table <- ~w(notifications filters lists oauth_authorizations oauth_tokens password_reset_tokens push_subscriptions websub_client_subscriptions) do
- execute """
+ for table <-
+ ~w(notifications filters lists oauth_authorizations oauth_tokens password_reset_tokens push_subscriptions websub_client_subscriptions) do
+ execute("""
ALTER TABLE #{table}
ALTER COLUMN user_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(user_id), 32, '0' ) AS uuid),
ADD CONSTRAINT #{table}_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
- """
+ """)
end
flush()
def down, do: :ok
defp start_clippy_heartbeats() do
- count = from(a in "activities", select: count(a.id)) |> Repo.one!
+ count = from(a in "activities", select: count(a.id)) |> Repo.one!()
if count > 5000 do
heartbeat_interval = :timer.minutes(2) + :timer.seconds(30)
- all_tips = Clippy.tips() ++ [
- "The migration is still running, maybe it's time for another “tea”?",
- "Happy rabbits practice a cute behavior known as a\n“binky:” they jump up in the air\nand twist\nand spin around!",
- "Nothing and everything.\n\nI still work.",
- "Pleroma runs on a Raspberry Pi!\n\n … but this migration will take forever if you\nactually run on a raspberry pi",
- "Status? Stati? Post? Note? Toot?\nRepeat? Reboost? Boost? Retweet? Retoot??\n\nI-I'm confused.",
- ]
-
- heartbeat = fn(heartbeat, runs, all_tips, tips) ->
- tips = if Integer.is_even(runs) do
- tips = if tips == [], do: all_tips, else: tips
- [tip | tips] = Enum.shuffle(tips)
- Clippy.puts(tip)
- tips
- else
- IO.puts "\n -- #{DateTime.to_string(DateTime.utc_now())} Migration still running, please wait…\n"
- tips
- end
+
+ all_tips =
+ Clippy.tips() ++
+ [
+ "The migration is still running, maybe it's time for another “tea”?",
+ "Happy rabbits practice a cute behavior known as a\n“binky:” they jump up in the air\nand twist\nand spin around!",
+ "Nothing and everything.\n\nI still work.",
+ "Pleroma runs on a Raspberry Pi!\n\n … but this migration will take forever if you\nactually run on a raspberry pi",
+ "Status? Stati? Post? Note? Toot?\nRepeat? Reboost? Boost? Retweet? Retoot??\n\nI-I'm confused."
+ ]
+
+ heartbeat = fn heartbeat, runs, all_tips, tips ->
+ tips =
+ if Integer.is_even(runs) do
+ tips = if tips == [], do: all_tips, else: tips
+ [tip | tips] = Enum.shuffle(tips)
+ Clippy.puts(tip)
+ tips
+ else
+ IO.puts(
+ "\n -- #{DateTime.to_string(DateTime.utc_now())} Migration still running, please wait…\n"
+ )
+
+ tips
+ end
+
:timer.sleep(heartbeat_interval)
heartbeat.(heartbeat, runs + 1, all_tips, tips)
end
- Clippy.puts [
+ Clippy.puts([
[:red, :bright, "It looks like you are running an older instance!"],
[""],
[:bright, "This migration may take a long time", :reset, " -- so you probably should"],
["go drink a cofe, or a tea, or a beer, a whiskey, a vodka,"],
["while it runs to deal with your temporary fediverse pause!"]
- ]
+ ])
+
:timer.sleep(heartbeat_interval)
- spawn_link(fn() -> heartbeat.(heartbeat, 1, all_tips, []) end)
+ spawn_link(fn -> heartbeat.(heartbeat, 1, all_tips, []) end)
end
end
if pid do
Process.unlink(pid)
Process.exit(pid, :kill)
- Clippy.puts [[:green, :bright, "Hurray!!", "", "", "Migration completed!"]]
+ Clippy.puts([[:green, :bright, "Hurray!!", "", "", "Migration completed!"]])
end
end
-
end
)
)
- execute("drop function if exists activity_visibility(actor varchar, recipients varchar[], data jsonb)")
+ execute(
+ "drop function if exists activity_visibility(actor varchar, recipients varchar[], data jsonb)"
+ )
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(
- :users,
- [
- """
- (setweight(to_tsvector('simple', regexp_replace(nickname, '\\W', ' ', 'g')), 'A') ||
- setweight(to_tsvector('simple', regexp_replace(coalesce(name, ''), '\\W', ' ', 'g')), 'B'))
- """
- ],
- name: :users_fts_index,
- using: :gin
- )
+ create_if_not_exists(
+ index(
+ :users,
+ [
+ """
+ (setweight(to_tsvector('simple', regexp_replace(nickname, '\\W', ' ', 'g')), 'A') ||
+ setweight(to_tsvector('simple', regexp_replace(coalesce(name, ''), '\\W', ' ', 'g')), 'B'))
+ """
+ ],
+ name: :users_fts_index,
+ using: :gin
+ )
+ )
end
end
"""
execute(definition)
-
end
def down do
-
end
end
use Ecto.Migration
def change do
- create_if_not_exists(index(:users, ["(info->'is_admin')"], name: :users_is_admin_index, using: :gin))
+ create_if_not_exists(
+ index(:users, ["(info->'is_admin')"], name: :users_is_admin_index, using: :gin)
+ )
end
end
def change do
create_if_not_exists table(:instances) do
- add :host, :string
- add :unreachable_since, :naive_datetime_usec
+ add(:host, :string)
+ add(:unreachable_since, :naive_datetime_usec)
timestamps()
end
- create_if_not_exists unique_index(:instances, [:host])
- create_if_not_exists index(:instances, [:unreachable_since])
+ create_if_not_exists(unique_index(:instances, [:host]))
+ create_if_not_exists(index(:instances, [:unreachable_since]))
end
end
"""
execute(definition)
-
end
def down do
-
end
-
end
@disable_ddl_transaction true
def change do
- create index(:activities, ["((data #> '{\"object\",\"likes\"}'))"], concurrently: true, name: :activities_likes, using: :gin)
+ create(
+ index(:activities, ["((data #> '{\"object\",\"likes\"}'))"],
+ concurrently: true,
+ name: :activities_likes,
+ using: :gin
+ )
+ )
end
end
use Ecto.Migration
def up do
- execute("UPDATE users SET info = jsonb_set(info, '{hide_network}'::text[], 'false'::jsonb) WHERE NOT(info::jsonb ? 'hide_network') AND local")
- execute("UPDATE users SET info = jsonb_set(info, '{hide_followings}'::text[], info->'hide_network') WHERE local")
- execute("UPDATE users SET info = jsonb_set(info, '{hide_followers}'::text[], info->'hide_network') WHERE local")
+ execute(
+ "UPDATE users SET info = jsonb_set(info, '{hide_network}'::text[], 'false'::jsonb) WHERE NOT(info::jsonb ? 'hide_network') AND local"
+ )
+
+ execute(
+ "UPDATE users SET info = jsonb_set(info, '{hide_followings}'::text[], info->'hide_network') WHERE local"
+ )
+
+ execute(
+ "UPDATE users SET info = jsonb_set(info, '{hide_followers}'::text[], info->'hide_network') WHERE local"
+ )
end
def down do
def change do
create_if_not_exists table(:thread_mutes) do
- add :user_id, references(:users, type: :uuid, on_delete: :delete_all)
- add :context, :string
+ add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+ add(:context, :string)
end
- create_if_not_exists unique_index(:thread_mutes, [:user_id, :context], name: :unique_index)
+ create_if_not_exists(unique_index(:thread_mutes, [:user_id, :context], name: :unique_index))
end
end
def change do
for t <- [:oauth_authorizations, :oauth_tokens] do
alter table(t) do
- add :scopes, {:array, :string}, default: [], null: false
+ add(:scopes, {:array, :string}, default: [], null: false)
end
end
end
@alter_apps_scopes "ALTER TABLE apps ALTER COLUMN scopes"
def up do
- execute "#{@alter_apps_scopes} TYPE varchar(255)[] USING string_to_array(scopes, ',')::varchar(255)[];"
- execute "#{@alter_apps_scopes} SET DEFAULT ARRAY[]::character varying[];"
- execute "#{@alter_apps_scopes} SET NOT NULL;"
+ execute(
+ "#{@alter_apps_scopes} TYPE varchar(255)[] USING string_to_array(scopes, ',')::varchar(255)[];"
+ )
+
+ execute("#{@alter_apps_scopes} SET DEFAULT ARRAY[]::character varying[];")
+ execute("#{@alter_apps_scopes} SET NOT NULL;")
end
def down do
- execute "#{@alter_apps_scopes} DROP NOT NULL;"
- execute "#{@alter_apps_scopes} DROP DEFAULT;"
- execute "#{@alter_apps_scopes} TYPE varchar(255) USING array_to_string(scopes, ',')::varchar(255);"
+ execute("#{@alter_apps_scopes} DROP NOT NULL;")
+ execute("#{@alter_apps_scopes} DROP DEFAULT;")
+
+ execute(
+ "#{@alter_apps_scopes} TYPE varchar(255) USING array_to_string(scopes, ',')::varchar(255);"
+ )
end
end
def up do
for t <- [:oauth_authorizations, :oauth_tokens] do
- execute "UPDATE #{t} SET scopes = apps.scopes FROM apps WHERE #{t}.app_id = apps.id;"
+ execute("UPDATE #{t} SET scopes = apps.scopes FROM apps WHERE #{t}.app_id = apps.id;")
end
end
def up do
for t <- [:apps, :oauth_authorizations, :oauth_tokens] do
- execute "UPDATE #{t} SET scopes = string_to_array(array_to_string(scopes, ' '), ' ');"
+ execute("UPDATE #{t} SET scopes = string_to_array(array_to_string(scopes, ' '), ' ');")
end
end
use Ecto.Migration
def up do
- execute "UPDATE users SET tags = array[]::varchar[] where tags IS NULL"
+ execute("UPDATE users SET tags = array[]::varchar[] where tags IS NULL")
end
def down, do: :noop
@public "https://www.w3.org/ns/activitystreams#Public"
def up do
- execute """
+ execute("""
WITH public_note_count AS (
SELECT
data->>'actor' AS actor,
SET "info" = jsonb_set(u.info, '{note_count}', o.count::varchar::jsonb, true)
FROM public_note_count AS o
WHERE u.ap_id = o.actor
- """
+ """)
end
def down do
- execute """
+ execute("""
WITH public_note_count AS (
SELECT
data->>'actor' AS actor,
SET "info" = jsonb_set(u.info, '{note_count}', o.count::varchar::jsonb, true)
FROM public_note_count AS o
WHERE u.ap_id = o.actor
- """
+ """)
end
end
def change do
create_if_not_exists table(:registrations, primary_key: false) do
- add :id, :uuid, primary_key: true
- add :user_id, references(:users, type: :uuid, on_delete: :delete_all)
- add :provider, :string
- add :uid, :string
- add :info, :map, default: %{}
+ add(:id, :uuid, primary_key: true)
+ add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+ add(:provider, :string)
+ add(:uid, :string)
+ add(:info, :map, default: %{})
timestamps()
end
- create_if_not_exists unique_index(:registrations, [:provider, :uid])
- create_if_not_exists unique_index(:registrations, [:user_id, :provider, :uid])
+ create_if_not_exists(unique_index(:registrations, [:provider, :uid]))
+ create_if_not_exists(unique_index(:registrations, [:user_id, :provider, :uid]))
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:notifications, ["id desc nulls last"])
+ create_if_not_exists(index(:notifications, ["id desc nulls last"]))
end
end
@disable_ddl_transaction true
def change do
- create index(:users, ["(info->'subscribers')"], name: :users_subscribers_index, using: :gin, concurrently: true)
+ create(
+ index(:users, ["(info->'subscribers')"],
+ name: :users_subscribers_index,
+ using: :gin,
+ concurrently: true
+ )
+ )
end
end
timestamps()
end
- create_if_not_exists index(:conversation_participations, [:conversation_id])
- create_if_not_exists unique_index(:conversation_participations, [:user_id, :conversation_id])
- create_if_not_exists unique_index(:conversations, [:ap_id])
+ create_if_not_exists(index(:conversation_participations, [:conversation_id]))
+ create_if_not_exists(unique_index(:conversation_participations, [:user_id, :conversation_id]))
+ create_if_not_exists(unique_index(:conversations, [:ap_id]))
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:conversation_participations, ["updated_at desc"])
+ create_if_not_exists(index(:conversation_participations, ["updated_at desc"]))
end
end
use Ecto.Migration
def change do
- create_if_not_exists(index(:users, ["(info->'deactivated')"], name: :users_deactivated_index, using: :gin))
+ create_if_not_exists(
+ index(:users, ["(info->'deactivated')"], name: :users_deactivated_index, using: :gin)
+ )
end
end
|> Enum.each(fn %{id: user_id, bookmarks: bookmarks} ->
Enum.each(bookmarks, fn ap_id ->
activity = Activity.get_create_by_object_ap_id(ap_id)
- unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id)
+ unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id)
end)
end)
def down do
alter table(:users) do
- add :bookmarks, {:array, :string}, null: false, default: []
+ add(:bookmarks, {:array, :string}, null: false, default: [])
end
end
end
use Ecto.Migration
def change do
- drop_if_exists index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"], using: :gin, name: :activities_fts)
- create_if_not_exists index(:objects, ["(to_tsvector('english', data->>'content'))"], using: :gin, name: :objects_fts)
+ drop_if_exists(
+ index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"],
+ using: :gin,
+ name: :activities_fts
+ )
+ )
+
+ create_if_not_exists(
+ index(:objects, ["(to_tsvector('english', data->>'content'))"],
+ using: :gin,
+ name: :objects_fts
+ )
+ )
end
end
use Ecto.Migration
def up do
- execute """
+ execute("""
UPDATE activities AS a
SET data = jsonb_set(data, '{state}', '"open"', true)
WHERE data->>'type' = 'Flag'
- """
+ """)
end
def down do
- execute """
+ execute("""
UPDATE activities AS a
SET data = data #- '{state}'
WHERE data->>'type' = 'Flag'
- """
+ """)
end
end
def up do
alter table(:filters) do
- modify :hide, :boolean, default: false
+ modify(:hide, :boolean, default: false)
end
end
def down do
alter table(:filters) do
- modify :hide, :boolean
+ modify(:hide, :boolean)
end
end
end
use Ecto.Migration
def change do
- create index(:objects, ["(data->>'inReplyTo')"], name: :objects_in_reply_to_index)
+ create(index(:objects, ["(data->>'inReplyTo')"], name: :objects_in_reply_to_index))
end
end
use Ecto.Migration
def change do
- drop_if_exists index(:activities, ["(data #> '{\"object\",\"tag\"}')"], using: :gin, name: :activities_tags)
- create_if_not_exists index(:objects, ["(data->'tag')"], using: :gin, name: :objects_tags)
+ drop_if_exists(
+ index(:activities, ["(data #> '{\"object\",\"tag\"}')"], using: :gin, name: :activities_tags)
+ )
+
+ create_if_not_exists(index(:objects, ["(data->'tag')"], using: :gin, name: :objects_tags))
end
end
alias Pleroma.User
def change do
- execute("update users set info = jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true")
+ execute(
+ "update users set info = jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true"
+ )
end
end
add(:participation_id, references(:conversation_participations, on_delete: :delete_all))
end
- create_if_not_exists index(:conversation_participation_recipient_ships, [:user_id])
- create_if_not_exists index(:conversation_participation_recipient_ships, [:participation_id])
+ create_if_not_exists(index(:conversation_participation_recipient_ships, [:user_id]))
+ create_if_not_exists(index(:conversation_participation_recipient_ships, [:participation_id]))
end
end
use Ecto.Migration
def change do
- create_if_not_exists index(:objects, ["(data->'likes')"], using: :gin, name: :objects_likes)
+ create_if_not_exists(index(:objects, ["(data->'likes')"], using: :gin, name: :objects_likes))
end
end
add(:object_id, references(:objects, type: :id), null: false)
add(:user_id, references(:users, type: :uuid, on_delete: :delete_all), null: false)
end
- create_if_not_exists index(:deliveries, :object_id, name: :deliveries_object_id)
+
+ create_if_not_exists(index(:deliveries, :object_id, name: :deliveries_object_id))
create_if_not_exists(unique_index(:deliveries, [:user_id, :object_id]))
end
end
use Ecto.Migration
def change do
-
end
def up do
drop_if_exists(index(:subscription_notifications, ["id desc nulls last"]))
drop_if_exists(table(:subscription_notifications))
end
+
def down do
:ok
end
def change do
alter table("users") do
- add_if_not_exists :keys, :text
+ add_if_not_exists(:keys, :text)
end
end
end
use Ecto.Migration
def change do
- execute("update users set keys = info->>'keys' where local", "update users set info = jsonb_set(info, '{keys}'::text[], to_jsonb(keys)) where local")
+ execute(
+ "update users set keys = info->>'keys' where local",
+ "update users set info = jsonb_set(info, '{keys}'::text[], to_jsonb(keys)) where local"
+ )
end
end