No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 1 commit ahead, 3 commits behind DrTom:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
.rubocop.yml
Gemfile
Gemfile.lock
MIT-LICENSE
README.mkd
Rakefile
pg_tasks.gemspec

README.mkd

PostgreSQL Tasks and Functions for Ruby on Rails

Installation

Add this line to your application's Gemfile:

gem 'pg_tasks', '>= 1.1.0', '< 2.0.0'

Usage

Rake Tasks

The following rake tasks are available:

rake db:pg:data:dump FILE=...
rake db:pg:data:restore FILE=...
rake db:pg:structure_and_data:dump FILE=...
rake db:pg:structure_and_data:restore FILE=...
rake db:pg:terminate_connections
rake db:pg:truncate_tables

The meaning should be clear from the names.

The FILE environment variable is optional. There are defaults.

Access from Ruby Code

PgTasks.data_dump(filename = nil)
PgTasks.data_restore(filename = nil)
PgTasks.structure_and_data_dump(filename = nil)
PgTasks.structure_and_data_restore(filename = nil)
PgTasks.terminate_connections()
PgTasks.truncate_tables()

Internals and Caveats

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.

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 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.

Calling PgTasks.terminate_connections() will also terminate the current connection.