Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTom committed Jan 27, 2015
1 parent e5f44c2 commit 49f7fb7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ Style/SpecialGlobalVars:
# Offense count: 4
Style/UnlessElse:
Enabled: false

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 11
31 changes: 15 additions & 16 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PostgreSQL Tasks and Functions for Ruby on Rails
Add this line to your application's Gemfile:

```ruby
gem 'pg_tasks', '>= 1.0.0', '< 2.0.0'
gem 'pg_tasks', '>= 1.1.0', '< 2.0.0'
```

## Usage
Expand Down Expand Up @@ -39,23 +39,22 @@ PgTasks.structure_and_data_restore(filename = nil)

## Internals and Caveats

This library uses and extends `ActiveRecord::Tasks::DatabaseTasks` as
well as `ActiveRecord::Tasks::PostgreSQLDatabaseTasks`.
This library uses and extends `ActiveRecord::Tasks::DatabaseTasks` as well as
`ActiveRecord::Tasks::PostgreSQLDatabaseTasks`.

The dump and restore tasks communicate with Postgresql via the system
binaries `pg_dump` and `pg_restore` (in the same way as some of the
original rails tasks do). `truncate_tables` uses
`ActiveRecord::Base.connection`.
The dump and restore tasks communicate with Postgresql via the system binaries
`pg_dump` and `pg_restore` (in the same way as some of the original rails tasks
do). `truncate_tables` uses `ActiveRecord::Base.connection`.

Restoring a complete database doesn't play well if there are open
connections. There will be warnings if there are conflicts during
restore. The restore continues however.
Restoring a complete database doesn't play well if there are open connections.
Restore is carried out in a single transaction add will abort immediately if
there is a problem.

`data_dump` might warn you about circular dependencies. Never mind,
`restore` disables the triggers temporarily. The role for restore
requieres permissions to disable triggers temporarily.
`data_dump` might warn you about circular dependencies. Never mind, `restore`
disables the triggers temporarily. The role for restore requieres permissions
to disable triggers temporarily.

`data_dump` as well as `truncate_tables` leaves the `schema_migrations`
table alone. This is the desired behavior for a library designed to
interact with *ruby on rails* respectively *active record*.
`data_dump` as well as `truncate_tables` leaves the `schema_migrations` table
alone. This is the desired behavior for a library designed to interact with
*ruby on rails* respectively *active record*.

7 changes: 4 additions & 3 deletions lib/pg_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def data_dump(filename)

def data_restore(filename)
set_psql_env
command = 'pg_restore --disable-triggers -a -x -O -d ' \
"#{Shellwords.escape(configuration['database'])} " \
command = 'pg_restore --disable-triggers ' \
'--single-transaction -a -x -O ' \
"-d #{Shellwords.escape(configuration['database'])} " \
"#{Shellwords.escape(filename)}"
unless Kernel.system(command)
raise 'Error during data_restore '
Expand All @@ -107,7 +108,7 @@ def structure_and_data_dump(filename)

def structure_and_data_restore(filename)
set_psql_env
command = 'pg_restore --disable-triggers -x -O -d ' \
command = 'pg_restore --disable-triggers --single-transaction -x -O -d ' \
"#{Shellwords.escape(configuration['database'])} " \
"#{Shellwords.escape(filename)}"
unless Kernel.system(command)
Expand Down

0 comments on commit 49f7fb7

Please sign in to comment.