activerecord 6.0.0 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +185 -1
- data/README.rdoc +1 -1
- data/lib/active_record.rb +1 -0
- data/lib/active_record/advisory_lock_base.rb +18 -0
- data/lib/active_record/aggregations.rb +0 -1
- data/lib/active_record/association_relation.rb +10 -8
- data/lib/active_record/associations.rb +2 -2
- data/lib/active_record/associations/alias_tracker.rb +0 -1
- data/lib/active_record/associations/association.rb +5 -1
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +0 -2
- data/lib/active_record/associations/collection_association.rb +6 -2
- data/lib/active_record/associations/collection_proxy.rb +1 -2
- data/lib/active_record/associations/has_many_association.rb +0 -1
- data/lib/active_record/associations/join_dependency.rb +13 -0
- data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
- data/lib/active_record/associations/preloader.rb +2 -3
- data/lib/active_record/attribute_assignment.rb +0 -1
- data/lib/active_record/attribute_decorators.rb +0 -2
- data/lib/active_record/attribute_methods/before_type_cast.rb +0 -1
- data/lib/active_record/attribute_methods/dirty.rb +2 -2
- data/lib/active_record/attribute_methods/primary_key.rb +0 -2
- data/lib/active_record/attribute_methods/read.rb +0 -1
- data/lib/active_record/attribute_methods/serialization.rb +0 -1
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +0 -2
- data/lib/active_record/attribute_methods/write.rb +0 -1
- data/lib/active_record/attributes.rb +0 -1
- data/lib/active_record/autosave_association.rb +8 -6
- data/lib/active_record/callbacks.rb +1 -2
- data/lib/active_record/coders/yaml_column.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +14 -7
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +21 -15
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -2
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +27 -27
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +47 -30
- data/lib/active_record/connection_adapters/abstract/transaction.rb +4 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +23 -8
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +25 -32
- data/lib/active_record/connection_adapters/connection_specification.rb +2 -3
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +8 -12
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +0 -1
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +8 -8
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +9 -3
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +15 -29
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -2
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +8 -7
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +0 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +3 -3
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +12 -7
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_handling.rb +13 -22
- data/lib/active_record/core.rb +8 -6
- data/lib/active_record/counter_cache.rb +4 -1
- data/lib/active_record/database_configurations/url_config.rb +0 -1
- data/lib/active_record/dynamic_matchers.rb +2 -3
- data/lib/active_record/explain.rb +0 -1
- data/lib/active_record/fixture_set/table_row.rb +0 -1
- data/lib/active_record/fixture_set/table_rows.rb +0 -1
- data/lib/active_record/fixtures.rb +0 -3
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/inheritance.rb +0 -3
- data/lib/active_record/insert_all.rb +4 -4
- data/lib/active_record/internal_metadata.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +0 -1
- data/lib/active_record/log_subscriber.rb +1 -1
- data/lib/active_record/middleware/database_selector.rb +0 -1
- data/lib/active_record/middleware/database_selector/resolver.rb +9 -14
- data/lib/active_record/migration.rb +4 -4
- data/lib/active_record/migration/command_recorder.rb +6 -18
- data/lib/active_record/migration/compatibility.rb +3 -3
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/model_schema.rb +3 -2
- data/lib/active_record/nested_attributes.rb +0 -2
- data/lib/active_record/no_touching.rb +2 -2
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +4 -5
- data/lib/active_record/querying.rb +1 -1
- data/lib/active_record/railtie.rb +1 -1
- data/lib/active_record/railties/collection_cache_association_loading.rb +1 -1
- data/lib/active_record/railties/databases.rake +3 -0
- data/lib/active_record/reflection.rb +8 -8
- data/lib/active_record/relation.rb +13 -1
- data/lib/active_record/relation/batches.rb +0 -1
- data/lib/active_record/relation/calculations.rb +1 -1
- data/lib/active_record/relation/delegation.rb +7 -6
- data/lib/active_record/relation/finder_methods.rb +10 -2
- data/lib/active_record/relation/from_clause.rb +4 -0
- data/lib/active_record/relation/merger.rb +0 -1
- data/lib/active_record/relation/predicate_builder.rb +1 -5
- data/lib/active_record/relation/query_methods.rb +37 -12
- data/lib/active_record/relation/spawn_methods.rb +0 -1
- data/lib/active_record/relation/where_clause.rb +0 -1
- data/lib/active_record/result.rb +0 -1
- data/lib/active_record/schema_migration.rb +1 -1
- data/lib/active_record/scoping.rb +0 -1
- data/lib/active_record/scoping/default.rb +0 -1
- data/lib/active_record/scoping/named.rb +3 -3
- data/lib/active_record/store.rb +1 -1
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +16 -1
- data/lib/active_record/tasks/mysql_database_tasks.rb +0 -1
- data/lib/active_record/tasks/postgresql_database_tasks.rb +0 -1
- data/lib/active_record/tasks/sqlite_database_tasks.rb +0 -1
- data/lib/active_record/test_fixtures.rb +2 -1
- data/lib/active_record/timestamp.rb +0 -1
- data/lib/active_record/touch_later.rb +1 -2
- data/lib/active_record/transactions.rb +9 -9
- data/lib/active_record/type.rb +0 -1
- data/lib/active_record/type/adapter_specific_registry.rb +2 -5
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +0 -1
- data/lib/active_record/type/type_map.rb +0 -1
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/validations.rb +2 -3
- data/lib/active_record/validations/associated.rb +1 -2
- data/lib/arel.rb +17 -6
- data/lib/arel/predications.rb +5 -6
- data/lib/arel/visitors/depth_first.rb +0 -1
- data/lib/arel/visitors/dot.rb +0 -1
- data/lib/arel/visitors/mssql.rb +0 -1
- data/lib/arel/visitors/oracle.rb +1 -2
- data/lib/arel/visitors/oracle12.rb +0 -1
- data/lib/arel/visitors/postgresql.rb +0 -1
- data/lib/arel/visitors/sqlite.rb +0 -1
- data/lib/arel/visitors/to_sql.rb +0 -1
- data/lib/arel/visitors/visitor.rb +0 -1
- data/lib/arel/visitors/where_sql.rb +0 -1
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
- data/lib/rails/generators/active_record/migration.rb +0 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +0 -1
- metadata +13 -9
|
@@ -56,7 +56,6 @@ module ActiveRecord
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
private
|
|
59
|
-
|
|
60
59
|
attr_reader :uri
|
|
61
60
|
|
|
62
61
|
def uri_parser
|
|
@@ -73,7 +72,7 @@ module ActiveRecord
|
|
|
73
72
|
# "localhost"
|
|
74
73
|
# # => {}
|
|
75
74
|
def query_hash
|
|
76
|
-
Hash[(@query || "").split("&").map { |pair| pair.split("=") }]
|
|
75
|
+
Hash[(@query || "").split("&").map { |pair| pair.split("=", 2) }]
|
|
77
76
|
end
|
|
78
77
|
|
|
79
78
|
def raw_config
|
|
@@ -186,7 +185,7 @@ module ActiveRecord
|
|
|
186
185
|
adapter_method = "#{spec[:adapter]}_connection"
|
|
187
186
|
|
|
188
187
|
unless ActiveRecord::Base.respond_to?(adapter_method)
|
|
189
|
-
raise AdapterNotFound, "database configuration specifies nonexistent #{spec
|
|
188
|
+
raise AdapterNotFound, "database configuration specifies nonexistent #{spec[:adapter]} adapter"
|
|
190
189
|
end
|
|
191
190
|
|
|
192
191
|
ConnectionSpecification.new(spec.delete(:name) || "primary", spec, adapter_method)
|
|
@@ -5,7 +5,7 @@ module ActiveRecord
|
|
|
5
5
|
module MySQL
|
|
6
6
|
module DatabaseStatements
|
|
7
7
|
# Returns an ActiveRecord::Result instance.
|
|
8
|
-
def select_all(
|
|
8
|
+
def select_all(*, **) # :nodoc:
|
|
9
9
|
result = if ExplainRegistry.collect? && prepared_statements
|
|
10
10
|
unprepared_statement { super }
|
|
11
11
|
else
|
|
@@ -19,7 +19,9 @@ module ActiveRecord
|
|
|
19
19
|
execute(sql, name).to_a
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
|
22
|
+
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
|
23
|
+
:begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback, :describe, :desc, :with
|
|
24
|
+
) # :nodoc:
|
|
23
25
|
private_constant :READ_QUERY
|
|
24
26
|
|
|
25
27
|
def write_query?(sql) # :nodoc:
|
|
@@ -71,8 +73,10 @@ module ActiveRecord
|
|
|
71
73
|
alias :exec_update :exec_delete
|
|
72
74
|
|
|
73
75
|
private
|
|
74
|
-
def execute_batch(
|
|
75
|
-
|
|
76
|
+
def execute_batch(statements, name = nil)
|
|
77
|
+
combine_multi_statements(statements).each do |statement|
|
|
78
|
+
execute(statement, name)
|
|
79
|
+
end
|
|
76
80
|
@connection.abandon_results!
|
|
77
81
|
end
|
|
78
82
|
|
|
@@ -88,14 +92,6 @@ module ActiveRecord
|
|
|
88
92
|
@connection.respond_to?(:set_server_option)
|
|
89
93
|
end
|
|
90
94
|
|
|
91
|
-
def build_truncate_statements(*table_names)
|
|
92
|
-
if table_names.size == 1
|
|
93
|
-
super.first
|
|
94
|
-
else
|
|
95
|
-
super
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
95
|
def multi_statements_enabled?(flags)
|
|
100
96
|
if flags.is_a?(Array)
|
|
101
97
|
flags.include?("MULTI_STATEMENTS")
|
|
@@ -7,7 +7,6 @@ module ActiveRecord
|
|
|
7
7
|
delegate :add_sql_comment!, :mariadb?, to: :@conn, private: true
|
|
8
8
|
|
|
9
9
|
private
|
|
10
|
-
|
|
11
10
|
def visit_DropForeignKey(name)
|
|
12
11
|
"DROP FOREIGN KEY #{name}"
|
|
13
12
|
end
|
|
@@ -63,7 +62,7 @@ module ActiveRecord
|
|
|
63
62
|
end
|
|
64
63
|
|
|
65
64
|
def index_in_create(table_name, column_name, options)
|
|
66
|
-
index_name, index_type, index_columns, _, _, index_using, comment = @conn.add_index_options(table_name, column_name, options)
|
|
65
|
+
index_name, index_type, index_columns, _, _, index_using, comment = @conn.add_index_options(table_name, column_name, **options)
|
|
67
66
|
add_sql_comment!((+"#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})"), comment)
|
|
68
67
|
end
|
|
69
68
|
end
|
|
@@ -51,26 +51,26 @@ module ActiveRecord
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
indexes.map do |index|
|
|
54
|
-
options = index.
|
|
54
|
+
options = index.pop
|
|
55
55
|
|
|
56
56
|
if expressions = options.delete(:expressions)
|
|
57
57
|
orders = options.delete(:orders)
|
|
58
58
|
lengths = options.delete(:lengths)
|
|
59
59
|
|
|
60
|
-
columns = index[-
|
|
60
|
+
columns = index[-1].map { |name|
|
|
61
61
|
[ name.to_sym, expressions[name] || +quote_column_name(name) ]
|
|
62
62
|
}.to_h
|
|
63
63
|
|
|
64
|
-
index[-
|
|
64
|
+
index[-1] = add_options_for_index_columns(
|
|
65
65
|
columns, order: orders, length: lengths
|
|
66
66
|
).values.join(", ")
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
IndexDefinition.new(*index)
|
|
69
|
+
IndexDefinition.new(*index, **options)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
def remove_column(table_name, column_name, type = nil, options
|
|
73
|
+
def remove_column(table_name, column_name, type = nil, **options)
|
|
74
74
|
if foreign_key_exists?(table_name, column: column_name)
|
|
75
75
|
remove_foreign_key(table_name, column: column_name)
|
|
76
76
|
end
|
|
@@ -154,8 +154,8 @@ module ActiveRecord
|
|
|
154
154
|
MySQL::SchemaCreation.new(self)
|
|
155
155
|
end
|
|
156
156
|
|
|
157
|
-
def create_table_definition(*args)
|
|
158
|
-
MySQL::TableDefinition.new(self, *args)
|
|
157
|
+
def create_table_definition(*args, **options)
|
|
158
|
+
MySQL::TableDefinition.new(self, *args, **options)
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
def new_column_from_field(table_name, field)
|
|
@@ -196,7 +196,7 @@ module ActiveRecord
|
|
|
196
196
|
end
|
|
197
197
|
|
|
198
198
|
def add_options_for_index_columns(quoted_columns, **options)
|
|
199
|
-
quoted_columns = add_index_length(quoted_columns, options)
|
|
199
|
+
quoted_columns = add_index_length(quoted_columns, **options)
|
|
200
200
|
super
|
|
201
201
|
end
|
|
202
202
|
|
|
@@ -67,7 +67,9 @@ module ActiveRecord
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
|
70
|
+
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
|
71
|
+
:begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback, :with
|
|
72
|
+
) # :nodoc:
|
|
71
73
|
private_constant :READ_QUERY
|
|
72
74
|
|
|
73
75
|
def write_query?(sql) # :nodoc:
|
|
@@ -164,8 +166,12 @@ module ActiveRecord
|
|
|
164
166
|
end
|
|
165
167
|
|
|
166
168
|
private
|
|
167
|
-
def
|
|
168
|
-
|
|
169
|
+
def execute_batch(statements, name = nil)
|
|
170
|
+
execute(combine_multi_statements(statements))
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def build_truncate_statements(table_names)
|
|
174
|
+
["TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}"]
|
|
169
175
|
end
|
|
170
176
|
|
|
171
177
|
# Returns the current ID of a table's sequence.
|
|
@@ -19,7 +19,7 @@ module ActiveRecord
|
|
|
19
19
|
|
|
20
20
|
def visit_ChangeColumnDefinition(o)
|
|
21
21
|
column = o.column
|
|
22
|
-
column.sql_type = type_to_sql(column.type, column.options)
|
|
22
|
+
column.sql_type = type_to_sql(column.type, **column.options)
|
|
23
23
|
quoted_column_name = quote_column_name(o.name)
|
|
24
24
|
|
|
25
25
|
change_column_sql = +"ALTER COLUMN #{quoted_column_name} TYPE #{column.sql_type}"
|
|
@@ -33,7 +33,7 @@ module ActiveRecord
|
|
|
33
33
|
if options[:using]
|
|
34
34
|
change_column_sql << " USING #{options[:using]}"
|
|
35
35
|
elsif options[:cast_as]
|
|
36
|
-
cast_as_type = type_to_sql(options[:cast_as], options)
|
|
36
|
+
cast_as_type = type_to_sql(options[:cast_as], **options)
|
|
37
37
|
change_column_sql << " USING CAST(#{quoted_column_name} AS #{cast_as_type})"
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -74,7 +74,7 @@ module ActiveRecord
|
|
|
74
74
|
INNER JOIN pg_index d ON t.oid = d.indrelid
|
|
75
75
|
INNER JOIN pg_class i ON d.indexrelid = i.oid
|
|
76
76
|
LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
|
|
77
|
-
WHERE i.relkind
|
|
77
|
+
WHERE i.relkind IN ('i', 'I')
|
|
78
78
|
AND i.relname = #{index[:name]}
|
|
79
79
|
AND t.relname = #{table[:name]}
|
|
80
80
|
AND n.nspname = #{index[:schema]}
|
|
@@ -92,7 +92,7 @@ module ActiveRecord
|
|
|
92
92
|
INNER JOIN pg_index d ON t.oid = d.indrelid
|
|
93
93
|
INNER JOIN pg_class i ON d.indexrelid = i.oid
|
|
94
94
|
LEFT JOIN pg_namespace n ON n.oid = i.relnamespace
|
|
95
|
-
WHERE i.relkind
|
|
95
|
+
WHERE i.relkind IN ('i', 'I')
|
|
96
96
|
AND d.indisprimary = 'f'
|
|
97
97
|
AND t.relname = #{scope[:name]}
|
|
98
98
|
AND n.nspname = #{scope[:schema]}
|
|
@@ -390,7 +390,7 @@ module ActiveRecord
|
|
|
390
390
|
rename_table_indexes(table_name, new_name)
|
|
391
391
|
end
|
|
392
392
|
|
|
393
|
-
def add_column(table_name, column_name, type, options
|
|
393
|
+
def add_column(table_name, column_name, type, **options) #:nodoc:
|
|
394
394
|
clear_cache!
|
|
395
395
|
super
|
|
396
396
|
change_column_comment(table_name, column_name, options[:comment]) if options.key?(:comment)
|
|
@@ -439,7 +439,7 @@ module ActiveRecord
|
|
|
439
439
|
end
|
|
440
440
|
|
|
441
441
|
def add_index(table_name, column_name, options = {}) #:nodoc:
|
|
442
|
-
index_name, index_type, index_columns_and_opclasses, index_options, index_algorithm, index_using, comment = add_index_options(table_name, column_name, options)
|
|
442
|
+
index_name, index_type, index_columns_and_opclasses, index_options, index_algorithm, index_using, comment = add_index_options(table_name, column_name, **options)
|
|
443
443
|
execute("CREATE #{index_type} INDEX #{index_algorithm} #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} #{index_using} (#{index_columns_and_opclasses})#{index_options}").tap do
|
|
444
444
|
execute "COMMENT ON INDEX #{quote_column_name(index_name)} IS #{quote(comment)}" if comment
|
|
445
445
|
end
|
|
@@ -553,12 +553,12 @@ module ActiveRecord
|
|
|
553
553
|
# requires that the ORDER BY include the distinct column.
|
|
554
554
|
def columns_for_distinct(columns, orders) #:nodoc:
|
|
555
555
|
order_columns = orders.reject(&:blank?).map { |s|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
556
|
+
# Convert Arel node to string
|
|
557
|
+
s = visitor.compile(s) unless s.is_a?(String)
|
|
558
|
+
# Remove any ASC/DESC modifiers
|
|
559
|
+
s.gsub(/\s+(?:ASC|DESC)\b/i, "")
|
|
560
|
+
.gsub(/\s+NULLS\s+(?:FIRST|LAST)\b/i, "")
|
|
561
|
+
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
|
|
562
562
|
|
|
563
563
|
(order_columns << super).join(", ")
|
|
564
564
|
end
|
|
@@ -613,8 +613,8 @@ module ActiveRecord
|
|
|
613
613
|
PostgreSQL::SchemaCreation.new(self)
|
|
614
614
|
end
|
|
615
615
|
|
|
616
|
-
def create_table_definition(*args)
|
|
617
|
-
PostgreSQL::TableDefinition.new(self, *args)
|
|
616
|
+
def create_table_definition(*args, **options)
|
|
617
|
+
PostgreSQL::TableDefinition.new(self, *args, **options)
|
|
618
618
|
end
|
|
619
619
|
|
|
620
620
|
def create_alter_table(name)
|
|
@@ -679,14 +679,14 @@ module ActiveRecord
|
|
|
679
679
|
end
|
|
680
680
|
end
|
|
681
681
|
|
|
682
|
-
def add_column_for_alter(table_name, column_name, type, options
|
|
682
|
+
def add_column_for_alter(table_name, column_name, type, **options)
|
|
683
683
|
return super unless options.key?(:comment)
|
|
684
684
|
[super, Proc.new { change_column_comment(table_name, column_name, options[:comment]) }]
|
|
685
685
|
end
|
|
686
686
|
|
|
687
687
|
def change_column_for_alter(table_name, column_name, type, options = {})
|
|
688
688
|
td = create_table_definition(table_name)
|
|
689
|
-
cd = td.new_column_definition(column_name, type, options)
|
|
689
|
+
cd = td.new_column_definition(column_name, type, **options)
|
|
690
690
|
sqls = [schema_creation.accept(ChangeColumnDefinition.new(cd, column_name))]
|
|
691
691
|
sqls << Proc.new { change_column_comment(table_name, column_name, options[:comment]) } if options.key?(:comment)
|
|
692
692
|
sqls
|
|
@@ -711,20 +711,6 @@ module ActiveRecord
|
|
|
711
711
|
"ALTER COLUMN #{quote_column_name(column_name)} #{null ? 'DROP' : 'SET'} NOT NULL"
|
|
712
712
|
end
|
|
713
713
|
|
|
714
|
-
def add_timestamps_for_alter(table_name, options = {})
|
|
715
|
-
options[:null] = false if options[:null].nil?
|
|
716
|
-
|
|
717
|
-
if !options.key?(:precision) && supports_datetime_with_precision?
|
|
718
|
-
options[:precision] = 6
|
|
719
|
-
end
|
|
720
|
-
|
|
721
|
-
[add_column_for_alter(table_name, :created_at, :datetime, options), add_column_for_alter(table_name, :updated_at, :datetime, options)]
|
|
722
|
-
end
|
|
723
|
-
|
|
724
|
-
def remove_timestamps_for_alter(table_name, options = {})
|
|
725
|
-
[remove_column_for_alter(table_name, :updated_at), remove_column_for_alter(table_name, :created_at)]
|
|
726
|
-
end
|
|
727
|
-
|
|
728
714
|
def add_index_opclass(quoted_columns, **options)
|
|
729
715
|
opclasses = options_for_index_columns(options[:opclass])
|
|
730
716
|
quoted_columns.each do |name, column|
|
|
@@ -733,7 +719,7 @@ module ActiveRecord
|
|
|
733
719
|
end
|
|
734
720
|
|
|
735
721
|
def add_options_for_index_columns(quoted_columns, **options)
|
|
736
|
-
quoted_columns = add_index_opclass(quoted_columns, options)
|
|
722
|
+
quoted_columns = add_index_opclass(quoted_columns, **options)
|
|
737
723
|
super
|
|
738
724
|
end
|
|
739
725
|
|
|
@@ -156,6 +156,10 @@ module ActiveRecord
|
|
|
156
156
|
true
|
|
157
157
|
end
|
|
158
158
|
|
|
159
|
+
def supports_partitioned_indexes?
|
|
160
|
+
database_version >= 110_000
|
|
161
|
+
end
|
|
162
|
+
|
|
159
163
|
def supports_partial_index?
|
|
160
164
|
true
|
|
161
165
|
end
|
|
@@ -361,6 +365,10 @@ module ActiveRecord
|
|
|
361
365
|
@has_pg_hint_plan
|
|
362
366
|
end
|
|
363
367
|
|
|
368
|
+
def supports_common_table_expressions?
|
|
369
|
+
true
|
|
370
|
+
end
|
|
371
|
+
|
|
364
372
|
def supports_lazy_transactions?
|
|
365
373
|
true
|
|
366
374
|
end
|
|
@@ -459,7 +467,6 @@ module ActiveRecord
|
|
|
459
467
|
end
|
|
460
468
|
|
|
461
469
|
private
|
|
462
|
-
|
|
463
470
|
# See https://www.postgresql.org/docs/current/static/errcodes-appendix.html
|
|
464
471
|
VALUE_LIMIT_VIOLATION = "22001"
|
|
465
472
|
NUMERIC_VALUE_OUT_OF_RANGE = "22003"
|
|
@@ -626,7 +633,7 @@ module ActiveRecord
|
|
|
626
633
|
SQL
|
|
627
634
|
|
|
628
635
|
if oids
|
|
629
|
-
query += "WHERE t.oid
|
|
636
|
+
query += "WHERE t.oid IN (%s)" % oids.join(", ")
|
|
630
637
|
else
|
|
631
638
|
query += initializer.query_conditions_for_initial_load
|
|
632
639
|
end
|