about summary refs log tree commit diff
path: root/db/migrate
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20210322164601_create_account_summaries.rb2
-rw-r--r--db/migrate/20210421121431_add_case_insensitive_btree_index_to_tags.rb13
-rw-r--r--db/migrate/20210425135952_add_index_on_media_attachments_account_id_status_id.rb13
-rw-r--r--db/migrate/20210505174616_update_follow_recommendations_to_version_2.rb18
4 files changed, 45 insertions, 1 deletions
diff --git a/db/migrate/20210322164601_create_account_summaries.rb b/db/migrate/20210322164601_create_account_summaries.rb
index b9faf180d..bc9011113 100644
--- a/db/migrate/20210322164601_create_account_summaries.rb
+++ b/db/migrate/20210322164601_create_account_summaries.rb
@@ -1,6 +1,6 @@
 class CreateAccountSummaries < ActiveRecord::Migration[5.2]
   def change
-    create_view :account_summaries, materialized: true
+    create_view :account_summaries, materialized: { no_data: true }
 
     # To be able to refresh the view concurrently,
     # at least one unique index is required
diff --git a/db/migrate/20210421121431_add_case_insensitive_btree_index_to_tags.rb b/db/migrate/20210421121431_add_case_insensitive_btree_index_to_tags.rb
new file mode 100644
index 000000000..ed359e8cd
--- /dev/null
+++ b/db/migrate/20210421121431_add_case_insensitive_btree_index_to_tags.rb
@@ -0,0 +1,13 @@
+class AddCaseInsensitiveBtreeIndexToTags < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    safety_assured { execute 'CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower_btree ON tags (lower(name) text_pattern_ops)' }
+    remove_index :tags, name: 'index_tags_on_name_lower'
+  end
+
+  def down
+    safety_assured { execute 'CREATE UNIQUE INDEX CONCURRENTLY index_tags_on_name_lower ON tags (lower(name))' }
+    remove_index :tags, name: 'index_tags_on_name_lower_btree'
+  end
+end
diff --git a/db/migrate/20210425135952_add_index_on_media_attachments_account_id_status_id.rb b/db/migrate/20210425135952_add_index_on_media_attachments_account_id_status_id.rb
new file mode 100644
index 000000000..5ef2d3c39
--- /dev/null
+++ b/db/migrate/20210425135952_add_index_on_media_attachments_account_id_status_id.rb
@@ -0,0 +1,13 @@
+class AddIndexOnMediaAttachmentsAccountIdStatusId < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    add_index :media_attachments, [:account_id, :status_id], order: { status_id: :desc }, algorithm: :concurrently
+    remove_index :media_attachments, :account_id, algorithm: :concurrently
+  end
+
+  def down
+    add_index :media_attachments, :account_id, algorithm: :concurrently
+    remove_index :media_attachments, [:account_id, :status_id], order: { status_id: :desc }, algorithm: :concurrently
+  end
+end
diff --git a/db/migrate/20210505174616_update_follow_recommendations_to_version_2.rb b/db/migrate/20210505174616_update_follow_recommendations_to_version_2.rb
new file mode 100644
index 000000000..56c0b4cb0
--- /dev/null
+++ b/db/migrate/20210505174616_update_follow_recommendations_to_version_2.rb
@@ -0,0 +1,18 @@
+class UpdateFollowRecommendationsToVersion2 < ActiveRecord::Migration[6.1]
+  # We're switching from a normal to a materialized view so we need
+  # custom `up` and `down` paths.
+
+  def up
+    drop_view :follow_recommendations
+    create_view :follow_recommendations, version: 2, materialized: { no_data: true }
+
+    # To be able to refresh the view concurrently,
+    # at least one unique index is required
+    safety_assured { add_index :follow_recommendations, :account_id, unique: true }
+  end
+
+  def down
+    drop_view :follow_recommendations, materialized: true
+    create_view :follow_recommendations, version: 1
+  end
+end