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/20180528141303_fix_accounts_unique_index.rb15
-rw-r--r--db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb40
-rw-r--r--db/migrate/20190715164535_add_instance_actor.rb5
-rw-r--r--db/migrate/20191007013357_update_pt_locales.rb4
-rw-r--r--db/migrate/20200508212852_reset_unique_jobs_locks.rb2
-rw-r--r--db/migrate/20210616214526_create_user_ips.rb5
-rw-r--r--db/migrate/20210621221010_add_skip_sign_in_token_to_users.rb5
-rw-r--r--db/migrate/20210722120340_create_account_statuses_cleanup_policies.rb20
-rw-r--r--db/migrate/20210904215403_add_edited_at_to_statuses.rb5
-rw-r--r--db/migrate/20210908220918_create_status_edits.rb13
-rw-r--r--db/migrate/20211031031021_create_preview_card_providers.rb12
-rw-r--r--db/migrate/20211112011713_add_language_to_preview_cards.rb7
-rw-r--r--db/migrate/20211115032527_add_trendable_to_preview_cards.rb5
-rw-r--r--db/migrate/20211123212714_add_link_type_to_preview_cards.rb5
-rw-r--r--db/migrate/20211213040746_update_account_summaries_to_version_2.rb24
-rw-r--r--db/migrate/20211231080958_add_category_to_reports.rb21
-rw-r--r--db/migrate/20220105163928_remove_mentions_status_id_index.rb9
-rw-r--r--db/migrate/20220115125126_add_report_id_to_account_warnings.rb6
-rw-r--r--db/migrate/20220115125341_fix_account_warning_actions.rb21
-rw-r--r--db/migrate/20220116202951_add_deleted_at_index_on_statuses.rb7
20 files changed, 230 insertions, 1 deletions
diff --git a/db/migrate/20180528141303_fix_accounts_unique_index.rb b/db/migrate/20180528141303_fix_accounts_unique_index.rb
index 02813f363..3e33e2cac 100644
--- a/db/migrate/20180528141303_fix_accounts_unique_index.rb
+++ b/db/migrate/20180528141303_fix_accounts_unique_index.rb
@@ -17,6 +17,21 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2]
     belongs_to :account, inverse_of: :stream_entries
   end
 
+  class Status < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    belongs_to :account
+  end
+
+  class Mention < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    belongs_to :account
+  end
+
+  class StatusPin < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    belongs_to :account
+  end
+
   disable_ddl_transaction!
 
   def up
diff --git a/db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb b/db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb
index bd4f4c2a3..40537e9c9 100644
--- a/db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb
+++ b/db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb
@@ -1,6 +1,46 @@
 class RemoveFauxRemoteAccountDuplicates < ActiveRecord::Migration[5.2]
   disable_ddl_transaction!
 
+  class StreamEntry < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    belongs_to :account, inverse_of: :stream_entries
+  end
+
+  class Status < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    belongs_to :account, inverse_of: :statuses
+    has_many :favourites, inverse_of: :status, dependent: :destroy
+    has_many :mentions, dependent: :destroy, inverse_of: :status
+  end
+
+  class Favourite < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    belongs_to :account, inverse_of: :favourites
+    belongs_to :status,  inverse_of: :favourites
+  end
+
+  class Mention < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    belongs_to :account, inverse_of: :mentions
+    belongs_to :status
+  end
+
+  class Notification < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    belongs_to :account, optional: true
+    belongs_to :from_account, class_name: 'Account', optional: true
+    belongs_to :activity, polymorphic: true, optional: true
+  end
+
+  class Account < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    has_many :stream_entries, inverse_of: :account, dependent: :destroy
+    has_many :statuses, inverse_of: :account, dependent: :destroy
+    has_many :favourites, inverse_of: :account, dependent: :destroy
+    has_many :mentions, inverse_of: :account, dependent: :destroy
+    has_many :notifications, inverse_of: :account, dependent: :destroy
+  end
+
   def up
     local_domain = Rails.configuration.x.local_domain
 
diff --git a/db/migrate/20190715164535_add_instance_actor.rb b/db/migrate/20190715164535_add_instance_actor.rb
index a26d54949..8c0301d69 100644
--- a/db/migrate/20190715164535_add_instance_actor.rb
+++ b/db/migrate/20190715164535_add_instance_actor.rb
@@ -1,4 +1,9 @@
 class AddInstanceActor < ActiveRecord::Migration[5.2]
+  class Account < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+    validates :username, uniqueness: { scope: :domain, case_sensitive: false }
+  end
+
   def up
     Account.create!(id: -99, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain)
   end
diff --git a/db/migrate/20191007013357_update_pt_locales.rb b/db/migrate/20191007013357_update_pt_locales.rb
index b7288d38a..9e8f8b424 100644
--- a/db/migrate/20191007013357_update_pt_locales.rb
+++ b/db/migrate/20191007013357_update_pt_locales.rb
@@ -1,4 +1,8 @@
 class UpdatePtLocales < ActiveRecord::Migration[5.2]
+  class User < ApplicationRecord
+    # Dummy class, to make migration possible across version changes
+  end
+
   disable_ddl_transaction!
 
   def up
diff --git a/db/migrate/20200508212852_reset_unique_jobs_locks.rb b/db/migrate/20200508212852_reset_unique_jobs_locks.rb
index 304e49322..d717ffc54 100644
--- a/db/migrate/20200508212852_reset_unique_jobs_locks.rb
+++ b/db/migrate/20200508212852_reset_unique_jobs_locks.rb
@@ -3,7 +3,7 @@ class ResetUniqueJobsLocks < ActiveRecord::Migration[5.2]
 
   def up
     # We do this to clean up unique job digests that were not properly
-    # disposed of prior to https://github.com/tootsuite/mastodon/pull/13361
+    # disposed of prior to https://github.com/mastodon/mastodon/pull/13361
 
     until SidekiqUniqueJobs::Digests.new.delete_by_pattern('*').nil?; end
   end
diff --git a/db/migrate/20210616214526_create_user_ips.rb b/db/migrate/20210616214526_create_user_ips.rb
new file mode 100644
index 000000000..68e81a9d8
--- /dev/null
+++ b/db/migrate/20210616214526_create_user_ips.rb
@@ -0,0 +1,5 @@
+class CreateUserIps < ActiveRecord::Migration[6.1]
+  def change
+    create_view :user_ips
+  end
+end
diff --git a/db/migrate/20210621221010_add_skip_sign_in_token_to_users.rb b/db/migrate/20210621221010_add_skip_sign_in_token_to_users.rb
new file mode 100644
index 000000000..43ad9b954
--- /dev/null
+++ b/db/migrate/20210621221010_add_skip_sign_in_token_to_users.rb
@@ -0,0 +1,5 @@
+class AddSkipSignInTokenToUsers < ActiveRecord::Migration[6.1]
+  def change
+    add_column :users, :skip_sign_in_token, :boolean
+  end
+end
diff --git a/db/migrate/20210722120340_create_account_statuses_cleanup_policies.rb b/db/migrate/20210722120340_create_account_statuses_cleanup_policies.rb
new file mode 100644
index 000000000..28cfb6ef5
--- /dev/null
+++ b/db/migrate/20210722120340_create_account_statuses_cleanup_policies.rb
@@ -0,0 +1,20 @@
+class CreateAccountStatusesCleanupPolicies < ActiveRecord::Migration[6.1]
+  def change
+    create_table :account_statuses_cleanup_policies do |t|
+      t.belongs_to :account, null: false, foreign_key: { on_delete: :cascade }
+      t.boolean :enabled, null: false, default: true
+      t.integer :min_status_age, null: false, default: 2.weeks.seconds
+      t.boolean :keep_direct, null: false, default: true
+      t.boolean :keep_pinned, null: false, default: true
+      t.boolean :keep_polls, null: false, default: false
+      t.boolean :keep_media, null: false, default: false
+      t.boolean :keep_self_fav, null: false, default: true
+      t.boolean :keep_self_bookmark, null: false, default: true
+      t.integer :min_favs, null: true
+      t.integer :min_reblogs, null: true
+
+      t.timestamps
+    end
+  end
+end
+
diff --git a/db/migrate/20210904215403_add_edited_at_to_statuses.rb b/db/migrate/20210904215403_add_edited_at_to_statuses.rb
new file mode 100644
index 000000000..216ad8e13
--- /dev/null
+++ b/db/migrate/20210904215403_add_edited_at_to_statuses.rb
@@ -0,0 +1,5 @@
+class AddEditedAtToStatuses < ActiveRecord::Migration[6.1]
+  def change
+    add_column :statuses, :edited_at, :datetime
+  end
+end
diff --git a/db/migrate/20210908220918_create_status_edits.rb b/db/migrate/20210908220918_create_status_edits.rb
new file mode 100644
index 000000000..6c90149d0
--- /dev/null
+++ b/db/migrate/20210908220918_create_status_edits.rb
@@ -0,0 +1,13 @@
+class CreateStatusEdits < ActiveRecord::Migration[6.1]
+  def change
+    create_table :status_edits do |t|
+      t.belongs_to :status, null: false, foreign_key: { on_delete: :cascade }
+      t.belongs_to :account, null: true, foreign_key: { on_delete: :nullify }
+      t.text :text, null: false, default: ''
+      t.text :spoiler_text, null: false, default: ''
+      t.boolean :media_attachments_changed, null: false, default: false
+
+      t.timestamps
+    end
+  end
+end
diff --git a/db/migrate/20211031031021_create_preview_card_providers.rb b/db/migrate/20211031031021_create_preview_card_providers.rb
new file mode 100644
index 000000000..0bd46198e
--- /dev/null
+++ b/db/migrate/20211031031021_create_preview_card_providers.rb
@@ -0,0 +1,12 @@
+class CreatePreviewCardProviders < ActiveRecord::Migration[6.1]
+  def change
+    create_table :preview_card_providers do |t|
+      t.string :domain, null: false, default: '', index: { unique: true }
+      t.attachment :icon
+      t.boolean :trendable
+      t.datetime :reviewed_at
+      t.datetime :requested_review_at
+      t.timestamps
+    end
+  end
+end
diff --git a/db/migrate/20211112011713_add_language_to_preview_cards.rb b/db/migrate/20211112011713_add_language_to_preview_cards.rb
new file mode 100644
index 000000000..995934de4
--- /dev/null
+++ b/db/migrate/20211112011713_add_language_to_preview_cards.rb
@@ -0,0 +1,7 @@
+class AddLanguageToPreviewCards < ActiveRecord::Migration[6.1]
+  def change
+    add_column :preview_cards, :language, :string
+    add_column :preview_cards, :max_score, :float
+    add_column :preview_cards, :max_score_at, :datetime
+  end
+end
diff --git a/db/migrate/20211115032527_add_trendable_to_preview_cards.rb b/db/migrate/20211115032527_add_trendable_to_preview_cards.rb
new file mode 100644
index 000000000..87bf3d7a2
--- /dev/null
+++ b/db/migrate/20211115032527_add_trendable_to_preview_cards.rb
@@ -0,0 +1,5 @@
+class AddTrendableToPreviewCards < ActiveRecord::Migration[6.1]
+  def change
+    add_column :preview_cards, :trendable, :boolean
+  end
+end
diff --git a/db/migrate/20211123212714_add_link_type_to_preview_cards.rb b/db/migrate/20211123212714_add_link_type_to_preview_cards.rb
new file mode 100644
index 000000000..9f57e0219
--- /dev/null
+++ b/db/migrate/20211123212714_add_link_type_to_preview_cards.rb
@@ -0,0 +1,5 @@
+class AddLinkTypeToPreviewCards < ActiveRecord::Migration[6.1]
+  def change
+    add_column :preview_cards, :link_type, :int
+  end
+end
diff --git a/db/migrate/20211213040746_update_account_summaries_to_version_2.rb b/db/migrate/20211213040746_update_account_summaries_to_version_2.rb
new file mode 100644
index 000000000..0d1f092ec
--- /dev/null
+++ b/db/migrate/20211213040746_update_account_summaries_to_version_2.rb
@@ -0,0 +1,24 @@
+class UpdateAccountSummariesToVersion2 < ActiveRecord::Migration[6.1]
+  def up
+    reapplication_follow_recommendations_v2 do
+      drop_view :account_summaries, materialized: true
+      create_view :account_summaries, version: 2, materialized: { no_data: true }
+      safety_assured { add_index :account_summaries, :account_id, unique: true }
+    end
+  end
+
+  def down
+    reapplication_follow_recommendations_v2 do
+      drop_view :account_summaries, materialized: true
+      create_view :account_summaries, version: 1, materialized: { no_data: true }
+      safety_assured { add_index :account_summaries, :account_id, unique: true }
+    end
+  end
+
+  def reapplication_follow_recommendations_v2
+    drop_view :follow_recommendations, materialized: true
+    yield
+    create_view :follow_recommendations, version: 2, materialized: { no_data: true }
+    safety_assured { add_index :follow_recommendations, :account_id, unique: true }
+  end
+end
diff --git a/db/migrate/20211231080958_add_category_to_reports.rb b/db/migrate/20211231080958_add_category_to_reports.rb
new file mode 100644
index 000000000..c2b495c63
--- /dev/null
+++ b/db/migrate/20211231080958_add_category_to_reports.rb
@@ -0,0 +1,21 @@
+require Rails.root.join('lib', 'mastodon', 'migration_helpers')
+
+class AddCategoryToReports < ActiveRecord::Migration[6.1]
+  include Mastodon::MigrationHelpers
+
+  disable_ddl_transaction!
+
+  def up
+    safety_assured { add_column_with_default :reports, :category, :int, default: 0, allow_null: false }
+    add_column :reports, :action_taken_at, :datetime
+    add_column :reports, :rule_ids, :bigint, array: true
+    safety_assured { execute 'UPDATE reports SET action_taken_at = updated_at WHERE action_taken = TRUE' }
+  end
+
+  def down
+    safety_assured { execute 'UPDATE reports SET action_taken = TRUE WHERE action_taken_at IS NOT NULL' }
+    remove_column :reports, :category
+    remove_column :reports, :action_taken_at
+    remove_column :reports, :rule_ids
+  end
+end
diff --git a/db/migrate/20220105163928_remove_mentions_status_id_index.rb b/db/migrate/20220105163928_remove_mentions_status_id_index.rb
new file mode 100644
index 000000000..56e903719
--- /dev/null
+++ b/db/migrate/20220105163928_remove_mentions_status_id_index.rb
@@ -0,0 +1,9 @@
+class RemoveMentionsStatusIdIndex < ActiveRecord::Migration[6.1]
+  def up
+    remove_index :mentions, name: :mentions_status_id_index if index_exists?(:mentions, :status_id, name: :mentions_status_id_index)
+  end
+
+  def down
+    # As this index should not exist and is a duplicate of another index, do not re-create it
+  end
+end
diff --git a/db/migrate/20220115125126_add_report_id_to_account_warnings.rb b/db/migrate/20220115125126_add_report_id_to_account_warnings.rb
new file mode 100644
index 000000000..a1c20c99e
--- /dev/null
+++ b/db/migrate/20220115125126_add_report_id_to_account_warnings.rb
@@ -0,0 +1,6 @@
+class AddReportIdToAccountWarnings < ActiveRecord::Migration[6.1]
+  def change
+    safety_assured { add_reference :account_warnings, :report, foreign_key: { on_delete: :cascade }, index: false }
+    add_column :account_warnings, :status_ids, :string, array: true
+  end
+end
diff --git a/db/migrate/20220115125341_fix_account_warning_actions.rb b/db/migrate/20220115125341_fix_account_warning_actions.rb
new file mode 100644
index 000000000..25cc17fd3
--- /dev/null
+++ b/db/migrate/20220115125341_fix_account_warning_actions.rb
@@ -0,0 +1,21 @@
+class FixAccountWarningActions < ActiveRecord::Migration[6.1]
+  disable_ddl_transaction!
+
+  def up
+    safety_assured do
+      execute 'UPDATE account_warnings SET action = 1000 WHERE action = 1'
+      execute 'UPDATE account_warnings SET action = 2000 WHERE action = 2'
+      execute 'UPDATE account_warnings SET action = 3000 WHERE action = 3'
+      execute 'UPDATE account_warnings SET action = 4000 WHERE action = 4'
+    end
+  end
+
+  def down
+    safety_assured do
+      execute 'UPDATE account_warnings SET action = 1 WHERE action = 1000'
+      execute 'UPDATE account_warnings SET action = 2 WHERE action = 2000'
+      execute 'UPDATE account_warnings SET action = 3 WHERE action = 3000'
+      execute 'UPDATE account_warnings SET action = 4 WHERE action = 4000'
+    end
+  end
+end
diff --git a/db/migrate/20220116202951_add_deleted_at_index_on_statuses.rb b/db/migrate/20220116202951_add_deleted_at_index_on_statuses.rb
new file mode 100644
index 000000000..dc3362552
--- /dev/null
+++ b/db/migrate/20220116202951_add_deleted_at_index_on_statuses.rb
@@ -0,0 +1,7 @@
+class AddDeletedAtIndexOnStatuses < ActiveRecord::Migration[6.1]
+  disable_ddl_transaction!
+
+  def change
+    add_index :statuses, :deleted_at, where: 'deleted_at IS NOT NULL', algorithm: :concurrently
+  end
+end