diff options
| author | lain <lain@soykaf.club> | 2020-11-04 15:05:01 +0100 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-11-04 15:05:01 +0100 | 
| commit | 329aa19c9f1175f915441c84689860155949bb08 (patch) | |
| tree | 17a92069fdb2f49d2f82efdabf3bec1e20822508 /priv/repo/migrations | |
| parent | 755f58168bb2b6b979c6f5d36f7eff56d2305911 (diff) | |
| parent | bc4d9c4ffc9ccd826220893a97ce695e4bb66f9d (diff) | |
| download | pleroma-329aa19c9f1175f915441c84689860155949bb08.tar.gz pleroma-329aa19c9f1175f915441c84689860155949bb08.zip | |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into alexgleason/pleroma-restrict-domain
Diffstat (limited to 'priv/repo/migrations')
5 files changed, 97 insertions, 0 deletions
| diff --git a/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs b/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs new file mode 100644 index 000000000..b7bdb9166 --- /dev/null +++ b/priv/repo/migrations/20200831114918_remove_unread_conversation_count_from_user.exs @@ -0,0 +1,38 @@ +defmodule Pleroma.Repo.Migrations.RemoveUnreadConversationCountFromUser do +  use Ecto.Migration +  import Ecto.Query +  alias Pleroma.Repo + +  def up do +    alter table(:users) do +      remove_if_exists(:unread_conversation_count, :integer) +    end +  end + +  def down do +    alter table(:users) do +      add_if_not_exists(:unread_conversation_count, :integer, default: 0) +    end + +    flush() +    recalc_unread_conversation_count() +  end + +  defp recalc_unread_conversation_count do +    participations_subquery = +      from( +        p in "conversation_participations", +        where: p.read == false, +        group_by: p.user_id, +        select: %{user_id: p.user_id, unread_conversation_count: count(p.id)} +      ) + +    from( +      u in "users", +      join: p in subquery(participations_subquery), +      on: p.user_id == u.id, +      update: [set: [unread_conversation_count: p.unread_conversation_count]] +    ) +    |> Repo.update_all([]) +  end +end diff --git a/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs b/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs new file mode 100644 index 000000000..68771c655 --- /dev/null +++ b/priv/repo/migrations/20200831115854_add_unread_index_to_conversation_participation.exs @@ -0,0 +1,12 @@ +defmodule Pleroma.Repo.Migrations.AddUnreadIndexToConversationParticipation do +  use Ecto.Migration + +  def change do +    create( +      index(:conversation_participations, [:user_id], +        where: "read = false", +        name: "unread_conversation_participation_count_index" +      ) +    ) +  end +end diff --git a/priv/repo/migrations/20200831192323_create_backups.exs b/priv/repo/migrations/20200831192323_create_backups.exs new file mode 100644 index 000000000..3ac5889e2 --- /dev/null +++ b/priv/repo/migrations/20200831192323_create_backups.exs @@ -0,0 +1,17 @@ +defmodule Pleroma.Repo.Migrations.CreateBackups do +  use Ecto.Migration + +  def change do +    create_if_not_exists table(:backups) do +      add(:user_id, references(:users, type: :uuid, on_delete: :delete_all)) +      add(:file_name, :string, null: false) +      add(:content_type, :string, null: false) +      add(:processed, :boolean, null: false, default: false) +      add(:file_size, :bigint) + +      timestamps() +    end + +    create_if_not_exists(index(:backups, [:user_id])) +  end +end diff --git a/priv/repo/migrations/20201013141127_refactor_locked_user_field.exs b/priv/repo/migrations/20201013141127_refactor_locked_user_field.exs new file mode 100644 index 000000000..6cd23dbac --- /dev/null +++ b/priv/repo/migrations/20201013141127_refactor_locked_user_field.exs @@ -0,0 +1,15 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.RefactorLockedUserField do +  use Ecto.Migration + +  def up do +    execute("ALTER TABLE users RENAME COLUMN locked TO is_locked;") +  end + +  def down do +    execute("ALTER TABLE users RENAME COLUMN is_locked TO locked;") +  end +end diff --git a/priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs b/priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs new file mode 100644 index 000000000..3fdc190cc --- /dev/null +++ b/priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs @@ -0,0 +1,15 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.RefactorDiscoverableUserField do +  use Ecto.Migration + +  def up do +    execute("ALTER TABLE users RENAME COLUMN discoverable TO is_discoverable;") +  end + +  def down do +    execute("ALTER TABLE users RENAME COLUMN is_discoverable TO discoverable;") +  end +end | 
