App-Sqitch

 view release on metacpan or  search on metacpan

lib/sqitch-configuration.pod  view on Meta::CPAN

  * prod-primary
      URI:           db:pg://sqitch@db1.example.com/widgets
      Registry:      sqitch
      Client:        psql
      Top Directory: pg
      Plan File:     sqitch.plan
      Extension:     sql
      Script Directories:
        Deploy:      pg/deploy
        Revert:      pg/revert
        Verify:      pg/verify
      Reworked Script Directories:
        Reworked:    pg
        Deploy:      pg/deploy
        Revert:      pg/revert
        Verify:      pg/verify
      No Variables
  * prod-standby
      URI:           db:pg://sqitch@db2.example.com/widgets
      Registry:      sqitch
      Client:        psql
      Top Directory: pg
      Plan File:     sqitch.plan
      Extension:     sql
      Script Directories:
        Deploy:      pg/deploy
        Revert:      pg/revert
        Verify:      pg/verify
      Reworked Script Directories:
        Reworked:    pg
        Deploy:      pg/deploy
        Revert:      pg/revert
        Verify:      pg/verify
      No Variables

Note the use of the shared plan and the F<pg> directory for scripts. We can
add a target for our SQLite database, too. Maybe it's used for development?

  > sqitch target add dev-sqlite db:sqlite:/var/db/widgets_dev.db
  > sqitch target show dev-sqlite
  * dev-sqlite
      URI:           db:sqlite:/var/db/widgets_dev.db
      Registry:      sqitch
      Client:        sqlite3
      Top Directory: sqlite
      Plan File:     sqitch.plan
      Extension:     sql
      Script Directories:
        Deploy:      sqlite/deploy
        Revert:      sqlite/revert
        Verify:      sqlite/verify
      Reworked Script Directories:
        Reworked:    sqlite
        Deploy:      sqlite/deploy
        Revert:      sqlite/revert
        Verify:      sqlite/verify
      No Variables

Now deploying any of these databases is as simple as specifying the target
name when executing the L<C<deploy>|sqitch-deploy> command (assuming the
C<sqitch> user is configured to authenticate to PostgreSQL without prompting
for a password):

  > sqitch deploy prod-primary
  > sqitch deploy prod-standby

Want them all? Just query the targets and pass each in turn:

  for target in `sqitch target | grep prod-`; do
      sqitch deploy $target
  done

The commands that accept a target name are identical to those that take
an engine name or target URI, as described in L</Database Interactions>.

=head2 Different Target, Different Plan

What about a project that manages different -- but related -- schemas on the
same engine? For example, say you have two plans for PostgreSQL, one for a
canonical data store, and one for a read-only copy that will have a subset of
data replicated to it. Maybe your billing database just needs an up-to-date
copy of the C<customers> and C<users> tables.

Targets can help us here, too. Just create the new plan file. It might use
some of the same change scripts as the canonical plan, or its own scripts, or
some of each. Just be sure all of its scripts are in the same top directory.
Then add targets for the specific servers and plans:

  > sqitch target add prod-primary db:pg://db1.example.com/widgets
  > sqitch target add prod-billing db:pg://cpa.example.com/billing --plan-file target.plan
  > sqitch target show prod-billing
  * prod-billing
      URI:           db:pg://cpa.example.com/billing
      Registry:      sqitch
      Client:        psql
      Top Directory: pg
      Plan File:     target.plan
      Extension:     sql
      Script Directories:
        Deploy:      pg/deploy
        Revert:      pg/revert
        Verify:      pg/verify
      Reworked Script Directories:
        Reworked:    pg
        Deploy:      pg/deploy
        Revert:      pg/revert
        Verify:      pg/verify
      No Variables

Now, any management of the C<prod-billing> target will use the F<target.plan>
plan file. Want to add changes to that plan? specify the plan file. Here's
an example that re-uses the existing change scripts:

  > sqitch add users target.plan -n 'Creates users table.'
  Skipped pg/deploy/users.sql: already exists
  Skipped pg/revert/users.sql: already exists
  Skipped pg/test/users.sql: already exists
  Skipped pg/verify/users.sql: already exists
  Added "users" to target.plan

=head1 Overworked



( run in 1.294 second using v1.01-cache-2.11-cpan-0b5f733616e )