summaryrefslogtreecommitdiff
path: root/priv/repo
diff options
context:
space:
mode:
Diffstat (limited to 'priv/repo')
-rw-r--r--priv/repo/migrations/20190123092341_users_add_is_admin_index.exs7
-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
-rw-r--r--priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs11
-rw-r--r--priv/repo/migrations/20190301101154_add_default_tags_to_user.exs9
-rw-r--r--priv/repo/migrations/20190303120636_update_user_note_counters.exs41
7 files changed, 107 insertions, 0 deletions
diff --git a/priv/repo/migrations/20190123092341_users_add_is_admin_index.exs b/priv/repo/migrations/20190123092341_users_add_is_admin_index.exs
new file mode 100644
index 000000000..ba6ff78b5
--- /dev/null
+++ b/priv/repo/migrations/20190123092341_users_add_is_admin_index.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.UsersAddIsAdminIndex do
+ use Ecto.Migration
+
+ def change do
+ create(index(:users, ["(info->'is_admin')"], name: :users_is_admin_index, using: :gin))
+ end
+end
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
diff --git a/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs b/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs
new file mode 100644
index 000000000..d44e5096b
--- /dev/null
+++ b/priv/repo/migrations/20190222104808_data_migration_normalize_scopes.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.DataMigrationNormalizeScopes do
+ use Ecto.Migration
+
+ def up do
+ for t <- [:apps, :oauth_authorizations, :oauth_tokens] do
+ execute "UPDATE #{t} SET scopes = string_to_array(array_to_string(scopes, ' '), ' ');"
+ end
+ end
+
+ def down, do: :noop
+end
diff --git a/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs b/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs
new file mode 100644
index 000000000..faeb8f1c6
--- /dev/null
+++ b/priv/repo/migrations/20190301101154_add_default_tags_to_user.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddDefaultTagsToUser do
+ use Ecto.Migration
+
+ def up do
+ execute "UPDATE users SET tags = array[]::varchar[] where tags IS NULL"
+ end
+
+ def down, do: :noop
+end
diff --git a/priv/repo/migrations/20190303120636_update_user_note_counters.exs b/priv/repo/migrations/20190303120636_update_user_note_counters.exs
new file mode 100644
index 000000000..54e68f7c9
--- /dev/null
+++ b/priv/repo/migrations/20190303120636_update_user_note_counters.exs
@@ -0,0 +1,41 @@
+defmodule Pleroma.Repo.Migrations.UpdateUserNoteCounters do
+ use Ecto.Migration
+
+ @public "https://www.w3.org/ns/activitystreams#Public"
+
+ def up do
+ execute """
+ WITH public_note_count AS (
+ SELECT
+ data->>'actor' AS actor,
+ count(id) AS count
+ FROM objects
+ WHERE data->>'type' = 'Note' AND (
+ data->'cc' ? '#{@public}' OR data->'to' ? '#{@public}'
+ )
+ GROUP BY data->>'actor'
+ )
+ UPDATE users AS u
+ SET "info" = jsonb_set(u.info, '{note_count}', o.count::varchar::jsonb, true)
+ FROM public_note_count AS o
+ WHERE u.ap_id = o.actor
+ """
+ end
+
+ def down do
+ execute """
+ WITH public_note_count AS (
+ SELECT
+ data->>'actor' AS actor,
+ count(id) AS count
+ FROM objects
+ WHERE data->>'type' = 'Note'
+ GROUP BY data->>'actor'
+ )
+ UPDATE users AS u
+ SET "info" = jsonb_set(u.info, '{note_count}', o.count::varchar::jsonb, true)
+ FROM public_note_count AS o
+ WHERE u.ap_id = o.actor
+ """
+ end
+end