From 949e35e26deaf6dc7c2e552b1b8db63de8a87445 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 14 Feb 2019 14:28:26 +0300 Subject: [PATCH] [#468] OAuth scopes-related data migration simplification. --- ...23318_data_migration_populate_o_auth_scopes.exs | 28 ---------------------- ...85600_data_migration_populate_o_auth_scopes.exs | 11 +++++++++ 2 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scopes.exs create mode 100644 priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs diff --git a/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scopes.exs b/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scopes.exs deleted file mode 100644 index 30b10f56f..000000000 --- a/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scopes.exs +++ /dev/null @@ -1,28 +0,0 @@ -defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScopes do - use Ecto.Migration - - require Ecto.Query - - alias Ecto.Query - alias Pleroma.Repo - alias Pleroma.Web.OAuth - alias Pleroma.Web.OAuth.{App, Authorization, Token} - - def up do - for app <- Repo.all(Query.from(app in App)) do - scopes = OAuth.parse_scopes(app.scopes) - - Repo.update_all( - Query.from(auth in Authorization, where: auth.app_id == ^app.id), - set: [scopes: scopes] - ) - - Repo.update_all( - Query.from(token in Token, where: token.app_id == ^app.id), - set: [scopes: scopes] - ) - end - end - - def down, do: :noop -end diff --git a/priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs b/priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs new file mode 100644 index 000000000..7afbcbd76 --- /dev/null +++ b/priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs @@ -0,0 +1,11 @@ +defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScopes do + use Ecto.Migration + + def up do + for t <- [:oauth_authorizations, :oauth_tokens] do + execute "UPDATE #{t} SET scopes = apps.scopes FROM apps WHERE #{t}.app_id = apps.id;" + end + end + + def down, do: :noop +end