mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-03 10:14:20 +00:00
[#468] OAuth scopes-related data migration simplification.
This commit is contained in:
parent
063baca5e4
commit
949e35e26d
|
@ -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
|
|
|
@ -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
|
Loading…
Reference in a new issue