Skip to content

Commit

Permalink
Merge pull request #12 from seanhuber/pg-dump-exclude-tables
Browse files Browse the repository at this point in the history
Add the ability to include --exclude-table options in pg_dump
  • Loading branch information
seanhuber committed Dec 1, 2017
2 parents 89398d9 + ec01870 commit 16d9748
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ db-clone requires `mysqldump` (for MySQL) and/or `pg_dump` (for PostgreSQL).

## Installation

Add `gem 'db-clone', '~> 2.0', '>= 2.0.1'` to your `Gemfile` and `bundle install`.
Add `gem 'db-clone', '~> 2.1'` to your `Gemfile` and `bundle install`.

## Usage

Expand Down Expand Up @@ -47,7 +47,7 @@ Db::Clone.setup do |config|
# default is 'development'
config.default_destination_database = 'my_destination_db'

# default is [], adds --ignore-table arguments to mysqldump
# default is [], adds --ignore-table arguments to mysqldump or --exclude-table arguments to pg_dump
config.ignore_tables = ['schema_migrations', 'some_other_table']
end
```
Expand Down
9 changes: 7 additions & 2 deletions lib/db/clone/cmd_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,23 @@ def build_mysql_cmd src_dest
end

def build_postgresql_cmd src_dest
[
pg_dump_args = [
"pg_dump --no-password --clean",
"--host=#{src_dest[:src]['host']}",
"--port=#{src_dest[:src]['port']}",
"--username=#{src_dest[:src]['username']}",
]

Db::Clone.ignore_tables.each{|tbl| pg_dump_args << "--exclude-table=#{tbl}"}

(pg_dump_args + [
"#{src_dest[:src]['database']}",
"| psql",
"--host=#{src_dest[:dest]['host']}",
"--port=#{src_dest[:dest]['port']}",
"--username=#{src_dest[:dest]['username']}",
"#{src_dest[:dest]['database']}"
].join(' ')
]).join(' ')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/db/clone/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Db
module Clone
VERSION = '2.0.1'
VERSION = '2.1.0'
end
end
3 changes: 2 additions & 1 deletion spec/db/clone/cmd_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

cmd_builder = Db::Clone::CmdBuilder.new src: @db_yml['pg_production'], dest: @db_yml['pg_development']

expect(cmd_builder.cmd).to eq("pg_dump --no-password --clean --host=localhost --port=5432 --username=pg_prod_user pg_prod_db | psql --host=localhost --port=5432 --username=pg_dev_user pg_dev_db")
expect(cmd_builder.cmd).to eq("pg_dump --no-password --clean --host=localhost --port=5432 --username=pg_prod_user --exclude-table=table_a --exclude-table=table_b --exclude-table=table_c pg_prod_db | psql --host=localhost --port=5432 --username=pg_dev_user pg_dev_db")

end
end

0 comments on commit 16d9748

Please sign in to comment.