Remove add_column_with_default
migration helper (#28654)
This commit is contained in:
parent
36b46ea3b5
commit
ea1c0feb86
29 changed files with 37 additions and 188 deletions
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddHideNotificationsToMute < ActiveRecord::Migration[5.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
add_column_with_default :mutes, :hide_notifications, :boolean, default: true, allow_null: false
|
||||
add_column :mutes, :hide_notifications, :boolean, default: true, null: false
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddDisabledToCustomEmojis < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :custom_emojis, :disabled, :bool, default: false }
|
||||
safety_assured { add_column :custom_emojis, :disabled, :bool, default: false, null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddReblogsToFollows < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default :follows, :show_reblogs, :boolean, default: true, allow_null: false
|
||||
add_column_with_default :follow_requests, :show_reblogs, :boolean, default: true, allow_null: false
|
||||
add_column :follows, :show_reblogs, :boolean, default: true, null: false
|
||||
add_column :follow_requests, :show_reblogs, :boolean, default: true, null: false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddMemorialToAccounts < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :accounts, :memorial, :bool, default: false }
|
||||
safety_assured { add_column :accounts, :memorial, :bool, default: false, null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddDisabledToUsers < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :users, :disabled, :bool, default: false }
|
||||
safety_assured { add_column :users, :disabled, :bool, default: false, null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddModeratorToAccounts < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :users, :moderator, :bool, default: false }
|
||||
safety_assured { add_column :users, :moderator, :bool, default: false, null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddEmbedURLToPreviewCards < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default :preview_cards, :embed_url, :string, default: '', allow_null: false
|
||||
add_column :preview_cards, :embed_url, :string, default: '', null: false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddAutofollowToInvites < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default :invites, :autofollow, :bool, default: false, allow_null: false
|
||||
add_column :invites, :autofollow, :bool, default: false, null: false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddWholeWordToCustomFilter < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
safety_assured do
|
||||
add_column_with_default :custom_filters, :whole_word, :boolean, default: true, allow_null: false
|
||||
add_column :custom_filters, :whole_word, :boolean, default: true, null: false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddConfidentialToDoorkeeperApplication < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default(
|
||||
add_column(
|
||||
:oauth_applications,
|
||||
:confidential,
|
||||
:boolean,
|
||||
allow_null: false,
|
||||
null: false,
|
||||
default: true # maintaining backwards compatibility: require secrets
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddSilentToMentions < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default(
|
||||
add_column(
|
||||
:mentions,
|
||||
:silent,
|
||||
:boolean,
|
||||
allow_null: false,
|
||||
null: false,
|
||||
default: false
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddRejectReportsToDomainBlocks < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default :domain_blocks, :reject_reports, :boolean, default: false, allow_null: false
|
||||
add_column :domain_blocks, :reject_reports, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddUnreadToAccountConversations < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default(
|
||||
add_column(
|
||||
:account_conversations,
|
||||
:unread,
|
||||
:boolean,
|
||||
allow_null: false,
|
||||
null: false,
|
||||
default: false
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddShowRepliesToLists < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default(
|
||||
add_column(
|
||||
:lists,
|
||||
:replies_policy,
|
||||
:integer,
|
||||
allow_null: false,
|
||||
null: false,
|
||||
default: 0
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddOverwriteToImports < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default :imports, :overwrite, :boolean, default: false, allow_null: false
|
||||
add_column :imports, :overwrite, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddLockVersionToPolls < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default(
|
||||
add_column(
|
||||
:polls,
|
||||
:lock_version,
|
||||
:integer,
|
||||
allow_null: false,
|
||||
null: false,
|
||||
default: 0
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddApprovedToUsers < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default(
|
||||
add_column(
|
||||
:users,
|
||||
:approved,
|
||||
:bool,
|
||||
allow_null: false,
|
||||
null: false,
|
||||
default: true
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddLockVersionToAccountStats < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :account_stats, :lock_version, :integer, allow_null: false, default: 0 }
|
||||
safety_assured { add_column :account_stats, :lock_version, :integer, null: false, default: 0 }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddTitleToAccountWarningPresets < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :account_warning_presets, :title, :string, default: '', allow_null: false }
|
||||
safety_assured { add_column :account_warning_presets, :title, :string, default: '', null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddNotifyToFollows < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default :follows, :notify, :boolean, default: false, allow_null: false
|
||||
add_column_with_default :follow_requests, :notify, :boolean, default: false, allow_null: false
|
||||
add_column :follows, :notify, :boolean, default: false, null: false
|
||||
add_column :follow_requests, :notify, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddObfuscateToDomainBlocks < ActiveRecord::Migration[5.2]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :domain_blocks, :obfuscate, :boolean, default: false, allow_null: false }
|
||||
safety_assured { add_column :domain_blocks, :obfuscate, :boolean, default: false, null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddCategoryToReports < ActiveRecord::Migration[6.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default :reports, :category, :int, default: 0, allow_null: false
|
||||
add_column :reports, :category, :int, default: 0, null: false
|
||||
change_table(:reports, bulk: true) do |t|
|
||||
t.column :action_taken_at, :datetime
|
||||
t.column :rule_ids, :bigint, array: true
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddActionToCustomFilters < ActiveRecord::Migration[6.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured do
|
||||
add_column_with_default :custom_filters, :action, :integer, allow_null: false, default: 0
|
||||
add_column :custom_filters, :action, :integer, null: false, default: 0
|
||||
execute 'UPDATE custom_filters SET action = 1 WHERE irreversible IS TRUE'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddExclusiveToLists < ActiveRecord::Migration[6.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :lists, :exclusive, :boolean, default: false, allow_null: false }
|
||||
safety_assured { add_column :lists, :exclusive, :boolean, default: false, null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddImageDescriptionToPreviewCards < ActiveRecord::Migration[7.0]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :preview_cards, :image_description, :string, default: '', allow_null: false }
|
||||
safety_assured { add_column :preview_cards, :image_description, :string, default: '', null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddIndexableToAccounts < ActiveRecord::Migration[7.0]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :accounts, :indexable, :boolean, default: false, allow_null: false }
|
||||
safety_assured { add_column :accounts, :indexable, :boolean, default: false, null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class RemoveWholeWordFromCustomFilters < ActiveRecord::Migration[6.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
|
@ -15,7 +11,7 @@ class RemoveWholeWordFromCustomFilters < ActiveRecord::Migration[6.1]
|
|||
|
||||
def down
|
||||
safety_assured do
|
||||
add_column_with_default :custom_filters, :whole_word, :boolean, default: true, allow_null: false
|
||||
add_column :custom_filters, :whole_word, :boolean, default: true, null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class RemoveIrreversibleFromCustomFilters < ActiveRecord::Migration[6.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
|
@ -15,7 +11,7 @@ class RemoveIrreversibleFromCustomFilters < ActiveRecord::Migration[6.1]
|
|||
|
||||
def down
|
||||
safety_assured do
|
||||
add_column_with_default :custom_filters, :irreversible, :boolean, allow_null: false, default: false
|
||||
add_column :custom_filters, :irreversible, :boolean, null: false, default: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,18 +104,7 @@ module Mastodon
|
|||
'in the body of your migration class'
|
||||
end
|
||||
|
||||
# If default value is presented, use `add_column_with_default` method instead.
|
||||
if options[:default]
|
||||
add_column_with_default(
|
||||
table_name,
|
||||
column_name,
|
||||
:datetime_with_timezone,
|
||||
default: options[:default],
|
||||
allow_null: options[:null]
|
||||
)
|
||||
else
|
||||
add_column(table_name, column_name, :datetime_with_timezone, **options)
|
||||
end
|
||||
add_column(table_name, column_name, :datetime_with_timezone, **options)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -377,34 +366,6 @@ module Mastodon
|
|||
end
|
||||
end
|
||||
|
||||
# Adds a column with a default value without locking an entire table.
|
||||
#
|
||||
# This method runs the following steps:
|
||||
#
|
||||
# 1. Add the column with a default value of NULL.
|
||||
# 2. Change the default value of the column to the specified value.
|
||||
# 3. Update all existing rows in batches.
|
||||
# 4. Set a `NOT NULL` constraint on the column if desired (the default).
|
||||
#
|
||||
# These steps ensure a column can be added to a large and commonly used
|
||||
# table without locking the entire table for the duration of the table
|
||||
# modification.
|
||||
#
|
||||
# table - The name of the table to update.
|
||||
# column - The name of the column to add.
|
||||
# type - The column type (e.g. `:integer`).
|
||||
# default - The default value for the column.
|
||||
# limit - Sets a column limit. For example, for :integer, the default is
|
||||
# 4-bytes. Set `limit: 8` to allow 8-byte integers.
|
||||
# allow_null - When set to `true` the column will allow NULL values, the
|
||||
# default is to not allow NULL values.
|
||||
#
|
||||
# This method can also take a block which is passed directly to the
|
||||
# `update_column_in_batches` method.
|
||||
def add_column_with_default(table, column, type, default:, limit: nil, allow_null: false, &block)
|
||||
add_column(table, column, type, default: default, limit: limit, null: allow_null)
|
||||
end
|
||||
|
||||
# Renames a column without requiring downtime.
|
||||
#
|
||||
# Concurrent renames work by using database triggers to ensure both the
|
||||
|
|
Loading…
Reference in a new issue