aboutsummaryrefslogtreecommitdiff
path: root/priv/repo
diff options
context:
space:
mode:
Diffstat (limited to 'priv/repo')
-rw-r--r--priv/repo/migrations/20200716195806_autolinker_to_linkify.exs2
-rw-r--r--priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs2
-rw-r--r--priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs2
-rw-r--r--priv/repo/migrations/20201007131955_add_config_version.exs14
-rw-r--r--priv/repo/migrations/20201007154420_change_key_in_config.exs49
-rw-r--r--priv/repo/migrations/20201101162751_combine_settings_without_key.exs29
-rw-r--r--priv/repo/migrations/20201102064359_create_base_config_version.exs15
7 files changed, 110 insertions, 3 deletions
diff --git a/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs b/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs
index 570acba84..74448d2c7 100644
--- a/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs
+++ b/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs
@@ -15,7 +15,7 @@ defmodule Pleroma.Repo.Migrations.AutolinkerToLinkify do
defp move_config(%{} = old, %{} = new) do
{:ok, _} = ConfigDB.update_or_create(new)
- {:ok, _} = ConfigDB.delete(old)
+ {:ok, _} = ConfigDB.delete_or_update(old)
:ok
end
diff --git a/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs
index 096ab4ce5..739ef7220 100644
--- a/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs
+++ b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs
@@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
import Ecto.Query, only: [from: 2]
def change do
- Pleroma.Config.Oban.warn()
+ Pleroma.Config.DeprecationWarnings.check_oban_config()
Application.ensure_all_started(:oban)
diff --git a/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs b/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs
index 725c5ab0b..78d966766 100644
--- a/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs
+++ b/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs
@@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
import Ecto.Query, only: [from: 2]
def change do
- Pleroma.Config.Oban.warn()
+ Pleroma.Config.DeprecationWarnings.check_oban_config()
Application.ensure_all_started(:oban)
diff --git a/priv/repo/migrations/20201007131955_add_config_version.exs b/priv/repo/migrations/20201007131955_add_config_version.exs
new file mode 100644
index 000000000..1cbfcb398
--- /dev/null
+++ b/priv/repo/migrations/20201007131955_add_config_version.exs
@@ -0,0 +1,14 @@
+defmodule Pleroma.Repo.Migrations.AddConfigVersion do
+ use Ecto.Migration
+
+ def change do
+ create_if_not_exists table(:config_versions) do
+ add(:backup, :binary)
+ add(:current, :boolean)
+
+ timestamps()
+ end
+
+ create_if_not_exists(unique_index(:config_versions, [:current], where: "current = true"))
+ end
+end
diff --git a/priv/repo/migrations/20201007154420_change_key_in_config.exs b/priv/repo/migrations/20201007154420_change_key_in_config.exs
new file mode 100644
index 000000000..844595a13
--- /dev/null
+++ b/priv/repo/migrations/20201007154420_change_key_in_config.exs
@@ -0,0 +1,49 @@
+defmodule Pleroma.Repo.Migrations.ChangeKeyInConfig do
+ use Ecto.Migration
+
+ import Ecto.Query
+
+ alias Pleroma.Repo
+
+ def up do
+ alter table(:config) do
+ modify(:key, :string, null: true)
+ end
+
+ create_if_not_exists(unique_index(:config, [:group, "(key is null)"], where: "key IS NULL"))
+ end
+
+ def down do
+ query = from(c in "config", where: is_nil(c.key))
+
+ if Repo.aggregate(query, :count) == 0 do
+ revert()
+ else
+ configs = Repo.all(query)
+
+ new_configs =
+ Enum.reduce(configs, [], fn %{group: group, value: config}, group_acc ->
+ Enum.reduce(config, group_acc, fn {key, value}, acc ->
+ [%{group: group, key: key, value: value} | acc]
+ end)
+ end)
+
+ Enum.each(new_configs, fn config ->
+ {:ok, _} = Pleroma.ConfigDB.update_or_create(config)
+ end)
+
+ Enum.each(configs, &Repo.delete!(&1))
+
+ flush()
+ revert()
+ end
+ end
+
+ defp revert do
+ alter table(:config) do
+ modify(:key, :string, null: false)
+ end
+
+ drop_if_exists(unique_index(:config, [:group, "(key is null)"]))
+ end
+end
diff --git a/priv/repo/migrations/20201101162751_combine_settings_without_key.exs b/priv/repo/migrations/20201101162751_combine_settings_without_key.exs
new file mode 100644
index 000000000..42c704b1b
--- /dev/null
+++ b/priv/repo/migrations/20201101162751_combine_settings_without_key.exs
@@ -0,0 +1,29 @@
+defmodule Pleroma.Repo.Migrations.CombineSettingsWithoutKey do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ alias Pleroma.ConfigDB
+ alias Pleroma.Repo
+
+ def change do
+ groups = ConfigDB.groups_without_keys()
+
+ configs =
+ from(c in ConfigDB, where: c.group in ^groups)
+ |> Repo.all()
+
+ new_configs =
+ configs
+ |> Enum.reduce([], fn %{group: group, key: key, value: value}, acc ->
+ Keyword.update(acc, group, [{key, value}], &Keyword.merge(&1, [{key, value}]))
+ end)
+ |> ConfigDB.from_keyword_to_maps()
+
+ Enum.each(new_configs, fn config ->
+ {:ok, _} = ConfigDB.update_or_create(config)
+ end)
+
+ Enum.each(configs, &Repo.delete!(&1))
+ end
+end
diff --git a/priv/repo/migrations/20201102064359_create_base_config_version.exs b/priv/repo/migrations/20201102064359_create_base_config_version.exs
new file mode 100644
index 000000000..2f1faf996
--- /dev/null
+++ b/priv/repo/migrations/20201102064359_create_base_config_version.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.CreateBaseConfigVersion do
+ use Ecto.Migration
+
+ def change do
+ configs = Pleroma.ConfigDB.all_as_keyword()
+
+ unless configs == [] do
+ %Pleroma.Config.Version{
+ backup: configs,
+ current: true
+ }
+ |> Pleroma.Repo.insert!()
+ end
+ end
+end