Skip to content

Commit

Permalink
Show dependencies in add info message.
Browse files Browse the repository at this point in the history
Also localize them.

Also in the process of updating the tutorial.
  • Loading branch information
theory committed Jun 27, 2012
1 parent 434877a commit 12b190d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
7 changes: 6 additions & 1 deletion lib/App/Sqitch/Command/add.pm
Expand Up @@ -5,6 +5,7 @@ use strict;
use warnings;
use utf8;
use Template::Tiny;
use Locale::TextDomain qw(App-Sqitch);
use Moose;
use MooseX::Types::Path::Class;
use Path::Class;
Expand Down Expand Up @@ -161,7 +162,11 @@ sub execute {

# We good, write the plan file back out.
$plan->write_to( $sqitch->plan_file );
$self->info( qq{Added "$name" to }, $sqitch->plan_file );
$self->info(__x(
'Added "{change}" to "{file}"',
change => $change->format_content,
file => $sqitch->plan_file,
));
return $self;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/sqitch-add.pod
@@ -1,15 +1,15 @@
=head1 Name

sqitch-add - Add a deployment change
sqitch-add - Add a database change to the plan

=head1 Synopsis

sqitch [options] add [<template-options>] name

=head1 Description

Add a new deployment change. This will result in the creation of a new script
files with the C<--extension> extension in the C<--deploy-dir>,
Add a database change to the plan. This will result in the creation of a new
script files with the C<--extension> extension in the C<--deploy-dir>,
C<--revert-dir>, and C<--test-dir> directories. The content of these files is
determined by the evaluation of templates. By default, system templates in
F<$(etc_path)/templates> are used. These can be overridden by a single user by
Expand Down
41 changes: 14 additions & 27 deletions lib/sqitchtutorial.pod
Expand Up @@ -130,11 +130,8 @@ Now we can try deploying this change:
First Sqitch created the metadata tables used to track database changes. The
structure and name of the metadata tables varies between databases (PostgreSQL
uses a schema to namespace its metadata; MySQL and SQLite use a prefix). Next,
Sqitch deploys changes. Here it is deploying something called C<HEAD+>.
Normally you would see a tag here, but since we've just added the files and
they are not yet committed to Git, there is no tag. C<HEAD+> is a special tag
reserved for use by Sqitch. It's enabled only by the use of the C<--untracked>
option, which allows Sqitch to find an deploy untracked changes.
Sqitch deploys changes. We only have one so far; the C<+> reinforces the idea
that the change is being added to the database.

With this change deployed, if you connect to the database, you'll be able to
see the role:
Expand All @@ -150,7 +147,6 @@ which reads the metadata tables from the database:

> sqitch -d flipr_test status
# On database flipr_test
# Tag: HEAD+
# Change: appuser
# Date: 2012-04-09 18:43:45
#
Expand All @@ -162,6 +158,7 @@ Let's make sure that we can revert the change:
Reverting all changes from flipr_test
- appuser

Note the C<-> reinforces that the change is being removed from the database.
And now the user should be gone:

> psql -d flipr_test -c '\du flipr'
Expand All @@ -171,64 +168,54 @@ And now the user should be gone:

And the status message should reflect as much:

> sqitch -d flipr_test status --untracked
> sqitch -d flipr_test status
# On database flipr_test
# Nothing deployed.
#
# Changes not deployed:
# * HEAD+
# appuser
#
Use "sqitch deploy --untracked" to deploy these changes

We've again used the C<--untracked> option, otherwise the C<appuser> change would
not appear in the list of "Changes not yet deployed."

We still have a record that the change happened, visible via the C<log>
command:

> sqitch -d flipr_test log
change appuser reverted
By: david
Date: 2012-04-09 18:45:47
Tag: HEAD+

change appuser deployed
By: david
Date: 2012-04-09 18:43:45
Tag: HEAD+

Cool. Now let's commit it.

> git add .
> git commit -m 'Add app user.'
[master 36acafd] Add app user.
[master a29fb74] Add app user.
2 files changed, 2 insertions(+)
create mode 100644 sql/deploy/appuser.sql
create mode 100644 sql/revert/appuser.sql
create mode 100644 deploy/appuser.sql
create mode 100644 revert/appuser.sql

And then deploy again:

> sqitch --db-name flipr_test deploy
Deploying 36acafd to flipr_test
Deploying changes to flipr_test
+ appuser

Notice we no longer need the C<--untracked> option. That's because we've
committed the change to Git, so Sqitch can read it from the Git history. And now
the user should be back:
And now the user should be back:

> psql -d flipr_test -c '\du flipr'
List of roles
Role name | Attributes | Member of
-----------+------------+-----------
flipr | | {}

When we look at the status, the deployment is tagged with the SHA1 of the
commit:
When we look at the status, the deployment will be there:

> sqitch -d flipr_test status
# On database flipr_test
# Tag: 36acafd
# Change: appuser
# Date: 2012-04-09 18:52:42
#
Expand All @@ -247,7 +234,6 @@ in, e.g.:

> sqitch status
# On database flipr_test
# Tag: 36acafd
# Change: appuser
# Date: 2012-04-09 18:52:42
#
Expand All @@ -262,9 +248,10 @@ Let's add another deployment, this time to create a table. Our app will need
users, of course, so we'll create a table for them. First, add the new change:

> sqitch add users --requires appuser
Created sql/deploy/users.sql
Created sql/revert/users.sql
Created sql/test/users.sql
Created deploy/users.sql
Created revert/users.sql
Created test/users.sql
Added "users :appuser" to sqitch.plan

Now edit the scripts. In C<sql/deploy/users.sql>, we put:

Expand Down
13 changes: 10 additions & 3 deletions t/add.t
Expand Up @@ -6,6 +6,7 @@ use utf8;
use Test::More tests => 77;
#use Test::More 'no_plan';
use App::Sqitch;
use Locale::TextDomain qw(App-Sqitch);
use Path::Class;
use Test::NoWarnings;
use Test::Exception;
Expand Down Expand Up @@ -280,7 +281,10 @@ is_deeply +MockOutput->get_info, [
["Created $deploy_file"],
["Created $revert_file"],
["Created $test_file"],
[qq{Added "widgets_table" to }, $sqitch->plan_file ],
[__x 'Added "{change}" to "{file}"',
change => 'widgets_table',
file => $sqitch->plan_file,
],
], 'Info should have reported file creation';

# Relod the plan file to make sure change is written to it.
Expand Down Expand Up @@ -317,5 +321,8 @@ is_deeply +MockOutput->get_info, [
["Skipped $deploy_file: already exists"],
["Created $revert_file"],
["Created $test_file"],
[qq{Added "foo_table" to }, $sqitch->plan_file ],
], 'Info should have reported skipping file';
[__x 'Added "{change}" to "{file}"',
change => 'foo_table :widgets_table !dr_evil !joker',
file => $sqitch->plan_file,
],
], 'Info should report skipping file and include dependencies';

0 comments on commit 12b190d

Please sign in to comment.