aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRusty Geldmacher <russell.geldmacher@gmail.com>2017-05-12 11:40:31 -0400
committerGuillermo Iguaran <guilleiguaran@gmail.com>2017-05-15 18:19:12 -0500
commitbe1dd45200b1f21aec5b151d78ef402df9fa28e4 (patch)
treee62532603dcee2e68ae27a4373c3b3c99042772b /activerecord
parent7cc526beb5c1ecc509db9f607c26fabaed4b4027 (diff)
downloadrails-be1dd45200b1f21aec5b151d78ef402df9fa28e4.tar.gz
rails-be1dd45200b1f21aec5b151d78ef402df9fa28e4.tar.bz2
rails-be1dd45200b1f21aec5b151d78ef402df9fa28e4.zip
Respect `ignore_tables` in Postgres structure dump
When using `sql` as the schema format, or even just doing `rake db:structure:dump`, it would be good to respect the list of ignored tables that has been configured.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/tasks/postgresql_database_tasks.rb6
-rw-r--r--activerecord/test/cases/tasks/postgresql_rake_test.rb8
2 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
index f1af90c1e8..7f1a768d8b 100644
--- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
@@ -66,6 +66,12 @@ module ActiveRecord
"--schema=#{part.strip}"
end
end
+
+ ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
+ if ignore_tables.any?
+ args += ignore_tables.flat_map { |table| ["-T", table] }
+ end
+
args << configuration["database"]
run_cmd("pg_dump", args, "dumping")
remove_sql_header_comments(filename)
diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb
index 512388af6b..a2e968aedf 100644
--- a/activerecord/test/cases/tasks/postgresql_rake_test.rb
+++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb
@@ -259,6 +259,14 @@ if current_adapter?(:PostgreSQLAdapter)
end
end
+ def test_structure_dump_with_ignore_tables
+ ActiveRecord::SchemaDumper.expects(:ignore_tables).returns(["foo", "bar"])
+
+ Kernel.expects(:system).with("pg_dump", "-s", "-x", "-O", "-f", @filename, "-T", "foo", "-T", "bar", "my-app-db").returns(true)
+
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, @filename)
+ end
+
def test_structure_dump_with_schema_search_path
@configuration["schema_search_path"] = "foo,bar"