activerecord 4.1.15 → 4.2.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +634 -2176
- data/README.rdoc +15 -10
- data/lib/active_record/aggregations.rb +12 -8
- data/lib/active_record/associations/association.rb +1 -1
- data/lib/active_record/associations/association_scope.rb +53 -21
- data/lib/active_record/associations/belongs_to_association.rb +15 -5
- data/lib/active_record/associations/builder/association.rb +16 -5
- data/lib/active_record/associations/builder/belongs_to.rb +7 -29
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -11
- data/lib/active_record/associations/builder/has_one.rb +2 -2
- data/lib/active_record/associations/builder/singular_association.rb +8 -1
- data/lib/active_record/associations/collection_association.rb +32 -44
- data/lib/active_record/associations/collection_proxy.rb +1 -10
- data/lib/active_record/associations/has_many_association.rb +60 -14
- data/lib/active_record/associations/has_many_through_association.rb +34 -23
- data/lib/active_record/associations/has_one_association.rb +0 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +18 -14
- data/lib/active_record/associations/join_dependency.rb +7 -9
- data/lib/active_record/associations/preloader/association.rb +9 -5
- data/lib/active_record/associations/preloader/through_association.rb +3 -3
- data/lib/active_record/associations/preloader.rb +2 -2
- data/lib/active_record/associations/singular_association.rb +16 -1
- data/lib/active_record/associations/through_association.rb +6 -22
- data/lib/active_record/associations.rb +58 -33
- data/lib/active_record/attribute.rb +131 -0
- data/lib/active_record/attribute_assignment.rb +19 -11
- data/lib/active_record/attribute_decorators.rb +66 -0
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -2
- data/lib/active_record/attribute_methods/dirty.rb +85 -42
- data/lib/active_record/attribute_methods/primary_key.rb +6 -8
- data/lib/active_record/attribute_methods/read.rb +14 -57
- data/lib/active_record/attribute_methods/serialization.rb +12 -146
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +32 -40
- data/lib/active_record/attribute_methods/write.rb +8 -23
- data/lib/active_record/attribute_methods.rb +53 -90
- data/lib/active_record/attribute_set/builder.rb +32 -0
- data/lib/active_record/attribute_set.rb +77 -0
- data/lib/active_record/attributes.rb +122 -0
- data/lib/active_record/autosave_association.rb +11 -21
- data/lib/active_record/base.rb +9 -19
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +69 -45
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +22 -42
- data/lib/active_record/connection_adapters/abstract/quoting.rb +59 -60
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +37 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +102 -21
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +9 -33
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +178 -55
- data/lib/active_record/connection_adapters/abstract/transaction.rb +120 -115
- data/lib/active_record/connection_adapters/abstract_adapter.rb +143 -57
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +156 -107
- data/lib/active_record/connection_adapters/column.rb +13 -244
- data/lib/active_record/connection_adapters/connection_specification.rb +6 -20
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -15
- data/lib/active_record/connection_adapters/mysql_adapter.rb +55 -143
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +15 -27
- data/lib/active_record/connection_adapters/postgresql/column.rb +20 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +39 -20
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +96 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +52 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +14 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +46 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +27 -0
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +17 -0
- data/lib/active_record/connection_adapters/postgresql/oid/float.rb +21 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +59 -0
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +35 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +76 -0
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/time.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +85 -0
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +26 -0
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +26 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +28 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +29 -388
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +42 -122
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +154 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +86 -34
- data/lib/active_record/connection_adapters/postgresql/utils.rb +66 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +188 -452
- data/lib/active_record/connection_adapters/schema_cache.rb +14 -28
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +54 -47
- data/lib/active_record/connection_handling.rb +1 -1
- data/lib/active_record/core.rb +119 -22
- data/lib/active_record/counter_cache.rb +60 -6
- data/lib/active_record/enum.rb +9 -10
- data/lib/active_record/errors.rb +27 -26
- data/lib/active_record/explain.rb +1 -1
- data/lib/active_record/fixtures.rb +52 -45
- data/lib/active_record/gem_version.rb +3 -3
- data/lib/active_record/inheritance.rb +33 -8
- data/lib/active_record/integration.rb +4 -4
- data/lib/active_record/locking/optimistic.rb +34 -16
- data/lib/active_record/migration/command_recorder.rb +19 -2
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration.rb +22 -32
- data/lib/active_record/model_schema.rb +39 -48
- data/lib/active_record/nested_attributes.rb +8 -18
- data/lib/active_record/persistence.rb +39 -22
- data/lib/active_record/query_cache.rb +3 -3
- data/lib/active_record/querying.rb +1 -8
- data/lib/active_record/railtie.rb +17 -10
- data/lib/active_record/railties/databases.rake +47 -42
- data/lib/active_record/readonly_attributes.rb +0 -1
- data/lib/active_record/reflection.rb +225 -92
- data/lib/active_record/relation/batches.rb +0 -2
- data/lib/active_record/relation/calculations.rb +28 -32
- data/lib/active_record/relation/delegation.rb +1 -1
- data/lib/active_record/relation/finder_methods.rb +42 -20
- data/lib/active_record/relation/merger.rb +0 -1
- data/lib/active_record/relation/predicate_builder/array_handler.rb +16 -11
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +0 -4
- data/lib/active_record/relation/predicate_builder.rb +1 -22
- data/lib/active_record/relation/query_methods.rb +98 -62
- data/lib/active_record/relation/spawn_methods.rb +6 -7
- data/lib/active_record/relation.rb +35 -11
- data/lib/active_record/result.rb +16 -9
- data/lib/active_record/sanitization.rb +8 -1
- data/lib/active_record/schema.rb +0 -1
- data/lib/active_record/schema_dumper.rb +51 -9
- data/lib/active_record/schema_migration.rb +4 -0
- data/lib/active_record/scoping/default.rb +5 -4
- data/lib/active_record/serializers/xml_serializer.rb +3 -7
- data/lib/active_record/statement_cache.rb +79 -5
- data/lib/active_record/store.rb +5 -5
- data/lib/active_record/tasks/database_tasks.rb +37 -5
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/postgresql_database_tasks.rb +2 -2
- data/lib/active_record/timestamp.rb +9 -7
- data/lib/active_record/transactions.rb +35 -21
- data/lib/active_record/type/binary.rb +40 -0
- data/lib/active_record/type/boolean.rb +19 -0
- data/lib/active_record/type/date.rb +46 -0
- data/lib/active_record/type/date_time.rb +43 -0
- data/lib/active_record/type/decimal.rb +40 -0
- data/lib/active_record/type/decimal_without_scale.rb +11 -0
- data/lib/active_record/type/float.rb +19 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +19 -0
- data/lib/active_record/type/integer.rb +23 -0
- data/lib/active_record/type/mutable.rb +16 -0
- data/lib/active_record/type/numeric.rb +36 -0
- data/lib/active_record/type/serialized.rb +51 -0
- data/lib/active_record/type/string.rb +36 -0
- data/lib/active_record/type/text.rb +11 -0
- data/lib/active_record/type/time.rb +26 -0
- data/lib/active_record/type/time_value.rb +38 -0
- data/lib/active_record/type/type_map.rb +48 -0
- data/lib/active_record/type/value.rb +101 -0
- data/lib/active_record/type.rb +20 -0
- data/lib/active_record/validations/uniqueness.rb +9 -23
- data/lib/active_record/validations.rb +21 -16
- data/lib/active_record.rb +2 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +8 -4
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb +1 -1
- metadata +71 -14
- data/lib/active_record/connection_adapters/postgresql/cast.rb +0 -168
@@ -28,12 +28,20 @@ db_namespace = namespace :db do
|
|
28
28
|
ActiveRecord::Tasks::DatabaseTasks.drop_current
|
29
29
|
end
|
30
30
|
|
31
|
+
namespace :purge do
|
32
|
+
task :all => :load_config do
|
33
|
+
ActiveRecord::Tasks::DatabaseTasks.purge_all
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# desc "Empty the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV it defaults to purging the development and test databases."
|
38
|
+
task :purge => [:load_config] do
|
39
|
+
ActiveRecord::Tasks::DatabaseTasks.purge_current
|
40
|
+
end
|
41
|
+
|
31
42
|
desc "Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
|
32
43
|
task :migrate => [:environment, :load_config] do
|
33
|
-
ActiveRecord::
|
34
|
-
ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration|
|
35
|
-
ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
|
36
|
-
end
|
44
|
+
ActiveRecord::Tasks::DatabaseTasks.migrate
|
37
45
|
db_namespace['_dump'].invoke if ActiveRecord::Base.dump_schema_after_migration
|
38
46
|
end
|
39
47
|
|
@@ -82,23 +90,21 @@ db_namespace = namespace :db do
|
|
82
90
|
|
83
91
|
desc 'Display status of migrations'
|
84
92
|
task :status => [:environment, :load_config] do
|
85
|
-
unless ActiveRecord::
|
86
|
-
|
87
|
-
next # means "return" for rake task
|
93
|
+
unless ActiveRecord::SchemaMigration.table_exists?
|
94
|
+
abort 'Schema migrations table does not exist yet.'
|
88
95
|
end
|
89
|
-
db_list = ActiveRecord::
|
90
|
-
|
91
|
-
file_list =
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
db_list = ActiveRecord::SchemaMigration.normalized_versions
|
97
|
+
|
98
|
+
file_list =
|
99
|
+
ActiveRecord::Migrator.migrations_paths.flat_map do |path|
|
100
|
+
# match "20091231235959_some_name.rb" and "001_some_name.rb" pattern
|
101
|
+
Dir.foreach(path).grep(/^(\d{3,})_(.+)\.rb$/) do
|
102
|
+
version = ActiveRecord::SchemaMigration.normalize_migration_number($1)
|
103
|
+
status = db_list.delete(version) ? 'up' : 'down'
|
104
|
+
[status, version, $2.humanize]
|
105
|
+
end
|
99
106
|
end
|
100
|
-
|
101
|
-
end
|
107
|
+
|
102
108
|
db_list.map! do |version|
|
103
109
|
['up', version, '********** NO FILE **********']
|
104
110
|
end
|
@@ -106,8 +112,8 @@ db_namespace = namespace :db do
|
|
106
112
|
puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n"
|
107
113
|
puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
|
108
114
|
puts "-" * 50
|
109
|
-
(db_list + file_list).sort_by {|
|
110
|
-
puts "#{
|
115
|
+
(db_list + file_list).sort_by { |_, version, _| version }.each do |status, version, name|
|
116
|
+
puts "#{status.center(8)} #{version.ljust(14)} #{name}"
|
111
117
|
end
|
112
118
|
puts
|
113
119
|
end
|
@@ -179,17 +185,21 @@ db_namespace = namespace :db do
|
|
179
185
|
task :load => [:environment, :load_config] do
|
180
186
|
require 'active_record/fixtures'
|
181
187
|
|
182
|
-
base_dir =
|
183
|
-
File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten
|
184
|
-
else
|
185
|
-
ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
186
|
-
end
|
188
|
+
base_dir = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
187
189
|
|
188
|
-
fixtures_dir =
|
190
|
+
fixtures_dir = if ENV['FIXTURES_DIR']
|
191
|
+
File.join base_dir, ENV['FIXTURES_DIR']
|
192
|
+
else
|
193
|
+
base_dir
|
194
|
+
end
|
189
195
|
|
190
|
-
|
191
|
-
|
192
|
-
|
196
|
+
fixture_files = if ENV['FIXTURES']
|
197
|
+
ENV['FIXTURES'].split(',')
|
198
|
+
else
|
199
|
+
Pathname.glob("#{fixtures_dir}/**/*.yml").map {|f| f.basename.sub_ext('').to_s }
|
200
|
+
end
|
201
|
+
|
202
|
+
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
|
193
203
|
end
|
194
204
|
|
195
205
|
# desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
|
@@ -201,12 +211,7 @@ db_namespace = namespace :db do
|
|
201
211
|
|
202
212
|
puts %Q(The fixture ID for "#{label}" is #{ActiveRecord::FixtureSet.identify(label)}.) if label
|
203
213
|
|
204
|
-
base_dir =
|
205
|
-
File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten
|
206
|
-
else
|
207
|
-
ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
208
|
-
end
|
209
|
-
|
214
|
+
base_dir = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
210
215
|
|
211
216
|
Dir["#{base_dir}/**/*.yml"].each do |file|
|
212
217
|
if data = YAML::load(ERB.new(IO.read(file)).result)
|
@@ -279,7 +284,7 @@ db_namespace = namespace :db do
|
|
279
284
|
db_namespace['structure:dump'].reenable
|
280
285
|
end
|
281
286
|
|
282
|
-
|
287
|
+
desc "Recreate the databases from the structure.sql file"
|
283
288
|
task :load => [:environment, :load_config] do
|
284
289
|
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:sql, ENV['DB_STRUCTURE'])
|
285
290
|
end
|
@@ -299,7 +304,7 @@ db_namespace = namespace :db do
|
|
299
304
|
end
|
300
305
|
|
301
306
|
# desc "Recreate the test database from the current schema"
|
302
|
-
task :load => %w(db:test:purge) do
|
307
|
+
task :load => %w(db:test:deprecated db:test:purge) do
|
303
308
|
case ActiveRecord::Base.schema_format
|
304
309
|
when :ruby
|
305
310
|
db_namespace["test:load_schema"].invoke
|
@@ -309,7 +314,7 @@ db_namespace = namespace :db do
|
|
309
314
|
end
|
310
315
|
|
311
316
|
# desc "Recreate the test database from an existent schema.rb file"
|
312
|
-
task :load_schema => %w(db:test:purge) do
|
317
|
+
task :load_schema => %w(db:test:deprecated db:test:purge) do
|
313
318
|
begin
|
314
319
|
should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
|
315
320
|
ActiveRecord::Schema.verbose = false
|
@@ -322,7 +327,7 @@ db_namespace = namespace :db do
|
|
322
327
|
end
|
323
328
|
|
324
329
|
# desc "Recreate the test database from an existent structure.sql file"
|
325
|
-
task :load_structure => %w(db:test:purge) do
|
330
|
+
task :load_structure => %w(db:test:deprecated db:test:purge) do
|
326
331
|
ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
|
327
332
|
end
|
328
333
|
|
@@ -343,12 +348,12 @@ db_namespace = namespace :db do
|
|
343
348
|
task :clone_structure => %w(db:test:deprecated db:structure:dump db:test:load_structure)
|
344
349
|
|
345
350
|
# desc "Empty the test database"
|
346
|
-
task :purge => %w(environment load_config) do
|
351
|
+
task :purge => %w(db:test:deprecated environment load_config) do
|
347
352
|
ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations['test']
|
348
353
|
end
|
349
354
|
|
350
355
|
# desc 'Check for pending migrations and load the test schema'
|
351
|
-
task :prepare => %w(environment load_config) do
|
356
|
+
task :prepare => %w(db:test:deprecated environment load_config) do
|
352
357
|
unless ActiveRecord::Base.configurations.blank?
|
353
358
|
db_namespace['test:load'].invoke
|
354
359
|
end
|