Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit a16528f715f49531c6013dde741fcba8182202b6 1 parent 9105cd1
David Heinemeier Hansson dhh authored
12 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
View
@@ -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
2  activerecord/lib/active_record/migration.rb
View
@@ -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
2  railties/CHANGELOG
View
@@ -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]
4 railties/lib/tasks/databases.rake
View
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.