sqitch - Sane database change management
sqitch [<options>] <command> [<command-options>] [<args>]
Sqitch is not integrated with any framework, ORM, or platform. Rather, it is a standalone change management system with no opinions about your database engine, application framework, or your development environment.
Database changes may declare dependencies on other changes -- even on changes from other Sqitch projects. This ensures proper order of execution, even when you've committed changes to your VCS out-of-order.
Change deployment is managed by maintaining a plan file. As such, there is no need to number your changes, although you can if you want. Sqitch doesn't much care how you name your changes.
Up until you tag and release your application, you can modify your change deployment scripts as often as you like. They're not locked in just because they've been committed to your VCS. This allows you to take an iterative approach to developing your database schema. Or, better, you can do test-driven database development.
A named unit of change. A change name must be used in the file names of its deployment and a reversion scripts. It may also be used in a test script file name.
A known deployment state, pointing to a single change, typically corresponding to a release. Think of it is a version number or VCS revision. A given point in the plan may have any number of tags.
The current state of the database. This is represented by the most recently-deployed change. If the state of the database is the same as the most recent change, then it is considered "up-to-date".
A list of one or more changes and their dependencies that define the order of deployment execution. The plan is stored in a "plan file," usually named sqitch.plan. Sqitch reads the plan file to determine what changes to execute to change the database from one state to another.
The act of adding a change to the plan. Sqitch will generate scripts for the change, which you then may modify with the necessary code (typically DDLs) to actually deploy, revert, and test the change.
The act of deploying changes to a database. Sqitch reads the plan, checks the current state of the database, and applies all the changes necessary to either bring the database up-to-date or to a requested state (a change name or tag).
The act of reverting database changes to reach an earlier deployment state. Sqitch reads the list of deployed changes from the database and reverts them in the reverse of the order in which they were applied. All changes may be reverted, or changes may be reverted to a requested state (a change name or tag).
User who commits or reverts changes to a database.
User who adds a change to the plan.
--plan-file FILE Path to a deployment plan file. --engine ENGINE Database engine. --db-client PATH Path to the engine command-line client. -d --db-name NAME Database name. -u --db-user USER Database user name. --db-host HOST Database server host name. --db-port PORT Database server port number. --top-dir DIR Path to directory with plan and scripts. --deploy-dir DIR Path to directory with deployment scripts. --revert-dir DIR Path to directory with reversion scripts. --test-dir DIR Path to directory with test scripts. --extension EXT SQL script file name extension. --etc-path Print the path to the etc directory and exit. --quiet Quiet mode with non-error output suppressed. --verbose Increment verbosity. --version Print the version number and exit. --help Print a usage statement and exit. --man Print the complete documentation and exit.
sqitch --plan-file plan.txt
Path to the deployment plan file. Defaults to $top_dir/sqitch.plan. See "Plan File" for a description of its structure.
sqitch --engine pg
The database engine to use. Supported engines include:
sqitch --db-client /usr/local/pgsql/bin/psql
Path to the command-line client for the database engine. Defaults to a client in the current path named appropriately for the specified engine.
sqitch --db-name widgets sqitch -d bricolage
sqitch --db-username root sqitch --db-user postgres sqitch -u Mom
User name to use when connecting to the database. Does not apply to all engines.
sqitch --db-host db.example.com
Host name to use when connecting to the database. Does not apply to all engines.
sqitch --db-port 7654
Port number to connect to. Does not apply to all engines.
sqitch --top-dir migrations/
Path to directory containing deployment, reversion, and test SQL scripts. It should contain subdirectories named
revert, and (optionally)
test. These may be overridden by
--test-dir. Defaults to
sqitch --deploy-dir db/up
Path to a directory containing SQL deployment scripts. Overrides the value implied by
sqitch --revert-dir db/up
Path to a directory containing SQL reversion scripts. Overrides the value implied by
sqitch --test-dir db/t
Path to a directory containing SQL test scripts. Overrides the value implied by
sqitch --extension ddl
The file name extension on deployment, reversion, and test SQL scripts. Defaults to
Print out the path to the Sqitch etc directory and exit. This is the directory where the system-wide configuration file lives, as well as deployment script templates.
Suppress normal output messages. Error messages will still be emitted to
STDERR. Overrides any value specified by
sqitch --verbose --verbose
A value between 0 and 3 specifying how verbose Sqitch should be. Unless
--quiet is specified, the default is 1, meaning that Sqitch will output basic status messages as it does its thing. Values of 2 and 3 each cause greater verbosity. Ignored if
--quiet is specified.
Outputs a brief description of the options supported by
sqitch and exits.
Outputs this documentation and exits.
Outputs the program name and version and exits.
Create the plan file and directories for deploy, revert, and test scripts if they do not already exist. This command is useful for starting a new Sqitch project.
Output information about the current deployment state of a database, including the name of the last deployed change, as well as any tags applied to it. If any changes in the plan have not been deployed, they will be listed separately.
Search and Output the complete change history of a database. Provides information about when changes were deployed, reverted, or failed, as well as who planned and committed the changes, and when.
*Not yet implemented.
Search and output the list of changes in the plan.
*Not yet implemented.
Sanity check the deployment scripts. Checks include:
Add a new change.
List tags or tag the latest change.
Rework an existing change.
*Not yet implemented.
Test changes. All SQL scripts in
--test-dir will be run. [XXX Not sure whether to have subdirectories for tests and expected output and to diff them, or to use some other approach.]
Get and set project, user, or system Sqitch options.
Bundle a Sqitch project for distribution. This command copies the Sqitch configuration, plan, and deploy, revert, and test scripts to a directory, so that it can be packaged up for distribution, such as in an RPM or tarball.
Show help for a specific command or, if no command is specified, show the same documentation as
Sqitch configuration can be set up on a project, user, or system-wide basis. The format of the configuration file, named sqitch.conf, is the same as for git.
Here's an example of a configuration file that might be useful checked into a VCS for a project that deploys to PostgreSQL and stores its deployment scripts with the extension ddl under the
migrations directory. It also wants bundle to be created in the _build/sql directory, and to deploy starting with the "gamma" tag:
[core] engine = pg top_dir = migrations extension = ddl [core "pg"] db_name = widgetopolis [revert] to = gamma [bundle] from = gamma tags_only = yes dest_dir = _build/sql
And here's an example of useful configuration in ~/.sqitch/sqitch.conf, to point to system-specific engine information:
[user] name = Marge N. O’Vera email = firstname.lastname@example.org [core "pg"] client = /usr/local/pgsql/bin/psql username = theory [core.mysql] client = /usr/local/mysql/bin/mysql username = root [core.sqlite] client = /usr/local/bin/sqlite3
Various commands read from the configuration file and adjust their operation accordingly. See sqitch-config for a list.
The original design for Sqitch was sketched out in a number of blog posts:
Other tools that do database change management include:
Numbered migrations for Ruby on Rails.
Numbered changes in pure SQL, integrated with Perl's Module::Build build system. Does not support reversion.
Numbered migrations in pure SQL.
PostgreSQL-specific dependency-tracking solution by depesz.
David E. Wheeler <email@example.com>
Copyright (c) 2012 iovation Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.