diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-01-01 22:55:49 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-01 22:55:49 -0500 |
commit | 2e621f6c911c75ed802c3ca8e07f5ea853bb057c (patch) | |
tree | 42dcbcf582da112ec626fc6bacf88d60059836db /activerecord/lib | |
parent | fadc0dc151e9e010cf5cfa0e05d4427eb1be321c (diff) | |
parent | 6cd757963d7f6b9bb33704c82bd9ee2bacaa1e28 (diff) | |
download | rails-2e621f6c911c75ed802c3ca8e07f5ea853bb057c.tar.gz rails-2e621f6c911c75ed802c3ca8e07f5ea853bb057c.tar.bz2 rails-2e621f6c911c75ed802c3ca8e07f5ea853bb057c.zip |
Merge pull request #27526 from kirs/database-tasks-schema-cache
Dump schema cache for custom connection
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 25d79a6c7d..cf1c0fb423 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -269,10 +269,7 @@ db_namespace = namespace :db do task dump: [:environment, :load_config] do conn = ActiveRecord::Base.connection filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema_cache.yml") - - conn.schema_cache.clear! - conn.data_sources.each { |table| conn.schema_cache.add(table) } - open(filename, "wb") { |f| f.write(YAML.dump(conn.schema_cache)) } + ActiveRecord::Tasks::DatabaseTasks.dump_schema_cache(conn, filename) end desc "Clears a db/schema_cache.yml file." diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index 6f868b6b7e..1423e6008f 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -275,6 +275,16 @@ module ActiveRecord end end + # Dumps the schema cache in YAML format for the connection into the file + # + # ==== Examples: + # ActiveRecord::Tasks::DatabaseTasks.dump_schema_cache(ActiveRecord::Base.connection, "tmp/schema_dump.yaml") + def dump_schema_cache(conn, filename) + conn.schema_cache.clear! + conn.data_sources.each { |table| conn.schema_cache.add(table) } + open(filename, "wb") { |f| f.write(YAML.dump(conn.schema_cache)) } + end + private def class_for_adapter(adapter) |