diff options
Diffstat (limited to 'priv')
-rw-r--r-- | priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs (renamed from priv/repo/migrations/20190208131753_add_scope_to_o_auth_entities.exs) | 4 | ||||
-rw-r--r-- | priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scopes.exs (renamed from priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scope.exs) | 7 | ||||
-rw-r--r-- | priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs | 17 |
3 files changed, 22 insertions, 6 deletions
diff --git a/priv/repo/migrations/20190208131753_add_scope_to_o_auth_entities.exs b/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs index 809e9ab22..4efbebc4d 100644 --- a/priv/repo/migrations/20190208131753_add_scope_to_o_auth_entities.exs +++ b/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs @@ -1,10 +1,10 @@ -defmodule Pleroma.Repo.Migrations.AddScopeToOAuthEntities do +defmodule Pleroma.Repo.Migrations.AddScopeSToOAuthEntities do use Ecto.Migration def change do for t <- [:oauth_authorizations, :oauth_tokens] do alter table(t) do - add :scope, :string + add :scopes, {:array, :string}, default: [], null: false end end end diff --git a/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scope.exs b/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scopes.exs index 722cd6cf9..30b10f56f 100644 --- a/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scope.exs +++ b/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scopes.exs @@ -1,4 +1,4 @@ -defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScope do +defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScopes do use Ecto.Migration require Ecto.Query @@ -11,16 +11,15 @@ defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScope do def up do for app <- Repo.all(Query.from(app in App)) do scopes = OAuth.parse_scopes(app.scopes) - scope = Enum.join(scopes, " ") Repo.update_all( Query.from(auth in Authorization, where: auth.app_id == ^app.id), - set: [scope: scope] + set: [scopes: scopes] ) Repo.update_all( Query.from(token in Token, where: token.app_id == ^app.id), - set: [scope: scope] + set: [scopes: scopes] ) end end diff --git a/priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs b/priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs new file mode 100644 index 000000000..72decd401 --- /dev/null +++ b/priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs @@ -0,0 +1,17 @@ +defmodule Pleroma.Repo.Migrations.ChangeAppsScopesToVarcharArray do + use Ecto.Migration + + @alter_apps_scopes "ALTER TABLE apps ALTER COLUMN scopes" + + def up do + execute "#{@alter_apps_scopes} TYPE varchar(255)[] USING string_to_array(scopes, ',')::varchar(255)[];" + execute "#{@alter_apps_scopes} SET DEFAULT ARRAY[]::character varying[];" + execute "#{@alter_apps_scopes} SET NOT NULL;" + end + + def down do + execute "#{@alter_apps_scopes} DROP NOT NULL;" + execute "#{@alter_apps_scopes} DROP DEFAULT;" + execute "#{@alter_apps_scopes} TYPE varchar(255) USING array_to_string(scopes, ',')::varchar(255);" + end +end |