Skip to content

Commit

Permalink
Merge pull request #65 from numbata/feature/ignore_tables
Browse files Browse the repository at this point in the history
Add :db_ignore_tables option
Thanks to @rdeshpande
  • Loading branch information
numbata committed Aug 28, 2015
2 parents ea1af35 + 4304c47 commit aa58c21
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ Add to config/deploy.rb:
# if you want to remove the dump file from the server after downloading
set :db_remote_clean, true

# if you want to exclude table from dump
set :db_ignore_tables, []

# if you want to exclude table data (but not table schema) from dump
set :db_ignore_data_tables, []

# If you want to import assets, you can change default asset dir (default = system)
# This directory must be in your shared directory on the server
set :assets_dir, %w(public/assets public/att)
Expand All @@ -49,6 +55,7 @@ Add to config/deploy.rb:

# if you prefer bzip2/unbzip2 instead of gzip
set :compressor, :bzip2

```

Add to .gitignore
Expand Down
36 changes: 30 additions & 6 deletions lib/capistrano-db-tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def output_file
@output_file ||= "db/#{database}_#{current_time}.sql.#{compressor.file_extension}"
end

def pgpass
"PGPASSWORD='#{@config['password']}'" if @config['password']
end

def compressor
@compressor ||= begin
compressor_klass = @cap.fetch(:compressor).to_s.split('_').collect(&:capitalize).join
Expand All @@ -60,11 +56,15 @@ def compressor

private

def pgpass
@config['password'] ? "PGPASSWORD='#{@config['password']}'" : ""
end

def dump_cmd
if mysql?
"mysqldump #{credentials} #{database} --lock-tables=false"
"mysqldump #{credentials} #{database} #{dump_cmd_opts}"
elsif postgresql?
"#{pgpass} pg_dump --no-acl --no-owner #{credentials} #{database}"
"#{pgpass} pg_dump #{credentials} #{database} #{dump_cmd_opts}"
end
end

Expand All @@ -77,6 +77,30 @@ def import_cmd(file)
end
end

def dump_cmd_opts
if mysql?
"--lock-tables=false #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts}"
elsif postgresql?
"--no-acl --no-owner #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts}"
end
end

def dump_cmd_ignore_tables_opts
ignore_tables = @cap.fetch(:db_ignore_tables, [])
if mysql?
ignore_tables.map{ |t| "--ignore-table=#{t}" }.join(" ")
elsif postgresql?
ignore_tables.map{ |t| "--exclude-table=#{t}" }.join(" ")
end
end

def dump_cmd_ignore_data_tables_opts
ignore_tables = @cap.fetch(:db_ignore_data_tables, [])
if postgresql?
ignore_tables.map{ |t| "--exclude-table-data=#{t}" }.join(" ")
end
end

end

class Remote < Base
Expand Down

0 comments on commit aa58c21

Please sign in to comment.