summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20191220174645_add_scopes_to_pleroma_feo_auth_records.exs
blob: e99d51c265299666632aae3591073c5d189f5648 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Repo.Migrations.AddScopesToPleromaFEOAuthRecords do
  use Ecto.Migration

  def up do
    update_scopes_clause = "SET scopes = '{read,write,follow,push,admin}'"
    apps_where = "WHERE apps.client_name like 'PleromaFE_%' or apps.client_name like 'AdminFE_%'"
    app_id_subquery_where = "WHERE app_id IN (SELECT apps.id FROM apps #{apps_where})"

    execute("UPDATE apps #{update_scopes_clause} #{apps_where}")

    for table <- ["oauth_authorizations", "oauth_tokens"] do
      execute("UPDATE #{table} #{update_scopes_clause} #{app_id_subquery_where}")
    end
  end

  def down, do: :noop
end