activerecord 6.0.0.beta1 → 6.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +529 -10
  3. data/README.rdoc +3 -1
  4. data/lib/active_record.rb +7 -1
  5. data/lib/active_record/association_relation.rb +15 -6
  6. data/lib/active_record/associations.rb +4 -3
  7. data/lib/active_record/associations/association.rb +27 -2
  8. data/lib/active_record/associations/builder/association.rb +14 -18
  9. data/lib/active_record/associations/builder/belongs_to.rb +5 -2
  10. data/lib/active_record/associations/builder/collection_association.rb +5 -15
  11. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +1 -1
  12. data/lib/active_record/associations/builder/has_many.rb +2 -0
  13. data/lib/active_record/associations/builder/has_one.rb +35 -1
  14. data/lib/active_record/associations/builder/singular_association.rb +2 -0
  15. data/lib/active_record/associations/collection_association.rb +5 -6
  16. data/lib/active_record/associations/collection_proxy.rb +13 -42
  17. data/lib/active_record/associations/has_many_association.rb +1 -9
  18. data/lib/active_record/associations/has_many_through_association.rb +4 -11
  19. data/lib/active_record/associations/join_dependency.rb +14 -9
  20. data/lib/active_record/associations/join_dependency/join_association.rb +21 -7
  21. data/lib/active_record/associations/preloader.rb +12 -7
  22. data/lib/active_record/associations/preloader/association.rb +37 -34
  23. data/lib/active_record/associations/preloader/through_association.rb +48 -39
  24. data/lib/active_record/attribute_methods.rb +3 -53
  25. data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
  26. data/lib/active_record/attribute_methods/dirty.rb +47 -14
  27. data/lib/active_record/attribute_methods/primary_key.rb +7 -15
  28. data/lib/active_record/attribute_methods/query.rb +2 -3
  29. data/lib/active_record/attribute_methods/read.rb +3 -9
  30. data/lib/active_record/attribute_methods/write.rb +6 -12
  31. data/lib/active_record/attributes.rb +13 -0
  32. data/lib/active_record/autosave_association.rb +21 -7
  33. data/lib/active_record/base.rb +0 -1
  34. data/lib/active_record/callbacks.rb +3 -3
  35. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +134 -23
  36. data/lib/active_record/connection_adapters/abstract/database_limits.rb +8 -4
  37. data/lib/active_record/connection_adapters/abstract/database_statements.rb +105 -70
  38. data/lib/active_record/connection_adapters/abstract/query_cache.rb +12 -5
  39. data/lib/active_record/connection_adapters/abstract/quoting.rb +63 -6
  40. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +5 -2
  41. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +51 -40
  42. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -1
  43. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +95 -30
  44. data/lib/active_record/connection_adapters/abstract/transaction.rb +17 -6
  45. data/lib/active_record/connection_adapters/abstract_adapter.rb +115 -35
  46. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +106 -138
  47. data/lib/active_record/connection_adapters/column.rb +17 -13
  48. data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
  49. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +3 -3
  50. data/lib/active_record/connection_adapters/mysql/database_statements.rb +48 -8
  51. data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
  52. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +40 -32
  53. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
  54. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +66 -5
  55. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
  56. data/lib/active_record/connection_adapters/mysql2_adapter.rb +18 -5
  57. data/lib/active_record/connection_adapters/postgresql/column.rb +17 -30
  58. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +8 -2
  59. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
  60. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
  61. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +6 -3
  62. data/lib/active_record/connection_adapters/postgresql/quoting.rb +40 -3
  63. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +36 -0
  64. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +98 -89
  65. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +47 -63
  66. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +23 -27
  67. data/lib/active_record/connection_adapters/postgresql_adapter.rb +95 -24
  68. data/lib/active_record/connection_adapters/schema_cache.rb +32 -14
  69. data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
  70. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +120 -0
  71. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +38 -2
  72. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +28 -2
  73. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +73 -118
  74. data/lib/active_record/connection_handling.rb +40 -17
  75. data/lib/active_record/core.rb +35 -24
  76. data/lib/active_record/database_configurations.rb +99 -50
  77. data/lib/active_record/database_configurations/hash_config.rb +11 -11
  78. data/lib/active_record/database_configurations/url_config.rb +21 -16
  79. data/lib/active_record/dynamic_matchers.rb +1 -1
  80. data/lib/active_record/enum.rb +15 -0
  81. data/lib/active_record/errors.rb +18 -13
  82. data/lib/active_record/fixtures.rb +11 -6
  83. data/lib/active_record/gem_version.rb +2 -2
  84. data/lib/active_record/inheritance.rb +1 -1
  85. data/lib/active_record/insert_all.rb +179 -0
  86. data/lib/active_record/integration.rb +13 -1
  87. data/lib/active_record/internal_metadata.rb +5 -1
  88. data/lib/active_record/locking/optimistic.rb +3 -4
  89. data/lib/active_record/log_subscriber.rb +1 -1
  90. data/lib/active_record/middleware/database_selector.rb +75 -0
  91. data/lib/active_record/middleware/database_selector/resolver.rb +88 -0
  92. data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
  93. data/lib/active_record/migration.rb +62 -44
  94. data/lib/active_record/migration/command_recorder.rb +28 -14
  95. data/lib/active_record/migration/compatibility.rb +72 -63
  96. data/lib/active_record/model_schema.rb +3 -0
  97. data/lib/active_record/persistence.rb +212 -19
  98. data/lib/active_record/querying.rb +18 -14
  99. data/lib/active_record/railtie.rb +9 -1
  100. data/lib/active_record/railties/collection_cache_association_loading.rb +3 -3
  101. data/lib/active_record/railties/databases.rake +124 -25
  102. data/lib/active_record/reflection.rb +18 -32
  103. data/lib/active_record/relation.rb +185 -35
  104. data/lib/active_record/relation/calculations.rb +40 -44
  105. data/lib/active_record/relation/delegation.rb +23 -31
  106. data/lib/active_record/relation/finder_methods.rb +23 -14
  107. data/lib/active_record/relation/merger.rb +11 -16
  108. data/lib/active_record/relation/query_attribute.rb +5 -3
  109. data/lib/active_record/relation/query_methods.rb +230 -69
  110. data/lib/active_record/relation/spawn_methods.rb +1 -1
  111. data/lib/active_record/relation/where_clause.rb +10 -10
  112. data/lib/active_record/sanitization.rb +33 -4
  113. data/lib/active_record/schema.rb +1 -1
  114. data/lib/active_record/schema_dumper.rb +10 -1
  115. data/lib/active_record/schema_migration.rb +1 -1
  116. data/lib/active_record/scoping.rb +6 -7
  117. data/lib/active_record/scoping/default.rb +7 -15
  118. data/lib/active_record/scoping/named.rb +10 -2
  119. data/lib/active_record/statement_cache.rb +2 -2
  120. data/lib/active_record/store.rb +48 -0
  121. data/lib/active_record/table_metadata.rb +9 -13
  122. data/lib/active_record/tasks/database_tasks.rb +109 -6
  123. data/lib/active_record/tasks/mysql_database_tasks.rb +3 -1
  124. data/lib/active_record/test_databases.rb +1 -16
  125. data/lib/active_record/test_fixtures.rb +2 -2
  126. data/lib/active_record/timestamp.rb +35 -19
  127. data/lib/active_record/touch_later.rb +4 -2
  128. data/lib/active_record/transactions.rb +56 -46
  129. data/lib/active_record/type_caster/connection.rb +16 -10
  130. data/lib/active_record/validations.rb +1 -0
  131. data/lib/active_record/validations/uniqueness.rb +4 -4
  132. data/lib/arel.rb +18 -4
  133. data/lib/arel/insert_manager.rb +3 -3
  134. data/lib/arel/nodes.rb +2 -1
  135. data/lib/arel/nodes/and.rb +1 -1
  136. data/lib/arel/nodes/case.rb +1 -1
  137. data/lib/arel/nodes/comment.rb +29 -0
  138. data/lib/arel/nodes/select_core.rb +16 -12
  139. data/lib/arel/nodes/unary.rb +1 -0
  140. data/lib/arel/nodes/values_list.rb +2 -17
  141. data/lib/arel/select_manager.rb +10 -10
  142. data/lib/arel/visitors/depth_first.rb +7 -2
  143. data/lib/arel/visitors/dot.rb +7 -2
  144. data/lib/arel/visitors/ibm_db.rb +13 -0
  145. data/lib/arel/visitors/informix.rb +6 -0
  146. data/lib/arel/visitors/mssql.rb +15 -1
  147. data/lib/arel/visitors/oracle12.rb +4 -5
  148. data/lib/arel/visitors/postgresql.rb +4 -10
  149. data/lib/arel/visitors/to_sql.rb +107 -131
  150. data/lib/arel/visitors/visitor.rb +9 -5
  151. data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
  152. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
  153. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
  154. data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
  155. data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
  156. metadata +19 -12
  157. data/lib/active_record/collection_cache_key.rb +0 -53
  158. data/lib/arel/nodes/values.rb +0 -16
@@ -7,7 +7,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
7
7
  <%- elsif attribute.token? -%>
8
8
  add_column :<%= table_name %>, :<%= attribute.name %>, :string<%= attribute.inject_options %>
9
9
  add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true
10
- <%- else -%>
10
+ <%- elsif !attribute.virtual? -%>
11
11
  add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
12
12
  <%- if attribute.has_index? -%>
13
13
  add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
@@ -21,7 +21,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
21
21
  <%- attributes.each do |attribute| -%>
22
22
  <%- if attribute.reference? -%>
23
23
  t.references :<%= attribute.name %><%= attribute.inject_options %>
24
- <%- else -%>
24
+ <%- elsif !attribute.virtual? -%>
25
25
  <%= '# ' unless attribute.has_index? -%>t.index <%= attribute.index_name %><%= attribute.inject_index_options %>
26
26
  <%- end -%>
27
27
  <%- end -%>
@@ -37,7 +37,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
37
37
  <%- if attribute.has_index? -%>
38
38
  remove_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
39
39
  <%- end -%>
40
+ <%- if !attribute.virtual? %>
40
41
  remove_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
42
+ <%- end -%>
41
43
  <%- end -%>
42
44
  <%- end -%>
43
45
  <%- end -%>
@@ -14,7 +14,7 @@ module ActiveRecord
14
14
  class_option :parent, type: :string, desc: "The parent class for the generated model"
15
15
  class_option :indexes, type: :boolean, default: true, desc: "Add indexes for references and belongs_to columns"
16
16
  class_option :primary_key_type, type: :string, desc: "The type for primary key"
17
- class_option :database, type: :string, aliases: %i(db), desc: "The database for your model's migration. By default, the current environment's primary database is used."
17
+ class_option :database, type: :string, aliases: %i(--db), desc: "The database for your model's migration. By default, the current environment's primary database is used."
18
18
 
19
19
  # creates the migration file for the model.
20
20
  def create_migration_file
@@ -1,7 +1,16 @@
1
1
  <% module_namespacing do -%>
2
2
  class <%= class_name %> < <%= parent_class_name.classify %>
3
3
  <% attributes.select(&:reference?).each do |attribute| -%>
4
- belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %>
4
+ belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
5
+ <% end -%>
6
+ <% attributes.select(&:rich_text?).each do |attribute| -%>
7
+ has_rich_text :<%= attribute.name %>
8
+ <% end -%>
9
+ <% attributes.select(&:attachment?).each do |attribute| -%>
10
+ has_one_attached :<%= attribute.name %>
11
+ <% end -%>
12
+ <% attributes.select(&:attachments?).each do |attribute| -%>
13
+ has_many_attached :<%= attribute.name %>
5
14
  <% end -%>
6
15
  <% attributes.select(&:token?).each do |attribute| -%>
7
16
  has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.beta1
4
+ version: 6.0.1.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-18 00:00:00.000000000 Z
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.0.beta1
19
+ version: 6.0.1.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 6.0.0.beta1
26
+ version: 6.0.1.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.0.beta1
33
+ version: 6.0.1.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 6.0.0.beta1
40
+ version: 6.0.1.rc1
41
41
  description: Databases on Rails. Build a persistent domain model by mapping database
42
42
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
43
43
  migrations, and testing come baked-in.
@@ -101,7 +101,6 @@ files:
101
101
  - lib/active_record/callbacks.rb
102
102
  - lib/active_record/coders/json.rb
103
103
  - lib/active_record/coders/yaml_column.rb
104
- - lib/active_record/collection_cache_key.rb
105
104
  - lib/active_record/connection_adapters/abstract/connection_pool.rb
106
105
  - lib/active_record/connection_adapters/abstract/database_limits.rb
107
106
  - lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -165,6 +164,7 @@ files:
165
164
  - lib/active_record/connection_adapters/postgresql_adapter.rb
166
165
  - lib/active_record/connection_adapters/schema_cache.rb
167
166
  - lib/active_record/connection_adapters/sql_type_metadata.rb
167
+ - lib/active_record/connection_adapters/sqlite3/database_statements.rb
168
168
  - lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb
169
169
  - lib/active_record/connection_adapters/sqlite3/quoting.rb
170
170
  - lib/active_record/connection_adapters/sqlite3/schema_creation.rb
@@ -195,6 +195,7 @@ files:
195
195
  - lib/active_record/fixtures.rb
196
196
  - lib/active_record/gem_version.rb
197
197
  - lib/active_record/inheritance.rb
198
+ - lib/active_record/insert_all.rb
198
199
  - lib/active_record/integration.rb
199
200
  - lib/active_record/internal_metadata.rb
200
201
  - lib/active_record/legacy_yaml_adapter.rb
@@ -202,6 +203,9 @@ files:
202
203
  - lib/active_record/locking/optimistic.rb
203
204
  - lib/active_record/locking/pessimistic.rb
204
205
  - lib/active_record/log_subscriber.rb
206
+ - lib/active_record/middleware/database_selector.rb
207
+ - lib/active_record/middleware/database_selector/resolver.rb
208
+ - lib/active_record/middleware/database_selector/resolver/session.rb
205
209
  - lib/active_record/migration.rb
206
210
  - lib/active_record/migration/command_recorder.rb
207
211
  - lib/active_record/migration/compatibility.rb
@@ -313,6 +317,7 @@ files:
313
317
  - lib/arel/nodes/bind_param.rb
314
318
  - lib/arel/nodes/case.rb
315
319
  - lib/arel/nodes/casted.rb
320
+ - lib/arel/nodes/comment.rb
316
321
  - lib/arel/nodes/count.rb
317
322
  - lib/arel/nodes/delete_statement.rb
318
323
  - lib/arel/nodes/descending.rb
@@ -346,7 +351,6 @@ files:
346
351
  - lib/arel/nodes/unary_operation.rb
347
352
  - lib/arel/nodes/unqualified_column.rb
348
353
  - lib/arel/nodes/update_statement.rb
349
- - lib/arel/nodes/values.rb
350
354
  - lib/arel/nodes/values_list.rb
351
355
  - lib/arel/nodes/window.rb
352
356
  - lib/arel/nodes/with.rb
@@ -381,12 +385,15 @@ files:
381
385
  - lib/rails/generators/active_record/model/model_generator.rb
382
386
  - lib/rails/generators/active_record/model/templates/model.rb.tt
383
387
  - lib/rails/generators/active_record/model/templates/module.rb.tt
384
- homepage: http://rubyonrails.org
388
+ homepage: https://rubyonrails.org
385
389
  licenses:
386
390
  - MIT
387
391
  metadata:
388
- source_code_uri: https://github.com/rails/rails/tree/v6.0.0.beta1/activerecord
389
- changelog_uri: https://github.com/rails/rails/blob/v6.0.0.beta1/activerecord/CHANGELOG.md
392
+ bug_tracker_uri: https://github.com/rails/rails/issues
393
+ changelog_uri: https://github.com/rails/rails/blob/v6.0.1.rc1/activerecord/CHANGELOG.md
394
+ documentation_uri: https://api.rubyonrails.org/v6.0.1.rc1/
395
+ mailing_list_uri: https://groups.google.com/forum/#!forum/rubyonrails-talk
396
+ source_code_uri: https://github.com/rails/rails/tree/v6.0.1.rc1/activerecord
390
397
  post_install_message:
391
398
  rdoc_options:
392
399
  - "--main"
@@ -404,7 +411,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
404
411
  - !ruby/object:Gem::Version
405
412
  version: 1.3.1
406
413
  requirements: []
407
- rubygems_version: 3.0.1
414
+ rubygems_version: 3.0.3
408
415
  signing_key:
409
416
  specification_version: 4
410
417
  summary: Object-relational mapper framework (part of Rails).
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecord
4
- module CollectionCacheKey
5
- def collection_cache_key(collection = all, timestamp_column = :updated_at) # :nodoc:
6
- query_signature = ActiveSupport::Digest.hexdigest(collection.to_sql)
7
- key = "#{collection.model_name.cache_key}/query-#{query_signature}"
8
-
9
- if collection.loaded? || collection.distinct_value
10
- size = collection.records.size
11
- if size > 0
12
- timestamp = collection.max_by(&timestamp_column)._read_attribute(timestamp_column)
13
- end
14
- else
15
- if collection.eager_loading?
16
- collection = collection.send(:apply_join_dependency)
17
- end
18
- column_type = type_for_attribute(timestamp_column)
19
- column = connection.visitor.compile(collection.arel_attribute(timestamp_column))
20
- select_values = "COUNT(*) AS #{connection.quote_column_name("size")}, MAX(%s) AS timestamp"
21
-
22
- if collection.has_limit_or_offset?
23
- query = collection.select("#{column} AS collection_cache_key_timestamp")
24
- subquery_alias = "subquery_for_cache_key"
25
- subquery_column = "#{subquery_alias}.collection_cache_key_timestamp"
26
- subquery = query.arel.as(subquery_alias)
27
- arel = Arel::SelectManager.new(subquery).project(select_values % subquery_column)
28
- else
29
- query = collection.unscope(:order)
30
- query.select_values = [select_values % column]
31
- arel = query.arel
32
- end
33
-
34
- result = connection.select_one(arel, nil)
35
-
36
- if result.blank?
37
- size = 0
38
- timestamp = nil
39
- else
40
- size = result["size"]
41
- timestamp = column_type.deserialize(result["timestamp"])
42
- end
43
-
44
- end
45
-
46
- if timestamp
47
- "#{key}-#{size}-#{timestamp.utc.to_s(cache_timestamp_format)}"
48
- else
49
- "#{key}-#{size}"
50
- end
51
- end
52
- end
53
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Arel # :nodoc: all
4
- module Nodes
5
- class Values < Arel::Nodes::Binary
6
- alias :expressions :left
7
- alias :expressions= :left=
8
- alias :columns :right
9
- alias :columns= :right=
10
-
11
- def initialize(exprs, columns = [])
12
- super
13
- end
14
- end
15
- end
16
- end