Permalink
Browse files

Added dump of schema version to the db_structure_dump task for databa…

…ses that support migrations #1835 [Rick Olson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2215 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9105cd1 commit a16528f715f49531c6013dde741fcba8182202b6 @dhh dhh committed Sep 12, 2005
View
12 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -374,7 +374,17 @@ def initialize_schema_information
# 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
View
2 activerecord/lib/active_record/migration.rb
@@ -170,7 +170,7 @@ def down(migrations_path, target_version = nil)
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
View
2 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]
View
4 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"

0 comments on commit a16528f

Please sign in to comment.