App-Sqitch
view release on metacpan or search on metacpan
lib/sqitchtutorial-snowflake.pod view on Meta::CPAN
* appschema ..
002003 (02000): SQL compilation error:
Schema 'FLIPR.NONESUCH' does not exist.
# Verify script "verify/appschema.sql" failed.
not ok
Verify Summary Report
---------------------
Changes: 1
Errors: 1
Verify failed
It's even nice enough to tell us what the problem is. Or, for the
divide-by-zero example, change the schema name:
USE WAREHOUSE &warehouse;
SELECT 1/COUNT(*) FROM information_schema.schemata WHERE schema_name = 'NONESUCH';
Then the verify will look something like:
> sqitch verify 'db:snowflake://movera@example/flipr?Driver=Snowflake'
Verifying db:snowflake://movera@example/flipr?Driver=Snowflake
* appschema ..
100051 (22012): Division by zero
# Verify script "verify/appschema.sql" failed.
not ok
Verify Summary Report
---------------------
Changes: 1
Errors: 1
Verify failed
Less useful error output, but enough to alert us that something has gone
wrong.
Don't forget to change the schema 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 registry
tables from the database:
> sqitch status 'db:snowflake://movera@example/flipr?Driver=Snowflake'
# On database db:snowflake://movera@example/flipr?Driver=Snowflake
# Project: flipr
# Change: 5a2ac4ae6801bfe392483ee5912b4e3592cdd57a
# Name: appschema
# Deployed: 2018-07-27 10:47:23 -0400
# 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:snowflake://movera@example/flipr?Driver=Snowflake'
Revert all changes from db:snowflake://movera@example/flipr?Driver=Snowflake? [Yes]
- appschema .. 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:
> snowsql --accountname example --username movera --dbname flipr -o friendly=false \
--query "SHOW TERSE SCHEMAS LIKE 'flipr'"
+------------+------+------+---------------+-------------+
| created_on | name | kind | database_name | schema_name |
|------------+------+------+---------------+-------------|
+------------+------+------+---------------+-------------+
0 Row(s) produced. Time Elapsed: 0.204s
And the status message should reflect as much:
> sqitch status 'db:snowflake://movera@example/flipr?Driver=Snowflake'
# On database db:snowflake://movera@example/flipr?Driver=Snowflake
No changes deployed
Of course, since nothing is deployed, the L<C<verify>|sqitch-verify> command
has nothing to verify:
> sqitch verify 'db:snowflake://movera@example/flipr?Driver=Snowflake'
Verifying db:snowflake://movera@example/flipr?Driver=Snowflake
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:snowflake://movera@example/flipr?Driver=Snowflake'
On database db:snowflake://movera@example/flipr?Driver=Snowflake
Revert 5a2ac4ae6801bfe392483ee5912b4e3592cdd57a
Name: appschema
Committer: Marge N. OâVera <marge@example.com>
Date: 2018-07-27 10:48:48 -0400
Add schema for all flipr objects.
Deploy 5a2ac4ae6801bfe392483ee5912b4e3592cdd57a
Name: appschema
Committer: Marge N. OâVera <marge@example.com>
Date: 2018-07-27 10:47:24 -0400
Add schema for all flipr objects.
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 flipr schema.'
[main 7fd5ace] Add flipr schema.
4 files changed, 10 insertions(+)
create mode 100644 deploy/appschema.sql
create mode 100644 revert/appschema.sql
create mode 100644 verify/appschema.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:snowflake://movera@example/flipr?Driver=Snowflake'
( run in 1.032 second using v1.01-cache-2.11-cpan-6aa56a78535 )