App-Sqitch

 view release on metacpan or  search on metacpan

lib/sqitchtutorial-sqlite.pod  view on Meta::CPAN


  SELECT nickname, password, fullname, twitter
	FROM users
   WHERE 0;

Now you can run the C<verify> script with the L<C<verify>|sqitch-verify>
command:

  > sqitch verify db:sqlite:flipr_test.db
  Verifying db:sqlite:flipr_test.db
	* users .. 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 table name in the script to
something that doesn't exist, something like:

  SELECT nickname, password, timestamp
	FROM users_nonesuch
   WHERE 0;

Then L<C<verify>|sqitch-verify> again:

  > sqitch verify db:sqlite:flipr_test.db
  Verifying db:sqlite:flipr_test.db
    * users .. Error: near line 5: no such table: users_nonesuch
  # Verify script "verify/users.sql" failed.
  not ok

  Verify Summary Report
  ---------------------
  Changes: 1
  Errors:  1
  Verify failed

SQLite is kind enough 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:sqlite:flipr_test.db
  # On database db:sqlite:flipr_test.db
  # Project:  flipr
  # Change:   f30fe47f5f99501fb8d481e910d9112c5ac0a676
  # Name:     users
  # Deployed: 2013-12-31 10:26:59 -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:sqlite:flipr_test.db
  Revert all changes from db:sqlite:flipr_test.db? [Yes] 
	- users .. 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:

	> sqlite3 flipr_test.db '.tables'

And the status message should reflect as much:

  > sqitch status db:sqlite:flipr_test.db
  # On database db:sqlite:flipr_test.db
  No changes deployed

Of course, since nothing is deployed, the L<C<verify>|sqitch-verify> command
has nothing to verify:

  > sqitch verify db:sqlite:flipr_test.db
  Verifying db:sqlite:flipr_test.db
  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:sqlite:flipr_test.db
  On database db:sqlite:flipr_test.db
  Revert f30fe47f5f99501fb8d481e910d9112c5ac0a676
  Name:      users
  Committer: Marge N. O’Vera <marge@example.com>
  Date:      2013-12-31 10:53:25 -0800

      Creates table to track our users.

  Deploy f30fe47f5f99501fb8d481e910d9112c5ac0a676
  Name:      users
  Committer: Marge N. O’Vera <marge@example.com>
  Date:      2013-12-31 10:26:59 -0800

      Creates table to track our users.

Note that the actions we took are shown in reverse chronological order, with
the revert first and then the deploy.

Cool. Let's tell Git to ignore F<*.db> files and then commit it.

  > echo '*.db' > .gitignore
  > git add .
  > git commit -m 'Add users table.'
  [main 6725454] Add users table.
   5 files changed, 31 insertions(+)
   create mode 100644 .gitignore
   create mode 100644 deploy/users.sql
   create mode 100644 revert/users.sql
   create mode 100644 verify/users.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 db:sqlite:flipr_test.db --verify
  Deploying changes to db:sqlite:flipr_test.db
	+ users .. ok

And now the C<users> table should be back:



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