diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-03-28 21:21:01 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-03-28 21:21:01 +0000 |
commit | c00de99f69358b58ca2bd6bc732e2de1b667800e (patch) | |
tree | fd5d4855a64bb15a99494b7efdb62f4798321a52 /activerecord/lib/active_record/connection_adapters | |
parent | ad8df03f9c831d88b8a7eb80c1b7dbcf02fc1b19 (diff) | |
download | rails-c00de99f69358b58ca2bd6bc732e2de1b667800e.tar.gz rails-c00de99f69358b58ca2bd6bc732e2de1b667800e.tar.bz2 rails-c00de99f69358b58ca2bd6bc732e2de1b667800e.zip |
Switched to UTC-timebased version numbers for migrations and the schema. This will as good as eliminate the problem of multiple migrations getting the same version assigned in different branches. Also added rake db:migrate:up/down to apply individual migrations that may need to be run when you merge branches (closes #11458) [jbarnette]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9122 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index b1f1fd4d73..c8913d0157 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -232,12 +232,20 @@ module ActiveRecord # Should not be called normally, but this operation is non-destructive. # The migrations module handles this automatically. - def initialize_schema_information + def initialize_schema_information(current_version=0) begin - execute "CREATE TABLE #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)} (version #{type_to_sql(:integer)})" - execute "INSERT INTO #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)} (version) VALUES(0)" + execute "CREATE TABLE #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)} (version #{type_to_sql(:string)})" + execute "INSERT INTO #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)} (version) VALUES(#{current_version})" rescue ActiveRecord::StatementInvalid - # Schema has been initialized + # Schema has been initialized, make sure version is a string + version_column = columns(:schema_info).detect { |c| c.name == "version" } + + # can't just alter the table, since SQLite can't deal + unless version_column.type == :string + version = ActiveRecord::Migrator.current_version + execute "DROP TABLE #{quote_table_name(ActiveRecord::Migrator.schema_info_table_name)}" + initialize_schema_information(version) + end end end |