aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs11
-rw-r--r--priv/repo/migrations/20190213185503_change_apps_scopes_to_varchar_array.exs17
-rw-r--r--priv/repo/migrations/20190213185600_data_migration_populate_o_auth_scopes.exs11
3 files changed, 39 insertions, 0 deletions
diff --git a/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs b/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs
new file mode 100644
index 000000000..4efbebc4d
--- /dev/null
+++ b/priv/repo/migrations/20190208131753_add_scopes_to_o_auth_entities.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.AddScopeSToOAuthEntities do
+ use Ecto.Migration
+
+ def change do
+ for t <- [:oauth_authorizations, :oauth_tokens] do
+ alter table(t) do
+ add :scopes, {:array, :string}, default: [], null: false
+ end
+ end
+ 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
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