App-Sqitch
view release on metacpan or search on metacpan
lib/sqitchtutorial-mysql.pod view on Meta::CPAN
END IF;
RETURN doit;
END;
|
Now you can run the C<verify> script with the L<C<verify>|sqitch-verify>
command:
> sqitch verify db:mysql://root@/flipr_test
Verifying flipr_test
* appuser .. ok
Verify successful
Looks good! If you want to make sure that the verify script correctly dies if
the table doesn't exist, temporarily change the user name in the script to
something that doesn't exist, something like:
SELECT sqitch.checkit(COUNT(*), 'User "flipr" does not exist')
FROM mysql.user WHERE user = 'nonesuch';
Then L<C<verify>|sqitch-verify> again:
> sqitch verify db:mysql://root@/flipr_test
Verifying db:mysql://root@/flipr_test
* appuser .. ERROR 1644 (ERR0R) at line 5 in file: 'verify/appuser.sql': User "flipr" does not exist
# Verify script "verify/appuser.sql" failed.
not ok
Verify Summary Report
---------------------
Changes: 1
Errors: 1
Verify failed
The C<checkit()> function is kind enough to use the error message to tell us
what the problem is. Don't forget to change the table name back before
continuing!
=head2 Status, Revert, Log, Repeat
For purely informational purposes, we can always see how a deployment was
recorded via the L<C<status>|sqitch-status> command, which reads the tables
from the registry database:
> sqitch status db:mysql://root@/flipr_test
# On database db:mysql://root@/flipr_test
# Project: flipr
# Change: f56dd1a1ab029f398cec2cebb2ecc527fa0332c2
# Name: appuser
# Deployed: 2013-12-31 13:13:17 -0800
# By: Marge N. OâVera <marge@example.com>
#
Nothing to deploy (up-to-date)
Let's make sure that we can revert the change:
> sqitch revert db:mysql://root@/flipr_test
Revert all changes from db:mysql://root@/flipr_test? [Yes]
- appuser .. ok
The L<C<revert>|sqitch-revert> command first prompts to make sure that we
really do want to revert. This is to prevent unnecessary accidents. You can
pass the C<-y> option to disable the prompt. Also, notice the C<-> before the
change name in the output, which reinforces that the change is being
I<removed> from the database. And now the schema should be gone:
> mysql -u root --execute "SELECT user from mysql.user WHERE user = 'flipr';"
And the status message should reflect as much:
> sqitch status db:mysql://root@/flipr_test
# On database db:mysql://root@/flipr_test
No changes deployed
Of course, since nothing is deployed, the L<C<verify>|sqitch-verify> command
has nothing to verify:
> sqitch verify db:mysql://root@/flipr_test
Verifying db:mysql://root@/flipr_test
No changes deployed
However, we still have a record that the change happened, visible via the
L<C<log>|sqitch-log> command:
> sqitch log db:mysql://root@/flipr_test
On database db:mysql://root@/flipr_test
Revert f56dd1a1ab029f398cec2cebb2ecc527fa0332c2
Name: appuser
Committer: Marge N. OâVera <marge@example.com>
Date: 2013-12-31 13:26:39 -0800
Creates a an application user.
Deploy f56dd1a1ab029f398cec2cebb2ecc527fa0332c2
Name: appuser
Committer: Marge N. OâVera <marge@example.com>
Date: 2013-12-31 13:13:17 -0800
Creates a an application user.
Note that the actions we took are shown in reverse chronological order, with
the revert first and then the deploy.
Cool. Now let's commit it.
> git add .
> git commit -m 'Add the "flipr" user.'
[main c63acb9] Add the "flipr" user.
4 files changed, 23 insertions(+)
create mode 100644 deploy/appuser.sql
create mode 100644 revert/appuser.sql
create mode 100644 verify/appuser.sql
And then deploy again. This time, let's use the C<--verify> option, so that
the C<verify> script is applied when the change is deployed:
> sqitch deploy --verify db:mysql://root@/flipr_test
Deploying changes to db:mysql://root@/flipr_test
+ appuser .. ok
And now the C<flipr> user should be back:
> mysql -u root --execute "SELECT user from mysql.user WHERE user = 'flipr';"
( run in 1.673 second using v1.01-cache-2.11-cpan-6aa56a78535 )