activerecord 6.0.0.beta3 → 6.0.0.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 (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +286 -6
  3. data/README.rdoc +3 -1
  4. data/lib/active_record.rb +0 -1
  5. data/lib/active_record/associations.rb +3 -2
  6. data/lib/active_record/associations/association.rb +1 -1
  7. data/lib/active_record/associations/builder/association.rb +14 -18
  8. data/lib/active_record/associations/builder/belongs_to.rb +5 -2
  9. data/lib/active_record/associations/builder/collection_association.rb +3 -13
  10. data/lib/active_record/associations/builder/has_many.rb +2 -0
  11. data/lib/active_record/associations/builder/has_one.rb +35 -1
  12. data/lib/active_record/associations/builder/singular_association.rb +2 -0
  13. data/lib/active_record/associations/collection_proxy.rb +1 -1
  14. data/lib/active_record/associations/has_many_through_association.rb +4 -11
  15. data/lib/active_record/associations/preloader.rb +11 -6
  16. data/lib/active_record/associations/preloader/association.rb +32 -30
  17. data/lib/active_record/associations/preloader/through_association.rb +48 -28
  18. data/lib/active_record/attribute_methods.rb +4 -3
  19. data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
  20. data/lib/active_record/attribute_methods/dirty.rb +42 -14
  21. data/lib/active_record/attribute_methods/primary_key.rb +7 -15
  22. data/lib/active_record/attribute_methods/query.rb +2 -3
  23. data/lib/active_record/attribute_methods/read.rb +3 -9
  24. data/lib/active_record/attribute_methods/write.rb +6 -12
  25. data/lib/active_record/attributes.rb +13 -0
  26. data/lib/active_record/autosave_association.rb +13 -3
  27. data/lib/active_record/base.rb +0 -1
  28. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -0
  29. data/lib/active_record/connection_adapters/abstract/database_limits.rb +8 -4
  30. data/lib/active_record/connection_adapters/abstract/database_statements.rb +84 -61
  31. data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -1
  32. data/lib/active_record/connection_adapters/abstract/quoting.rb +10 -6
  33. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +4 -7
  34. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +70 -14
  35. data/lib/active_record/connection_adapters/abstract_adapter.rb +56 -11
  36. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +65 -69
  37. data/lib/active_record/connection_adapters/column.rb +17 -13
  38. data/lib/active_record/connection_adapters/mysql/database_statements.rb +45 -7
  39. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +4 -4
  40. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +9 -6
  41. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
  42. data/lib/active_record/connection_adapters/mysql2_adapter.rb +6 -2
  43. data/lib/active_record/connection_adapters/postgresql/column.rb +17 -30
  44. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +5 -1
  45. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +34 -38
  46. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +23 -27
  47. data/lib/active_record/connection_adapters/postgresql_adapter.rb +57 -27
  48. data/lib/active_record/connection_adapters/schema_cache.rb +32 -14
  49. data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
  50. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +118 -0
  51. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +2 -2
  52. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +50 -112
  53. data/lib/active_record/connection_handling.rb +17 -10
  54. data/lib/active_record/core.rb +15 -20
  55. data/lib/active_record/database_configurations.rb +14 -14
  56. data/lib/active_record/database_configurations/hash_config.rb +11 -11
  57. data/lib/active_record/database_configurations/url_config.rb +12 -12
  58. data/lib/active_record/dynamic_matchers.rb +1 -1
  59. data/lib/active_record/enum.rb +6 -0
  60. data/lib/active_record/errors.rb +1 -1
  61. data/lib/active_record/gem_version.rb +1 -1
  62. data/lib/active_record/insert_all.rb +180 -0
  63. data/lib/active_record/integration.rb +13 -1
  64. data/lib/active_record/internal_metadata.rb +5 -1
  65. data/lib/active_record/locking/optimistic.rb +3 -4
  66. data/lib/active_record/log_subscriber.rb +1 -1
  67. data/lib/active_record/migration.rb +25 -18
  68. data/lib/active_record/migration/command_recorder.rb +28 -14
  69. data/lib/active_record/migration/compatibility.rb +10 -0
  70. data/lib/active_record/persistence.rb +206 -13
  71. data/lib/active_record/querying.rb +17 -12
  72. data/lib/active_record/railties/databases.rake +68 -6
  73. data/lib/active_record/reflection.rb +2 -2
  74. data/lib/active_record/relation.rb +98 -20
  75. data/lib/active_record/relation/calculations.rb +39 -39
  76. data/lib/active_record/relation/delegation.rb +22 -30
  77. data/lib/active_record/relation/finder_methods.rb +3 -9
  78. data/lib/active_record/relation/merger.rb +7 -16
  79. data/lib/active_record/relation/query_methods.rb +153 -38
  80. data/lib/active_record/relation/where_clause.rb +9 -5
  81. data/lib/active_record/sanitization.rb +3 -2
  82. data/lib/active_record/schema_dumper.rb +5 -0
  83. data/lib/active_record/schema_migration.rb +1 -1
  84. data/lib/active_record/scoping/default.rb +6 -7
  85. data/lib/active_record/scoping/named.rb +1 -1
  86. data/lib/active_record/statement_cache.rb +2 -2
  87. data/lib/active_record/store.rb +48 -0
  88. data/lib/active_record/table_metadata.rb +3 -3
  89. data/lib/active_record/tasks/database_tasks.rb +36 -1
  90. data/lib/active_record/touch_later.rb +2 -2
  91. data/lib/active_record/transactions.rb +52 -41
  92. data/lib/active_record/validations/uniqueness.rb +3 -5
  93. data/lib/arel/insert_manager.rb +3 -3
  94. data/lib/arel/nodes.rb +2 -1
  95. data/lib/arel/nodes/comment.rb +29 -0
  96. data/lib/arel/nodes/select_core.rb +16 -12
  97. data/lib/arel/nodes/unary.rb +1 -0
  98. data/lib/arel/nodes/values_list.rb +2 -17
  99. data/lib/arel/select_manager.rb +10 -10
  100. data/lib/arel/visitors/depth_first.rb +6 -1
  101. data/lib/arel/visitors/dot.rb +7 -2
  102. data/lib/arel/visitors/ibm_db.rb +13 -0
  103. data/lib/arel/visitors/informix.rb +6 -0
  104. data/lib/arel/visitors/mssql.rb +15 -1
  105. data/lib/arel/visitors/oracle12.rb +4 -5
  106. data/lib/arel/visitors/postgresql.rb +4 -10
  107. data/lib/arel/visitors/to_sql.rb +87 -108
  108. data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
  109. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
  110. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
  111. data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
  112. data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
  113. metadata +12 -11
  114. data/lib/active_record/collection_cache_key.rb +0 -53
  115. data/lib/arel/nodes/values.rb +0 -16
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
9
9
 
10
10
  class_option :primary_key_type, type: :string, desc: "The type for primary key"
11
- class_option :database, type: :string, aliases: %i(db), desc: "The database for your migration. By default, the current environment's primary database is used."
11
+ class_option :database, type: :string, aliases: %i(--db), desc: "The database for your migration. By default, the current environment's primary database is used."
12
12
 
13
13
  def create_migration_file
14
14
  set_local_assigns!
@@ -6,7 +6,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
6
6
  t.string :password_digest<%= attribute.inject_options %>
7
7
  <% elsif attribute.token? -%>
8
8
  t.string :<%= attribute.name %><%= attribute.inject_options %>
9
- <% else -%>
9
+ <% elsif !attribute.virtual? -%>
10
10
  t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
11
11
  <% end -%>
12
12
  <% end -%>
@@ -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.beta3
4
+ version: 6.0.0.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-03-13 00:00:00.000000000 Z
11
+ date: 2019-04-24 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.beta3
19
+ version: 6.0.0.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.beta3
26
+ version: 6.0.0.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.beta3
33
+ version: 6.0.0.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.beta3
40
+ version: 6.0.0.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
@@ -316,6 +317,7 @@ files:
316
317
  - lib/arel/nodes/bind_param.rb
317
318
  - lib/arel/nodes/case.rb
318
319
  - lib/arel/nodes/casted.rb
320
+ - lib/arel/nodes/comment.rb
319
321
  - lib/arel/nodes/count.rb
320
322
  - lib/arel/nodes/delete_statement.rb
321
323
  - lib/arel/nodes/descending.rb
@@ -349,7 +351,6 @@ files:
349
351
  - lib/arel/nodes/unary_operation.rb
350
352
  - lib/arel/nodes/unqualified_column.rb
351
353
  - lib/arel/nodes/update_statement.rb
352
- - lib/arel/nodes/values.rb
353
354
  - lib/arel/nodes/values_list.rb
354
355
  - lib/arel/nodes/window.rb
355
356
  - lib/arel/nodes/with.rb
@@ -384,12 +385,12 @@ files:
384
385
  - lib/rails/generators/active_record/model/model_generator.rb
385
386
  - lib/rails/generators/active_record/model/templates/model.rb.tt
386
387
  - lib/rails/generators/active_record/model/templates/module.rb.tt
387
- homepage: http://rubyonrails.org
388
+ homepage: https://rubyonrails.org
388
389
  licenses:
389
390
  - MIT
390
391
  metadata:
391
- source_code_uri: https://github.com/rails/rails/tree/v6.0.0.beta3/activerecord
392
- changelog_uri: https://github.com/rails/rails/blob/v6.0.0.beta3/activerecord/CHANGELOG.md
392
+ source_code_uri: https://github.com/rails/rails/tree/v6.0.0.rc1/activerecord
393
+ changelog_uri: https://github.com/rails/rails/blob/v6.0.0.rc1/activerecord/CHANGELOG.md
393
394
  post_install_message:
394
395
  rdoc_options:
395
396
  - "--main"
@@ -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