r3569@asus: jeremy | 2005-09-26 05:33:09 -0700
Ticket 1749 - reset_sequences workaround for non-integer sequences r3570@asus: jeremy | 2005-09-26 08:30:30 -0700 Fixtures.reset_sequences should only reset sequences corresponding to integer primary keys named id. #1749 r3571@asus: jeremy | 2005-09-26 08:31:11 -0700 Update change log. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2343 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
b2c46ed5fd
commit
a68557952f
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Fixtures should only reset a PostgreSQL sequence if it corresponds to an integer primary key named id. #1749 [chris@chrisbrinker.com]
|
||||||
|
|
||||||
* Standardize the interpretation of boolean columns in the Mysql and Sqlite adapters. (Use MysqlAdapter.emulate_booleans = false to disable this behavior)
|
* Standardize the interpretation of boolean columns in the Mysql and Sqlite adapters. (Use MysqlAdapter.emulate_booleans = false to disable this behavior)
|
||||||
|
|
||||||
* Added new symbol-driven approach to activating observers with Base#observers= [DHH]. Example:
|
* Added new symbol-driven approach to activating observers with Base#observers= [DHH]. Example:
|
||||||
|
|
|
@ -246,15 +246,15 @@ class Fixtures < Hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Work around for PostgreSQL to have new fixtures created from id 1 and running.
|
# Start PostgreSQL fixtures at id 1. Skip tables without models
|
||||||
|
# and models with nonstandard primary keys.
|
||||||
def self.reset_sequences(connection, table_names)
|
def self.reset_sequences(connection, table_names)
|
||||||
table_names.flatten.each do |table|
|
table_names.flatten.each do |table|
|
||||||
table_class = Inflector.classify(table.to_s)
|
if table_class = table.to_s.classify.constantize rescue nil
|
||||||
if Object.const_defined?(table_class)
|
pk = table_class.columns_hash[table_class.primary_key]
|
||||||
pk = eval("#{table_class}::primary_key")
|
if pk and pk.name == 'id' and pk.type == :integer
|
||||||
if pk == 'id'
|
|
||||||
connection.execute(
|
connection.execute(
|
||||||
"SELECT setval('#{table.to_s}_id_seq', (SELECT MAX(id) FROM #{table.to_s}), true)",
|
"SELECT setval('#{table}_id_seq', (SELECT MAX(id) FROM #{table}), true)",
|
||||||
'Setting Sequence'
|
'Setting Sequence'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue