mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-24 14:56:27 +00:00
Capture minimum postgres version 12 (#27528)
This commit is contained in:
parent
2d8f759a34
commit
4aa05d45fc
|
@ -67,7 +67,7 @@ Mastodon acts as an OAuth2 provider, so 3rd party apps can use the REST and Stre
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
- **PostgreSQL** 9.5+
|
- **PostgreSQL** 12+
|
||||||
- **Redis** 4+
|
- **Redis** 4+
|
||||||
- **Ruby** 2.7+
|
- **Ruby** 2.7+
|
||||||
- **Node.js** 16+
|
- **Node.js** 16+
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
StrongMigrations.start_after = 2017_09_24_022025
|
StrongMigrations.start_after = 2017_09_24_022025
|
||||||
StrongMigrations.target_version = 10
|
StrongMigrations.target_version = 12
|
||||||
|
|
|
@ -158,10 +158,8 @@ module Mastodon
|
||||||
'in the body of your migration class'
|
'in the body of your migration class'
|
||||||
end
|
end
|
||||||
|
|
||||||
if supports_drop_index_concurrently?
|
options = options.merge({ algorithm: :concurrently })
|
||||||
options = options.merge({ algorithm: :concurrently })
|
disable_statement_timeout
|
||||||
disable_statement_timeout
|
|
||||||
end
|
|
||||||
|
|
||||||
remove_index(table_name, **options.merge({ column: column_name }))
|
remove_index(table_name, **options.merge({ column: column_name }))
|
||||||
end
|
end
|
||||||
|
@ -182,28 +180,12 @@ module Mastodon
|
||||||
'in the body of your migration class'
|
'in the body of your migration class'
|
||||||
end
|
end
|
||||||
|
|
||||||
if supports_drop_index_concurrently?
|
options = options.merge({ algorithm: :concurrently })
|
||||||
options = options.merge({ algorithm: :concurrently })
|
disable_statement_timeout
|
||||||
disable_statement_timeout
|
|
||||||
end
|
|
||||||
|
|
||||||
remove_index(table_name, **options.merge({ name: index_name }))
|
remove_index(table_name, **options.merge({ name: index_name }))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Only available on Postgresql >= 9.2
|
|
||||||
def supports_drop_index_concurrently?
|
|
||||||
version = select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
|
|
||||||
|
|
||||||
version >= 90_200
|
|
||||||
end
|
|
||||||
|
|
||||||
# Only available on Postgresql >= 11
|
|
||||||
def supports_add_column_with_default?
|
|
||||||
version = select_one("SELECT current_setting('server_version_num') AS v")['v'].to_i
|
|
||||||
|
|
||||||
version >= 110_000
|
|
||||||
end
|
|
||||||
|
|
||||||
# Adds a foreign key with only minimal locking on the tables involved.
|
# Adds a foreign key with only minimal locking on the tables involved.
|
||||||
#
|
#
|
||||||
# This method only requires minimal locking when using PostgreSQL. When
|
# This method only requires minimal locking when using PostgreSQL. When
|
||||||
|
@ -420,42 +402,7 @@ module Mastodon
|
||||||
# This method can also take a block which is passed directly to the
|
# This method can also take a block which is passed directly to the
|
||||||
# `update_column_in_batches` method.
|
# `update_column_in_batches` method.
|
||||||
def add_column_with_default(table, column, type, default:, limit: nil, allow_null: false, &block)
|
def add_column_with_default(table, column, type, default:, limit: nil, allow_null: false, &block)
|
||||||
if supports_add_column_with_default?
|
add_column(table, column, type, default: default, limit: limit, null: allow_null)
|
||||||
add_column(table, column, type, default: default, limit: limit, null: allow_null)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if transaction_open?
|
|
||||||
raise 'add_column_with_default can not be run inside a transaction, ' \
|
|
||||||
'you can disable transactions by calling disable_ddl_transaction! ' \
|
|
||||||
'in the body of your migration class'
|
|
||||||
end
|
|
||||||
|
|
||||||
disable_statement_timeout
|
|
||||||
|
|
||||||
transaction do
|
|
||||||
if limit
|
|
||||||
add_column(table, column, type, default: nil, limit: limit)
|
|
||||||
else
|
|
||||||
add_column(table, column, type, default: nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Changing the default before the update ensures any newly inserted
|
|
||||||
# rows already use the proper default value.
|
|
||||||
change_column_default(table, column, default)
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
|
||||||
update_column_in_batches(table, column, default, &block)
|
|
||||||
|
|
||||||
change_column_null(table, column, false) unless allow_null
|
|
||||||
# We want to rescue _all_ exceptions here, even those that don't inherit
|
|
||||||
# from StandardError.
|
|
||||||
rescue Exception => error # rubocop: disable all
|
|
||||||
remove_column(table, column)
|
|
||||||
|
|
||||||
raise error
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Renames a column without requiring downtime.
|
# Renames a column without requiring downtime.
|
||||||
|
|
Loading…
Reference in a new issue