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
This commit is contained in:
David Heinemeier Hansson
2005-09-12 05:33:18 +00:00
parent 9105cd1064
commit a16528f715
4 changed files with 18 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 File

@@ -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"