First
[anni] / priv / repo / migrations / 20191220174645_add_scopes_to_pleroma_feo_auth_records.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.AddScopesToPleromaFEOAuthRecords do
6   use Ecto.Migration
7
8   def up do
9     update_scopes_clause = "SET scopes = '{read,write,follow,push,admin}'"
10     apps_where = "WHERE apps.client_name like 'PleromaFE_%' or apps.client_name like 'AdminFE_%'"
11     app_id_subquery_where = "WHERE app_id IN (SELECT apps.id FROM apps #{apps_where})"
12
13     execute("UPDATE apps #{update_scopes_clause} #{apps_where}")
14
15     for table <- ["oauth_authorizations", "oauth_tokens"] do
16       execute("UPDATE #{table} #{update_scopes_clause} #{app_id_subquery_where}")
17     end
18   end
19
20   def down, do: :noop
21 end