diff options
Diffstat (limited to 'priv')
3 files changed, 61 insertions, 0 deletions
| diff --git a/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs b/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs new file mode 100644 index 000000000..d44e5096b --- /dev/null +++ b/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs @@ -0,0 +1,11 @@ +defmodule Pleroma.Repo.Migrations.DataMigrationNormalizeScopes do +  use Ecto.Migration + +  def up do +    for t <- [:apps, :oauth_authorizations, :oauth_tokens] do +      execute "UPDATE #{t} SET scopes = string_to_array(array_to_string(scopes, ' '), ' ');" +    end +  end + +  def down, do: :noop +end diff --git a/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs b/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs new file mode 100644 index 000000000..faeb8f1c6 --- /dev/null +++ b/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs @@ -0,0 +1,9 @@ +defmodule Pleroma.Repo.Migrations.AddDefaultTagsToUser do +  use Ecto.Migration + +  def up do +    execute "UPDATE users SET tags = array[]::varchar[] where tags IS NULL" +  end + +  def down, do: :noop +end diff --git a/priv/repo/migrations/20190303120636_update_user_note_counters.exs b/priv/repo/migrations/20190303120636_update_user_note_counters.exs new file mode 100644 index 000000000..54e68f7c9 --- /dev/null +++ b/priv/repo/migrations/20190303120636_update_user_note_counters.exs @@ -0,0 +1,41 @@ +defmodule Pleroma.Repo.Migrations.UpdateUserNoteCounters do +  use Ecto.Migration + +  @public "https://www.w3.org/ns/activitystreams#Public" + +  def up do +    execute """ +      WITH public_note_count AS ( +        SELECT +          data->>'actor' AS actor, +          count(id) AS count +        FROM objects +        WHERE data->>'type' = 'Note' AND ( +          data->'cc' ? '#{@public}' OR data->'to' ? '#{@public}' +        ) +        GROUP BY data->>'actor' +      ) +      UPDATE users AS u +      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 """ +      WITH public_note_count AS ( +        SELECT +          data->>'actor' AS actor, +          count(id) AS count +        FROM objects +        WHERE data->>'type' = 'Note' +        GROUP BY data->>'actor' +      ) +      UPDATE users AS u +      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 | 
