summaryrefslogtreecommitdiff
path: root/priv/repo/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'priv/repo/migrations')
-rw-r--r--priv/repo/migrations/20170426154155_create_websub_client_subscription.exs2
-rw-r--r--priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs2
-rw-r--r--priv/repo/migrations/20170906152508_create_o_auth_token.exs2
-rw-r--r--priv/repo/migrations/20180813003722_create_filters.exs2
-rw-r--r--priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs2
-rw-r--r--priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs9
-rw-r--r--priv/repo/migrations/20190123092341_users_add_is_admin_index.exs7
-rw-r--r--priv/repo/migrations/20190123125546_create_instances.exs15
-rw-r--r--priv/repo/migrations/20190203185340_split_hide_network.exs12
-rw-r--r--priv/repo/migrations/20190204200237_add_correct_dm_index.exs30
-rw-r--r--priv/repo/migrations/20190205114625_create_thread_mutes.exs12
-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
-rw-r--r--priv/repo/migrations/20190315101315_create_registrations.exs18
-rw-r--r--priv/repo/migrations/20190325185009_create_notification_id_index.exs7
-rw-r--r--priv/repo/migrations/20190328053912_create_scheduled_activities.exs16
-rw-r--r--priv/repo/migrations/20190403131720_add_oauth_token_indexes.exs9
-rw-r--r--priv/repo/migrations/20190404050946_add_fields_to_user_invite_tokens.exs12
-rw-r--r--priv/repo/migrations/20190405160700_add_index_on_subscribers.exs8
23 files changed, 260 insertions, 5 deletions
diff --git a/priv/repo/migrations/20170426154155_create_websub_client_subscription.exs b/priv/repo/migrations/20170426154155_create_websub_client_subscription.exs
index f42782840..89d3af7ae 100644
--- a/priv/repo/migrations/20170426154155_create_websub_client_subscription.exs
+++ b/priv/repo/migrations/20170426154155_create_websub_client_subscription.exs
@@ -5,7 +5,7 @@ defmodule Pleroma.Repo.Migrations.CreateWebsubClientSubscription do
create table(:websub_client_subscriptions) do
add :topic, :string
add :secret, :string
- add :valid_until, :naive_datetime
+ add :valid_until, :naive_datetime_usec
add :state, :string
add :subscribers, :map
diff --git a/priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs b/priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs
index b4332870e..ead1d023e 100644
--- a/priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs
+++ b/priv/repo/migrations/20170906143140_create_o_auth_authorizations.exs
@@ -6,7 +6,7 @@ defmodule Pleroma.Repo.Migrations.CreateOAuthAuthorizations do
add :app_id, references(:apps)
add :user_id, references(:users)
add :token, :string
- add :valid_until, :naive_datetime
+ add :valid_until, :naive_datetime_usec
add :used, :boolean, default: false
timestamps()
diff --git a/priv/repo/migrations/20170906152508_create_o_auth_token.exs b/priv/repo/migrations/20170906152508_create_o_auth_token.exs
index 7f8550f33..ed56bbf36 100644
--- a/priv/repo/migrations/20170906152508_create_o_auth_token.exs
+++ b/priv/repo/migrations/20170906152508_create_o_auth_token.exs
@@ -7,7 +7,7 @@ defmodule Pleroma.Repo.Migrations.CreateOAuthToken do
add :user_id, references(:users)
add :token, :string
add :refresh_token, :string
- add :valid_until, :naive_datetime
+ add :valid_until, :naive_datetime_usec
timestamps()
end
diff --git a/priv/repo/migrations/20180813003722_create_filters.exs b/priv/repo/migrations/20180813003722_create_filters.exs
index a273004ee..8e7129f34 100644
--- a/priv/repo/migrations/20180813003722_create_filters.exs
+++ b/priv/repo/migrations/20180813003722_create_filters.exs
@@ -8,7 +8,7 @@ defmodule Pleroma.Repo.Migrations.CreateFilters do
add :hide, :boolean
add :phrase, :string
add :context, {:array, :string}
- add :expires_at, :datetime
+ add :expires_at, :utc_datetime
add :whole_word, :boolean
timestamps()
diff --git a/priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs b/priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs
index 1942e4e9c..815177e05 100644
--- a/priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs
+++ b/priv/repo/migrations/20180919060348_users_add_last_refreshed_at.exs
@@ -3,7 +3,7 @@ defmodule Pleroma.Repo.Migrations.UsersAddLastRefreshedAt do
def change do
alter table(:users) do
- add :last_refreshed_at, :naive_datetime
+ add :last_refreshed_at, :naive_datetime_usec
end
end
end
diff --git a/priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs b/priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs
new file mode 100644
index 000000000..55e97ae0e
--- /dev/null
+++ b/priv/repo/migrations/20181214121049_add_bookmarks_to_users.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddBookmarksToUsers do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ add :bookmarks, {:array, :string}, null: false, default: []
+ end
+ end
+end
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/20190123125546_create_instances.exs b/priv/repo/migrations/20190123125546_create_instances.exs
new file mode 100644
index 000000000..3d23b343e
--- /dev/null
+++ b/priv/repo/migrations/20190123125546_create_instances.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Repo.Migrations.CreateInstances do
+ use Ecto.Migration
+
+ def change do
+ create table(:instances) do
+ add :host, :string
+ add :unreachable_since, :naive_datetime_usec
+
+ timestamps()
+ end
+
+ create unique_index(:instances, [:host])
+ create index(:instances, [:unreachable_since])
+ end
+end
diff --git a/priv/repo/migrations/20190203185340_split_hide_network.exs b/priv/repo/migrations/20190203185340_split_hide_network.exs
new file mode 100644
index 000000000..8b7a9151b
--- /dev/null
+++ b/priv/repo/migrations/20190203185340_split_hide_network.exs
@@ -0,0 +1,12 @@
+defmodule Pleroma.Repo.Migrations.SplitHideNetwork do
+ use Ecto.Migration
+
+ def up do
+ execute("UPDATE users SET info = jsonb_set(info, '{hide_network}'::text[], 'false'::jsonb) WHERE NOT(info::jsonb ? 'hide_network') AND local")
+ execute("UPDATE users SET info = jsonb_set(info, '{hide_followings}'::text[], info->'hide_network') WHERE local")
+ execute("UPDATE users SET info = jsonb_set(info, '{hide_followers}'::text[], info->'hide_network') WHERE local")
+ end
+
+ def down do
+ end
+end
diff --git a/priv/repo/migrations/20190204200237_add_correct_dm_index.exs b/priv/repo/migrations/20190204200237_add_correct_dm_index.exs
new file mode 100644
index 000000000..558732cd2
--- /dev/null
+++ b/priv/repo/migrations/20190204200237_add_correct_dm_index.exs
@@ -0,0 +1,30 @@
+defmodule Pleroma.Repo.Migrations.AddCorrectDMIndex do
+ use Ecto.Migration
+ @disable_ddl_transaction true
+
+ def up do
+ drop_if_exists(
+ index(:activities, ["activity_visibility(actor, recipients, data)"],
+ name: :activities_visibility_index
+ )
+ )
+
+ create(
+ index(:activities, ["activity_visibility(actor, recipients, data)", "id DESC NULLS LAST"],
+ name: :activities_visibility_index,
+ concurrently: true,
+ where: "data->>'type' = 'Create'"
+ )
+ )
+ end
+
+ def down do
+ drop(
+ index(:activities, ["activity_visibility(actor, recipients, data)", "id DESC"],
+ name: :activities_visibility_index,
+ concurrently: true,
+ where: "data->>'type' = 'Create'"
+ )
+ )
+ end
+end
diff --git a/priv/repo/migrations/20190205114625_create_thread_mutes.exs b/priv/repo/migrations/20190205114625_create_thread_mutes.exs
new file mode 100644
index 000000000..8e9eccbae
--- /dev/null
+++ b/priv/repo/migrations/20190205114625_create_thread_mutes.exs
@@ -0,0 +1,12 @@
+defmodule Pleroma.Repo.Migrations.CreateThreadMutes do
+ use Ecto.Migration
+
+ def change do
+ create table(:thread_mutes) do
+ add :user_id, references(:users, type: :uuid, on_delete: :delete_all)
+ add :context, :string
+ end
+
+ create unique_index(:thread_mutes, [:user_id, :context], name: :unique_index)
+ 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
diff --git a/priv/repo/migrations/20190315101315_create_registrations.exs b/priv/repo/migrations/20190315101315_create_registrations.exs
new file mode 100644
index 000000000..6b28cbdd3
--- /dev/null
+++ b/priv/repo/migrations/20190315101315_create_registrations.exs
@@ -0,0 +1,18 @@
+defmodule Pleroma.Repo.Migrations.CreateRegistrations do
+ use Ecto.Migration
+
+ def change do
+ create table(:registrations, primary_key: false) do
+ add :id, :uuid, primary_key: true
+ add :user_id, references(:users, type: :uuid, on_delete: :delete_all)
+ add :provider, :string
+ add :uid, :string
+ add :info, :map, default: %{}
+
+ timestamps()
+ end
+
+ create unique_index(:registrations, [:provider, :uid])
+ create unique_index(:registrations, [:user_id, :provider, :uid])
+ end
+end
diff --git a/priv/repo/migrations/20190325185009_create_notification_id_index.exs b/priv/repo/migrations/20190325185009_create_notification_id_index.exs
new file mode 100644
index 000000000..a6ab38d02
--- /dev/null
+++ b/priv/repo/migrations/20190325185009_create_notification_id_index.exs
@@ -0,0 +1,7 @@
+defmodule Pleroma.Repo.Migrations.CreateNotificationIdIndex do
+ use Ecto.Migration
+
+ def change do
+ create index(:notifications, ["id desc nulls last"])
+ end
+end
diff --git a/priv/repo/migrations/20190328053912_create_scheduled_activities.exs b/priv/repo/migrations/20190328053912_create_scheduled_activities.exs
new file mode 100644
index 000000000..dd737e25a
--- /dev/null
+++ b/priv/repo/migrations/20190328053912_create_scheduled_activities.exs
@@ -0,0 +1,16 @@
+defmodule Pleroma.Repo.Migrations.CreateScheduledActivities do
+ use Ecto.Migration
+
+ def change do
+ create table(:scheduled_activities) do
+ add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
+ add(:scheduled_at, :naive_datetime, null: false)
+ add(:params, :map, null: false)
+
+ timestamps()
+ end
+
+ create(index(:scheduled_activities, [:scheduled_at]))
+ create(index(:scheduled_activities, [:user_id]))
+ end
+end
diff --git a/priv/repo/migrations/20190403131720_add_oauth_token_indexes.exs b/priv/repo/migrations/20190403131720_add_oauth_token_indexes.exs
new file mode 100644
index 000000000..ebcd29389
--- /dev/null
+++ b/priv/repo/migrations/20190403131720_add_oauth_token_indexes.exs
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddOauthTokenIndexes do
+ use Ecto.Migration
+
+ def change do
+ create(unique_index(:oauth_tokens, [:token]))
+ create(index(:oauth_tokens, [:app_id]))
+ create(index(:oauth_tokens, [:user_id]))
+ end
+end
diff --git a/priv/repo/migrations/20190404050946_add_fields_to_user_invite_tokens.exs b/priv/repo/migrations/20190404050946_add_fields_to_user_invite_tokens.exs
new file mode 100644
index 000000000..211a14135
--- /dev/null
+++ b/priv/repo/migrations/20190404050946_add_fields_to_user_invite_tokens.exs
@@ -0,0 +1,12 @@
+defmodule Pleroma.Repo.Migrations.AddFieldsToUserInviteTokens do
+ use Ecto.Migration
+
+ def change do
+ alter table(:user_invite_tokens) do
+ add(:expires_at, :date)
+ add(:uses, :integer, default: 0)
+ add(:max_use, :integer)
+ add(:invite_type, :string, default: "one_time")
+ end
+ end
+end
diff --git a/priv/repo/migrations/20190405160700_add_index_on_subscribers.exs b/priv/repo/migrations/20190405160700_add_index_on_subscribers.exs
new file mode 100644
index 000000000..232f75c92
--- /dev/null
+++ b/priv/repo/migrations/20190405160700_add_index_on_subscribers.exs
@@ -0,0 +1,8 @@
+defmodule Pleroma.Repo.Migrations.AddIndexOnSubscribers do
+ use Ecto.Migration
+
+ @disable_ddl_transaction true
+ def change do
+ create index(:users, ["(info->'subscribers')"], name: :users_subscribers_index, using: :gin, concurrently: true)
+ end
+end