allow_null: options[:null]
)
else
- add_column(table_name, column_name, :datetime_with_timezone, options)
+ add_column(table_name, column_name, :datetime_with_timezone, **options)
end
end
end
options = options.merge({ algorithm: :concurrently })
disable_statement_timeout
- add_index(table_name, column_name, options)
+ add_index(table_name, column_name, **options)
end
# Removes an existed index, concurrently when supported
disable_statement_timeout
end
- remove_index(table_name, options.merge({ column: column_name }))
+ remove_index(table_name, **options.merge({ column: column_name }))
end
# Removes an existing index, concurrently when supported
disable_statement_timeout
end
- remove_index(table_name, options.merge({ name: index_name }))
+ remove_index(table_name, **options.merge({ name: index_name }))
end
# Only available on Postgresql >= 9.2
col_opts[:limit] = old_col.limit
end
- add_column(table, new, new_type, col_opts)
+ add_column(table, new, new_type, **col_opts)
# We set the default value _after_ adding the column so we don't end up
# updating any existing data with the default value. This isn't
new_pk_index_name = "index_#{table}_on_#{column}_cm"
unless indexes_for(table, column).find{|i| i.name == old_pk_index_name}
- add_concurrent_index(table, [temp_column], {
+ add_concurrent_index(table, [temp_column],
unique: true,
name: new_pk_index_name
- })
+ )
end
end
end
options[:using] = index.using if index.using
options[:where] = index.where if index.where
- add_concurrent_index(table, new_columns, options)
+ add_concurrent_index(table, new_columns, **options)
end
end
--- /dev/null
+# frozen_string_literal: true
+
+# Monkey-patch various Paperclip methods for Ruby 3.0 compatibility
+
+module Paperclip
+ module Schema
+ module StatementsExtensions
+ def add_attachment(table_name, *attachment_names)
+ raise ArgumentError, 'Please specify attachment name in your add_attachment call in your migration.' if attachment_names.empty?
+
+ options = attachment_names.extract_options!
+
+ attachment_names.each do |attachment_name|
+ COLUMNS.each_pair do |column_name, column_type|
+ column_options = options.merge(options[column_name.to_sym] || {})
+ add_column(table_name, "#{attachment_name}_#{column_name}", column_type, **column_options)
+ end
+ end
+ end
+ end
+
+ module TableDefinitionExtensions
+ def attachment(*attachment_names)
+ options = attachment_names.extract_options!
+ attachment_names.each do |attachment_name|
+ COLUMNS.each_pair do |column_name, column_type|
+ column_options = options.merge(options[column_name.to_sym] || {})
+ column("#{attachment_name}_#{column_name}", column_type, **column_options)
+ end
+ end
+ end
+ end
+ end
+end
+
+Paperclip::Schema::Statements.prepend(Paperclip::Schema::StatementsExtensions)
+Paperclip::Schema::TableDefinition.prepend(Paperclip::Schema::TableDefinitionExtensions)