summaryrefslogtreecommitdiff
path: root/priv/repo/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'priv/repo/migrations')
-rw-r--r--priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs2
-rw-r--r--priv/repo/migrations/20200806175913_rename_instance_chat.exs77
-rw-r--r--priv/repo/migrations/20201221202251_create_hashtags.exs13
-rw-r--r--priv/repo/migrations/20201221202252_remove_data_from_hashtags.exs15
-rw-r--r--priv/repo/migrations/20201221203824_create_hashtags_objects.exs13
-rw-r--r--priv/repo/migrations/20210105195018_create_data_migrations.exs17
-rw-r--r--priv/repo/migrations/20210106183301_data_migration_create_populate_hashtags_table.exs16
-rw-r--r--priv/repo/migrations/20210111172254_create_data_migration_failed_ids.exs14
-rw-r--r--priv/repo/migrations/20210121080964_add_default_text_search_config.exs2
-rw-r--r--priv/repo/migrations/20210202110641_add_pinned_objects_to_users.exs9
-rw-r--r--priv/repo/migrations/20210203141144_add_featured_address_to_users.exs23
-rw-r--r--priv/repo/migrations/20210205145000_move_pinned_activities_into_pinned_objects.exs28
-rw-r--r--priv/repo/migrations/20210206045221_remove_pinned_activities_from_users.exs15
-rw-r--r--priv/repo/migrations/20210222183840_remove_hashtags_objects_duplicate_index.exs11
-rw-r--r--priv/repo/migrations/20210222184616_change_hashtags_name_to_text.exs15
-rw-r--r--priv/repo/migrations/20210401143153_user_notification_settings_fix.exs17
-rw-r--r--priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs19
17 files changed, 304 insertions, 2 deletions
diff --git a/priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs b/priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs
index 43d616705..bfac09f9e 100644
--- a/priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs
+++ b/priv/repo/migrations/20190711042021_create_safe_jsonb_set.exs
@@ -9,7 +9,7 @@ defmodule Pleroma.Repo.Migrations.CreateSafeJsonbSet do
begin
result := jsonb_set(target, path, coalesce(new_value, 'null'::jsonb), create_missing);
if result is NULL then
- raise 'jsonb_set tried to wipe the object, please report this incindent to Pleroma bug tracker. https://git.pleroma.social/pleroma/pleroma/issues/new';
+ raise 'jsonb_set tried to wipe the object, please report this incident to Pleroma bug tracker. https://git.pleroma.social/pleroma/pleroma/issues/new';
return target;
else
return result;
diff --git a/priv/repo/migrations/20200806175913_rename_instance_chat.exs b/priv/repo/migrations/20200806175913_rename_instance_chat.exs
new file mode 100644
index 000000000..31585efe8
--- /dev/null
+++ b/priv/repo/migrations/20200806175913_rename_instance_chat.exs
@@ -0,0 +1,77 @@
+defmodule Pleroma.Repo.Migrations.RenameInstanceChat do
+ use Ecto.Migration
+
+ alias Pleroma.ConfigDB
+
+ @instance_params %{group: :pleroma, key: :instance}
+ @shout_params %{group: :pleroma, key: :shout}
+ @chat_params %{group: :pleroma, key: :chat}
+
+ def up do
+ instance_updated? = maybe_update_instance_key(:up) != :noop
+ chat_updated? = maybe_update_chat_key(:up) != :noop
+
+ case Enum.any?([instance_updated?, chat_updated?]) do
+ true -> :ok
+ false -> :noop
+ end
+ end
+
+ def down do
+ instance_updated? = maybe_update_instance_key(:down) != :noop
+ chat_updated? = maybe_update_chat_key(:down) != :noop
+
+ case Enum.any?([instance_updated?, chat_updated?]) do
+ true -> :ok
+ false -> :noop
+ end
+ end
+
+ # pleroma.instance.chat_limit -> pleroma.shout.limit
+ defp maybe_update_instance_key(:up) do
+ with %ConfigDB{value: values} <- ConfigDB.get_by_params(@instance_params),
+ limit when is_integer(limit) <- values[:chat_limit] do
+ @shout_params |> Map.put(:value, limit: limit) |> ConfigDB.update_or_create()
+ @instance_params |> Map.put(:subkeys, [":chat_limit"]) |> ConfigDB.delete()
+ else
+ _ ->
+ :noop
+ end
+ end
+
+ # pleroma.shout.limit -> pleroma.instance.chat_limit
+ defp maybe_update_instance_key(:down) do
+ with %ConfigDB{value: values} <- ConfigDB.get_by_params(@shout_params),
+ limit when is_integer(limit) <- values[:limit] do
+ @instance_params |> Map.put(:value, chat_limit: limit) |> ConfigDB.update_or_create()
+ @shout_params |> Map.put(:subkeys, [":limit"]) |> ConfigDB.delete()
+ else
+ _ ->
+ :noop
+ end
+ end
+
+ # pleroma.chat.enabled -> pleroma.shout.enabled
+ defp maybe_update_chat_key(:up) do
+ with %ConfigDB{value: values} <- ConfigDB.get_by_params(@chat_params),
+ enabled? when is_boolean(enabled?) <- values[:enabled] do
+ @shout_params |> Map.put(:value, enabled: enabled?) |> ConfigDB.update_or_create()
+ @chat_params |> Map.put(:subkeys, [":enabled"]) |> ConfigDB.delete()
+ else
+ _ ->
+ :noop
+ end
+ end
+
+ # pleroma.shout.enabled -> pleroma.chat.enabled
+ defp maybe_update_chat_key(:down) do
+ with %ConfigDB{value: values} <- ConfigDB.get_by_params(@shout_params),
+ enabled? when is_boolean(enabled?) <- values[:enabled] do
+ @chat_params |> Map.put(:value, enabled: enabled?) |> ConfigDB.update_or_create()
+ @shout_params |> Map.put(:subkeys, [":enabled"]) |> ConfigDB.delete()
+ else
+ _ ->
+ :noop
+ end
+ end
+end
diff --git a/priv/repo/migrations/20201221202251_create_hashtags.exs b/priv/repo/migrations/20201221202251_create_hashtags.exs
new file mode 100644
index 000000000..8d2e9ae66
--- /dev/null
+++ b/priv/repo/migrations/20201221202251_create_hashtags.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.CreateHashtags do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:hashtags) do
+ add(:name, :citext, null: false)
+
+ timestamps()
+ end
+
+ create_if_not_exists(unique_index(:hashtags, [:name]))
+ end
+end
diff --git a/priv/repo/migrations/20201221202252_remove_data_from_hashtags.exs b/priv/repo/migrations/20201221202252_remove_data_from_hashtags.exs
new file mode 100644
index 000000000..0442c3b87
--- /dev/null
+++ b/priv/repo/migrations/20201221202252_remove_data_from_hashtags.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.RemoveDataFromHashtags do
+ use Ecto.Migration
+
+ def up do
+ alter table(:hashtags) do
+ remove_if_exists(:data, :map)
+ end
+ end
+
+ def down do
+ alter table(:hashtags) do
+ add_if_not_exists(:data, :map, default: %{})
+ end
+ end
+end
diff --git a/priv/repo/migrations/20201221203824_create_hashtags_objects.exs b/priv/repo/migrations/20201221203824_create_hashtags_objects.exs
new file mode 100644
index 000000000..581f32b3c
--- /dev/null
+++ b/priv/repo/migrations/20201221203824_create_hashtags_objects.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.CreateHashtagsObjects do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:hashtags_objects, primary_key: false) do
+ add(:hashtag_id, references(:hashtags), null: false, primary_key: true)
+ add(:object_id, references(:objects), null: false, primary_key: true)
+ end
+
+ # Note: PK index: "hashtags_objects_pkey" PRIMARY KEY, btree (hashtag_id, object_id)
+ create_if_not_exists(index(:hashtags_objects, [:object_id]))
+ end
+end
diff --git a/priv/repo/migrations/20210105195018_create_data_migrations.exs b/priv/repo/migrations/20210105195018_create_data_migrations.exs
new file mode 100644
index 000000000..5f2e8d96c
--- /dev/null
+++ b/priv/repo/migrations/20210105195018_create_data_migrations.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.CreateDataMigrations do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:data_migrations) do
+ add(:name, :string, null: false)
+ add(:state, :integer, default: 1)
+ add(:feature_lock, :boolean, default: false)
+ add(:params, :map, default: %{})
+ add(:data, :map, default: %{})
+
+ timestamps()
+ end
+
+ create_if_not_exists(unique_index(:data_migrations, [:name]))
+ end
+end
diff --git a/priv/repo/migrations/20210106183301_data_migration_create_populate_hashtags_table.exs b/priv/repo/migrations/20210106183301_data_migration_create_populate_hashtags_table.exs
new file mode 100644
index 000000000..cf3cf26a0
--- /dev/null
+++ b/priv/repo/migrations/20210106183301_data_migration_create_populate_hashtags_table.exs
@@ -0,0 +1,16 @@
+defmodule Pleroma.Repo.Migrations.DataMigrationCreatePopulateHashtagsTable do
+ use Ecto.Migration
+
+ def up do
+ dt = NaiveDateTime.utc_now()
+
+ execute(
+ "INSERT INTO data_migrations(name, inserted_at, updated_at) " <>
+ "VALUES ('populate_hashtags_table', '#{dt}', '#{dt}') ON CONFLICT DO NOTHING;"
+ )
+ end
+
+ def down do
+ execute("DELETE FROM data_migrations WHERE name = 'populate_hashtags_table';")
+ end
+end
diff --git a/priv/repo/migrations/20210111172254_create_data_migration_failed_ids.exs b/priv/repo/migrations/20210111172254_create_data_migration_failed_ids.exs
new file mode 100644
index 000000000..18afa74ac
--- /dev/null
+++ b/priv/repo/migrations/20210111172254_create_data_migration_failed_ids.exs
@@ -0,0 +1,14 @@
+defmodule Pleroma.Repo.Migrations.CreateDataMigrationFailedIds do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:data_migration_failed_ids, primary_key: false) do
+ add(:data_migration_id, references(:data_migrations), null: false, primary_key: true)
+ add(:record_id, :bigint, null: false, primary_key: true)
+ end
+
+ create_if_not_exists(
+ unique_index(:data_migration_failed_ids, [:data_migration_id, :record_id])
+ )
+ end
+end
diff --git a/priv/repo/migrations/20210121080964_add_default_text_search_config.exs b/priv/repo/migrations/20210121080964_add_default_text_search_config.exs
index 09b6cccc9..27f600b70 100644
--- a/priv/repo/migrations/20210121080964_add_default_text_search_config.exs
+++ b/priv/repo/migrations/20210121080964_add_default_text_search_config.exs
@@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.AddDefaultTextSearchConfig do
def change do
execute("DO $$
BEGIN
- execute 'ALTER DATABASE '||current_database()||' SET default_text_search_config = ''english'' ';
+ execute 'ALTER DATABASE \"'||current_database()||'\" SET default_text_search_config = ''english'' ';
END
$$;")
end
diff --git a/priv/repo/migrations/20210202110641_add_pinned_objects_to_users.exs b/priv/repo/migrations/20210202110641_add_pinned_objects_to_users.exs
new file mode 100644
index 000000000..644527246
--- /dev/null
+++ b/priv/repo/migrations/20210202110641_add_pinned_objects_to_users.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddPinnedObjectsToUsers do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ add(:pinned_objects, :map)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20210203141144_add_featured_address_to_users.exs b/priv/repo/migrations/20210203141144_add_featured_address_to_users.exs
new file mode 100644
index 000000000..0f6a21611
--- /dev/null
+++ b/priv/repo/migrations/20210203141144_add_featured_address_to_users.exs
@@ -0,0 +1,23 @@
+defmodule Pleroma.Repo.Migrations.AddFeaturedAddressToUsers do
+ use Ecto.Migration
+
+ def up do
+ alter table(:users) do
+ add(:featured_address, :string)
+ end
+
+ create(index(:users, [:featured_address]))
+
+ execute("""
+
+ update users set featured_address = concat(ap_id, '/collections/featured') where local = true and featured_address is null;
+
+ """)
+ end
+
+ def down do
+ alter table(:users) do
+ remove(:featured_address)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20210205145000_move_pinned_activities_into_pinned_objects.exs b/priv/repo/migrations/20210205145000_move_pinned_activities_into_pinned_objects.exs
new file mode 100644
index 000000000..9aee545e3
--- /dev/null
+++ b/priv/repo/migrations/20210205145000_move_pinned_activities_into_pinned_objects.exs
@@ -0,0 +1,28 @@
+defmodule Pleroma.Repo.Migrations.MovePinnedActivitiesIntoPinnedObjects do
+ use Ecto.Migration
+
+ import Ecto.Query
+
+ alias Pleroma.Repo
+ alias Pleroma.User
+
+ def up do
+ from(u in User)
+ |> select([u], {u.id, fragment("?.pinned_activities", u)})
+ |> Repo.stream()
+ |> Stream.each(fn {user_id, pinned_activities_ids} ->
+ pinned_activities = Pleroma.Activity.all_by_ids_with_object(pinned_activities_ids)
+
+ pins =
+ Map.new(pinned_activities, fn %{object: %{data: %{"id" => object_id}}} ->
+ {object_id, NaiveDateTime.utc_now()}
+ end)
+
+ from(u in User, where: u.id == ^user_id)
+ |> Repo.update_all(set: [pinned_objects: pins])
+ end)
+ |> Stream.run()
+ end
+
+ def down, do: :noop
+end
diff --git a/priv/repo/migrations/20210206045221_remove_pinned_activities_from_users.exs b/priv/repo/migrations/20210206045221_remove_pinned_activities_from_users.exs
new file mode 100644
index 000000000..a3ee93f48
--- /dev/null
+++ b/priv/repo/migrations/20210206045221_remove_pinned_activities_from_users.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.RemovePinnedActivitiesFromUsers do
+ use Ecto.Migration
+
+ def up do
+ alter table(:users) do
+ remove(:pinned_activities)
+ end
+ end
+
+ def down do
+ alter table(:users) do
+ add(:pinned_activities, {:array, :string}, default: [])
+ end
+ end
+end
diff --git a/priv/repo/migrations/20210222183840_remove_hashtags_objects_duplicate_index.exs b/priv/repo/migrations/20210222183840_remove_hashtags_objects_duplicate_index.exs
new file mode 100644
index 000000000..6c4a2dfdc
--- /dev/null
+++ b/priv/repo/migrations/20210222183840_remove_hashtags_objects_duplicate_index.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.RemoveHashtagsObjectsDuplicateIndex do
+ use Ecto.Migration
+
+ @moduledoc "Removes `hashtags_objects_hashtag_id_object_id_index` index (duplicate of PK index)."
+
+ def up do
+ drop_if_exists(unique_index(:hashtags_objects, [:hashtag_id, :object_id]))
+ end
+
+ def down, do: nil
+end
diff --git a/priv/repo/migrations/20210222184616_change_hashtags_name_to_text.exs b/priv/repo/migrations/20210222184616_change_hashtags_name_to_text.exs
new file mode 100644
index 000000000..8940b6ca3
--- /dev/null
+++ b/priv/repo/migrations/20210222184616_change_hashtags_name_to_text.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.ChangeHashtagsNameToText do
+ use Ecto.Migration
+
+ def up do
+ alter table(:hashtags) do
+ modify(:name, :text)
+ end
+ end
+
+ def down do
+ alter table(:hashtags) do
+ modify(:name, :citext)
+ end
+ end
+end
diff --git a/priv/repo/migrations/20210401143153_user_notification_settings_fix.exs b/priv/repo/migrations/20210401143153_user_notification_settings_fix.exs
new file mode 100644
index 000000000..cf68f1be6
--- /dev/null
+++ b/priv/repo/migrations/20210401143153_user_notification_settings_fix.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Repo.Migrations.UserNotificationSettingsFix do
+ use Ecto.Migration
+
+ def up do
+ execute(~s(UPDATE users
+ SET
+ notification_settings = '{"followers": true, "follows": true, "non_follows": true, "non_followers": true}'::jsonb WHERE notification_settings IS NULL
+))
+
+ execute("ALTER TABLE users
+ ALTER COLUMN notification_settings SET NOT NULL")
+ end
+
+ def down do
+ :ok
+ end
+end
diff --git a/priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs b/priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs
new file mode 100644
index 000000000..f4ebf53d6
--- /dev/null
+++ b/priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.DeleteHashtagsObjectsCascade do
+ use Ecto.Migration
+
+ def up do
+ execute("ALTER TABLE hashtags_objects DROP CONSTRAINT hashtags_objects_object_id_fkey")
+
+ alter table(:hashtags_objects) do
+ modify(:object_id, references(:objects, on_delete: :delete_all))
+ end
+ end
+
+ def down do
+ execute("ALTER TABLE hashtags_objects DROP CONSTRAINT hashtags_objects_object_id_fkey")
+
+ alter table(:hashtags_objects) do
+ modify(:object_id, references(:objects, on_delete: :nothing))
+ end
+ end
+end