diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-12 05:33:18 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-12 05:33:18 +0000 |
commit | a16528f715f49531c6013dde741fcba8182202b6 (patch) | |
tree | 6662c2a59e0793e2f9c606baa967ef2b66fdafb8 | |
parent | 9105cd10640c06b53536d99211ef8183b1fa7705 (diff) | |
download | rails-a16528f715f49531c6013dde741fcba8182202b6.tar.gz rails-a16528f715f49531c6013dde741fcba8182202b6.tar.bz2 rails-a16528f715f49531c6013dde741fcba8182202b6.zip |
Added dump of schema version to the db_structure_dump task for databases that support migrations #1835 [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2215 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 2 | ||||
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/tasks/databases.rake | 4 |
4 files changed, 18 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index e0c880780e..cbc8e7c273 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -374,7 +374,17 @@ module ActiveRecord # Schema has been intialized end end - + + def dump_schema_information + begin + if (current_schema = ActiveRecord::Migrator.current_version) > 0 + return "INSERT INTO schema_info (version) VALUES (#{current_schema});" + end + rescue ActiveRecord::StatementInvalid + # No Schema Info + end + end + def create_table(name, options = {}) table_definition = TableDefinition.new(self) table_definition.primary_key(options[:primary_key] || "id") unless options[:id] == false diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 6f9b0ee2b4..9cde37548d 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -170,7 +170,7 @@ module ActiveRecord end def current_version - Base.connection.select_one("SELECT version FROM schema_info")["version"].to_i + (Base.connection.select_one("SELECT version FROM schema_info") || {})["version"].to_i end end diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 56588f4707..a2a099155f 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added dump of schema version to the db_structure_dump task for databases that support migrations #1835 [Rick Olson] + * Fixed script/profiler for Ruby 1.8.2 #1863 [Rick Olson] * Fixed clone_structure_to_test task for SQLite #1864 [jon@burningbush.us] diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 5ea69da240..e7ae234b53 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -61,6 +61,10 @@ task :db_structure_dump => :environment do else raise "Unknown database adapter '#{abcs["test"]["adapter"]}'" end + + if ActiveRecord::Base.connection.supports_migrations? + File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } + end end desc "Empty the test database" |