Skip to content

Commit

Permalink
Respect 'ignore_tables' in MySQL structure dump
Browse files Browse the repository at this point in the history
  • Loading branch information
guilleiguaran committed May 15, 2017
1 parent be1dd45 commit 486562f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions activerecord/lib/active_record/tasks/mysql_database_tasks.rb
Expand Up @@ -60,6 +60,12 @@ def structure_dump(filename, extra_flags)
args.concat(["--routines"])
args.concat(["--skip-comments"])
args.concat(Array(extra_flags)) if extra_flags

ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
if ignore_tables.any?
args += ignore_tables.map { |table| "--ignore-table=#{configuration['database']}.#{table}" }
end

args.concat(["#{configuration['database']}"])

run_cmd("mysqldump", args, "dumping")
Expand Down
16 changes: 16 additions & 0 deletions activerecord/test/cases/tasks/mysql_rake_test.rb
Expand Up @@ -294,6 +294,13 @@ def test_structure_dump
ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
end

def test_structure_dump
filename = "awesome-file.sql"
Kernel.expects(:system).with("mysqldump", "--result-file", filename, "--no-data", "--routines", "--skip-comments", "test-db").returns(true)

ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
end

def test_structure_dump_with_extra_flags
filename = "awesome-file.sql"
expected_command = ["mysqldump", "--result-file", filename, "--no-data", "--routines", "--skip-comments", "--noop", "test-db"]
Expand All @@ -305,6 +312,15 @@ def test_structure_dump_with_extra_flags
end
end

def test_structure_dump_with_ignore_tables
filename = "awesome-file.sql"
ActiveRecord::SchemaDumper.expects(:ignore_tables).returns(["foo", "bar"])

Kernel.expects(:system).with("mysqldump", "--result-file", filename, "--no-data", "--routines", "--skip-comments", "--ignore-table=test-db.foo", "--ignore-table=test-db.bar", "test-db").returns(true)

ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
end

def test_warn_when_external_structure_dump_command_execution_fails
filename = "awesome-file.sql"
Kernel.expects(:system)
Expand Down

0 comments on commit 486562f

Please sign in to comment.