Merge remote-tracking branch 'pleroma/develop' into poll-notification-fixes
This commit is contained in:
commit
62bf6d67e3
361 changed files with 8361 additions and 2945 deletions
|
|
@ -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;
|
||||
|
|
|
|||
77
priv/repo/migrations/20200806175913_rename_instance_chat.exs
Normal file
77
priv/repo/migrations/20200806175913_rename_instance_chat.exs
Normal file
|
|
@ -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
|
||||
13
priv/repo/migrations/20201221202251_create_hashtags.exs
Normal file
13
priv/repo/migrations/20201221202251_create_hashtags.exs
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue