activerecord 3.2.9.rc1 → 3.2.9.rc2
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.
- data/CHANGELOG.md +18 -1
- data/lib/active_record/associations/collection_association.rb +3 -1
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +1 -1
- data/lib/active_record/connection_adapters/column.rb +13 -2
- data/lib/active_record/persistence.rb +1 -1
- data/lib/active_record/railties/databases.rake +54 -34
- data/lib/active_record/version.rb +1 -1
- metadata +6 -6
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
## Rails 3.2.9 (unreleased)
|
2
2
|
|
3
|
+
* Fix issue with collection associations calling first(n)/last(n) and attempting
|
4
|
+
to set the inverse association when `:inverse_of` was used. Fixes #8087.
|
5
|
+
|
6
|
+
*Carlos Antonio da Silva*
|
7
|
+
|
8
|
+
* Fix bug when Column is trying to type cast boolean values to integer.
|
9
|
+
Fixes #8067.
|
10
|
+
|
11
|
+
*Rafael Mendonça França*
|
12
|
+
|
13
|
+
* Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
|
14
|
+
Fixes #8032.
|
15
|
+
|
16
|
+
*Grace Liu + Rafael Mendonça França*
|
17
|
+
|
18
|
+
* Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
|
19
|
+
|
3
20
|
* Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
|
4
21
|
|
5
22
|
*Henrik Nyh*
|
@@ -11,7 +28,7 @@
|
|
11
28
|
* Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
|
12
29
|
and the dup'ed object shared the same errors.
|
13
30
|
|
14
|
-
*
|
31
|
+
*Christian Seiler*
|
15
32
|
|
16
33
|
* Synchronize around deleting from the reserved connections hash.
|
17
34
|
Fixes #7955
|
@@ -571,7 +571,9 @@ module ActiveRecord
|
|
571
571
|
args.shift if args.first.is_a?(Hash) && args.first.empty?
|
572
572
|
|
573
573
|
collection = fetch_first_or_last_using_find?(args) ? scoped : load_target
|
574
|
-
collection.send(type, *args).tap
|
574
|
+
collection.send(type, *args).tap do |record|
|
575
|
+
set_inverse_instance record if record.is_a? ActiveRecord::Base
|
576
|
+
end
|
575
577
|
end
|
576
578
|
end
|
577
579
|
end
|
@@ -67,7 +67,7 @@ module ActiveRecord
|
|
67
67
|
:port => config.port,
|
68
68
|
:database => config.path.sub(%r{^/},""),
|
69
69
|
:host => config.host }
|
70
|
-
spec.reject!{ |_,value|
|
70
|
+
spec.reject!{ |_,value| value.blank? }
|
71
71
|
spec.map { |key,value| spec[key] = URI.unescape(value) if value.is_a?(String) }
|
72
72
|
if config.query
|
73
73
|
options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys
|
@@ -75,7 +75,7 @@ module ActiveRecord
|
|
75
75
|
|
76
76
|
case type
|
77
77
|
when :string, :text then value
|
78
|
-
when :integer then value
|
78
|
+
when :integer then klass.value_to_integer(value)
|
79
79
|
when :float then value.to_f
|
80
80
|
when :decimal then klass.value_to_decimal(value)
|
81
81
|
when :datetime, :timestamp then klass.string_to_time(value)
|
@@ -92,7 +92,7 @@ module ActiveRecord
|
|
92
92
|
|
93
93
|
case type
|
94
94
|
when :string, :text then var_name
|
95
|
-
when :integer then "(#{var_name}
|
95
|
+
when :integer then "#{klass}.value_to_integer(#{var_name})"
|
96
96
|
when :float then "#{var_name}.to_f"
|
97
97
|
when :decimal then "#{klass}.value_to_decimal(#{var_name})"
|
98
98
|
when :datetime, :timestamp then "#{klass}.string_to_time(#{var_name})"
|
@@ -168,6 +168,17 @@ module ActiveRecord
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
+
# Used to convert values to integer.
|
172
|
+
# handle the case when an integer column is used to store boolean values
|
173
|
+
def value_to_integer(value)
|
174
|
+
case value
|
175
|
+
when TrueClass, FalseClass
|
176
|
+
value ? 1 : 0
|
177
|
+
else
|
178
|
+
value.to_i
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
171
182
|
# convert something to a BigDecimal
|
172
183
|
def value_to_decimal(value)
|
173
184
|
# Using .class is faster than .is_a? and
|
@@ -194,7 +194,7 @@ module ActiveRecord
|
|
194
194
|
raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name)
|
195
195
|
raise ActiveRecordError, "can not update on a new record object" unless persisted?
|
196
196
|
|
197
|
-
updated_count = self.class.update_all({ name => value }, self.class.primary_key => id)
|
197
|
+
updated_count = self.class.update_all({ name => value }, self.class.primary_key => id)
|
198
198
|
|
199
199
|
raw_write_attribute(name, value)
|
200
200
|
|
@@ -2,6 +2,25 @@ require 'active_support/core_ext/object/inclusion'
|
|
2
2
|
require 'active_record'
|
3
3
|
|
4
4
|
db_namespace = namespace :db do
|
5
|
+
def database_url_config
|
6
|
+
@database_url_config ||=
|
7
|
+
ActiveRecord::Base::ConnectionSpecification::Resolver.new(ENV["DATABASE_URL"], {}).spec.config.stringify_keys
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_config(options = {})
|
11
|
+
options = { :env => Rails.env }.merge! options
|
12
|
+
|
13
|
+
if options[:config]
|
14
|
+
@current_config = options[:config]
|
15
|
+
else
|
16
|
+
@current_config ||= if ENV['DATABASE_URL']
|
17
|
+
database_url_config
|
18
|
+
else
|
19
|
+
ActiveRecord::Base.configurations[options[:env]]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
5
24
|
task :load_config do
|
6
25
|
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
7
26
|
ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
|
@@ -35,10 +54,14 @@ db_namespace = namespace :db do
|
|
35
54
|
end
|
36
55
|
end
|
37
56
|
|
38
|
-
desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
|
57
|
+
desc 'Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
|
39
58
|
task :create => [:load_config, :rails_env] do
|
40
|
-
|
41
|
-
|
59
|
+
if ENV['DATABASE_URL']
|
60
|
+
create_database(database_url_config)
|
61
|
+
else
|
62
|
+
configs_for_environment.each { |config| create_database(config) }
|
63
|
+
ActiveRecord::Base.establish_connection(configs_for_environment.first)
|
64
|
+
end
|
42
65
|
end
|
43
66
|
|
44
67
|
def mysql_creation_options(config)
|
@@ -133,9 +156,13 @@ db_namespace = namespace :db do
|
|
133
156
|
end
|
134
157
|
end
|
135
158
|
|
136
|
-
desc 'Drops the database
|
159
|
+
desc 'Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)'
|
137
160
|
task :drop => [:load_config, :rails_env] do
|
138
|
-
|
161
|
+
if ENV['DATABASE_URL']
|
162
|
+
drop_database_and_rescue(database_url_config)
|
163
|
+
else
|
164
|
+
configs_for_environment.each { |config| drop_database_and_rescue(config) }
|
165
|
+
end
|
139
166
|
end
|
140
167
|
|
141
168
|
def local_database?(config, &block)
|
@@ -146,7 +173,6 @@ db_namespace = namespace :db do
|
|
146
173
|
end
|
147
174
|
end
|
148
175
|
|
149
|
-
|
150
176
|
desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
|
151
177
|
task :migrate => [:environment, :load_config] do
|
152
178
|
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
@@ -201,8 +227,6 @@ db_namespace = namespace :db do
|
|
201
227
|
|
202
228
|
desc 'Display status of migrations'
|
203
229
|
task :status => [:environment, :load_config] do
|
204
|
-
config = ActiveRecord::Base.configurations[Rails.env]
|
205
|
-
ActiveRecord::Base.establish_connection(config)
|
206
230
|
unless ActiveRecord::Base.connection.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
|
207
231
|
puts 'Schema migrations table does not exist yet.'
|
208
232
|
next # means "return" for rake task
|
@@ -222,7 +246,7 @@ db_namespace = namespace :db do
|
|
222
246
|
['up', version, '********** NO FILE **********']
|
223
247
|
end
|
224
248
|
# output
|
225
|
-
puts "\ndatabase: #{
|
249
|
+
puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n"
|
226
250
|
puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
|
227
251
|
puts "-" * 50
|
228
252
|
(db_list + file_list).sort_by {|migration| migration[1]}.each do |migration|
|
@@ -314,7 +338,6 @@ db_namespace = namespace :db do
|
|
314
338
|
task :load => [:environment, :load_config] do
|
315
339
|
require 'active_record/fixtures'
|
316
340
|
|
317
|
-
ActiveRecord::Base.establish_connection(Rails.env)
|
318
341
|
base_dir = File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten
|
319
342
|
fixtures_dir = File.join [base_dir, ENV['FIXTURES_DIR']].compact
|
320
343
|
|
@@ -353,7 +376,6 @@ db_namespace = namespace :db do
|
|
353
376
|
require 'active_record/schema_dumper'
|
354
377
|
filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
|
355
378
|
File.open(filename, "w:utf-8") do |file|
|
356
|
-
ActiveRecord::Base.establish_connection(Rails.env)
|
357
379
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
358
380
|
end
|
359
381
|
db_namespace['schema:dump'].reenable
|
@@ -377,25 +399,25 @@ db_namespace = namespace :db do
|
|
377
399
|
namespace :structure do
|
378
400
|
desc 'Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql'
|
379
401
|
task :dump => [:environment, :load_config] do
|
380
|
-
|
402
|
+
config = current_config
|
381
403
|
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
|
382
|
-
case
|
404
|
+
case config['adapter']
|
383
405
|
when /mysql/, 'oci', 'oracle'
|
384
|
-
ActiveRecord::Base.establish_connection(
|
406
|
+
ActiveRecord::Base.establish_connection(config)
|
385
407
|
File.open(filename, "w:utf-8") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
386
408
|
when /postgresql/
|
387
|
-
set_psql_env(
|
388
|
-
search_path =
|
409
|
+
set_psql_env(config)
|
410
|
+
search_path = config['schema_search_path']
|
389
411
|
unless search_path.blank?
|
390
412
|
search_path = search_path.split(",").map{|search_path_part| "--schema=#{Shellwords.escape(search_path_part.strip)}" }.join(" ")
|
391
413
|
end
|
392
|
-
`pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(
|
414
|
+
`pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(config['database'])}`
|
393
415
|
raise 'Error dumping database' if $?.exitstatus == 1
|
394
416
|
when /sqlite/
|
395
|
-
dbfile =
|
417
|
+
dbfile = config['database']
|
396
418
|
`sqlite3 #{dbfile} .schema > #{filename}`
|
397
419
|
when 'sqlserver'
|
398
|
-
`smoscript -s #{
|
420
|
+
`smoscript -s #{config['host']} -d #{config['database']} -u #{config['username']} -p #{config['password']} -f #{filename} -A -U`
|
399
421
|
when "firebird"
|
400
422
|
set_firebird_env(abcs[Rails.env])
|
401
423
|
db_string = firebird_db_string(abcs[Rails.env])
|
@@ -412,36 +434,34 @@ db_namespace = namespace :db do
|
|
412
434
|
|
413
435
|
# desc "Recreate the databases from the structure.sql file"
|
414
436
|
task :load => [:environment, :load_config] do
|
415
|
-
|
416
|
-
|
417
|
-
abcs = ActiveRecord::Base.configurations
|
437
|
+
config = current_config
|
418
438
|
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
|
419
|
-
case
|
439
|
+
case config['adapter']
|
420
440
|
when /mysql/
|
421
|
-
ActiveRecord::Base.establish_connection(
|
441
|
+
ActiveRecord::Base.establish_connection(config)
|
422
442
|
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
|
423
443
|
IO.read(filename).split("\n\n").each do |table|
|
424
444
|
ActiveRecord::Base.connection.execute(table)
|
425
445
|
end
|
426
446
|
when /postgresql/
|
427
|
-
set_psql_env(
|
428
|
-
`psql -f "#{filename}" #{
|
447
|
+
set_psql_env(config)
|
448
|
+
`psql -f "#{filename}" #{config['database']}`
|
429
449
|
when /sqlite/
|
430
|
-
dbfile =
|
450
|
+
dbfile = config['database']
|
431
451
|
`sqlite3 #{dbfile} < "#{filename}"`
|
432
452
|
when 'sqlserver'
|
433
|
-
`sqlcmd -S #{
|
453
|
+
`sqlcmd -S #{config['host']} -d #{config['database']} -U #{config['username']} -P #{config['password']} -i #{filename}`
|
434
454
|
when 'oci', 'oracle'
|
435
|
-
ActiveRecord::Base.establish_connection(
|
455
|
+
ActiveRecord::Base.establish_connection(config)
|
436
456
|
IO.read(filename).split(";\n\n").each do |ddl|
|
437
457
|
ActiveRecord::Base.connection.execute(ddl)
|
438
458
|
end
|
439
459
|
when 'firebird'
|
440
|
-
set_firebird_env(
|
441
|
-
db_string = firebird_db_string(
|
460
|
+
set_firebird_env(config)
|
461
|
+
db_string = firebird_db_string(config)
|
442
462
|
sh "isql -i #{filename} #{db_string}"
|
443
463
|
else
|
444
|
-
raise "Task not supported by '#{
|
464
|
+
raise "Task not supported by '#{config['adapter']}'"
|
445
465
|
end
|
446
466
|
end
|
447
467
|
|
@@ -465,10 +485,10 @@ db_namespace = namespace :db do
|
|
465
485
|
# desc "Recreate the test database from an existent structure.sql file"
|
466
486
|
task :load_structure => 'db:test:purge' do
|
467
487
|
begin
|
468
|
-
|
488
|
+
current_config(:config => ActiveRecord::Base.configurations['test'])
|
469
489
|
db_namespace["structure:load"].invoke
|
470
490
|
ensure
|
471
|
-
|
491
|
+
current_config(:config => nil)
|
472
492
|
end
|
473
493
|
end
|
474
494
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.9.
|
4
|
+
version: 3.2.9.rc2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.2.9.
|
21
|
+
version: 3.2.9.rc2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 3.2.9.
|
29
|
+
version: 3.2.9.rc2
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: activemodel
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 3.2.9.
|
37
|
+
version: 3.2.9.rc2
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 3.2.9.
|
45
|
+
version: 3.2.9.rc2
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: arel
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|