aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/schema_dumper.rb
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2012-12-02 21:16:32 -0800
committerJosh Susser <josh@hasmanythrough.com>2012-12-02 21:16:32 -0800
commitf02d2185ebbe01f455a9a91216ff7094b014ea72 (patch)
tree078c6183d84a9b3c7e72fe77450083df13d86b7e /activerecord/lib/active_record/schema_dumper.rb
parent0a5afa229d769bce9e221f34053bb93b60817a5a (diff)
downloadrails-f02d2185ebbe01f455a9a91216ff7094b014ea72.tar.gz
rails-f02d2185ebbe01f455a9a91216ff7094b014ea72.tar.bz2
rails-f02d2185ebbe01f455a9a91216ff7094b014ea72.zip
Add migration history to schema.rb dump
Diffstat (limited to 'activerecord/lib/active_record/schema_dumper.rb')
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 36bde44e7c..73c0f5b9eb 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -24,6 +24,7 @@ module ActiveRecord
def dump(stream)
header(stream)
+ migrations(stream)
tables(stream)
trailer(stream)
stream
@@ -44,7 +45,7 @@ module ActiveRecord
stream.puts "# encoding: #{stream.external_encoding.name}"
end
- stream.puts <<HEADER
+ header_text = <<HEADER_RUBY
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
@@ -59,13 +60,25 @@ module ActiveRecord
ActiveRecord::Schema.define(#{define_params}) do
-HEADER
+HEADER_RUBY
+ stream.puts header_text
end
def trailer(stream)
stream.puts "end"
end
+ def migrations(stream)
+ all_migrations = ActiveRecord::SchemaMigration.all.to_a
+ if all_migrations.any?
+ stream.puts(" migrations do")
+ all_migrations.each do |migration|
+ stream.puts(migration.schema_line(" "))
+ end
+ stream.puts(" end")
+ end
+ end
+
def tables(stream)
@connection.tables.sort.each do |tbl|
next if ['schema_migrations', ignore_tables].flatten.any? do |ignored|