aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb12
-rw-r--r--activerecord/lib/active_record/migration.rb2
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/tasks/databases.rake4
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"