Name

App::Sqitch::Engine - Sqitch Deployment Engine

Synopsis

my $engine = App::Sqitch::Engine->new( sqitch => $sqitch );

Description

App::Sqitch::Engine provides the base class for all Sqitch storage engines. Most likely this will not be of much interest to you unless you are hacking on the engine code.

Interface

Class Methods

config_vars

my %vars = App::Sqitch::Engine->config_vars;

Returns a hash of names and types to use for configuration variables for the engine. These can be set under the core.$engine_name section in any configuration file.

The keys in the returned hash are the names of the variables. The values are the data types. Valid data types include:

any
int
num
bool
bool-or-int

Values ending in + (a plus sign) may be specified multiple times. Example:

(
    client  => 'any',
    db_name => 'any',
    host    => 'any',
    port    => 'int',
    set     => 'any+',
)

In this example, the port variable will be stored and retrieved as an integer. The set variable may be of any type and may be included multiple times. All the other variables may be of any type.

By default, App::Sqitch::Engine returns an empty list. Subclasses for supported engines will return more.

Constructors

load

my $cmd = App::Sqitch::Engine->load(%params);

A factory method for instantiating Sqitch engines. It loads the subclass for the specified engine and calls new, passing the Sqitch object. Supported parameters are:

sqitch

The App::Sqitch object driving the whole thing.

new

my $engine = App::Sqitch::Engine->new(%params);

Instantiates and returns a App::Sqitch::Engine object.

Instance Methods

name

my $name = $engine->name;

The name of the engine. Defaults to the last part of the package name, so as a rule you should not need to override it, since it is that string that Sqitch uses to find the engine class.

target

my $target = $engine->target;

Returns the name of the target database. This will usually be the same as the configured database name or the value of the --db-name option. Hover, subclasses may override it to provide other values, such as when neither of the above have values but there is nevertheless a default value assumed by the engine. Used internally by deploy() and revert() in status messages.

deploy

$engine->deploy($tag);

Deploys the App::Sqitch::Plan::Tag to the database, including all of its associated steps.

deploy_step

$engine->deploy_step($step);

Used internally by deploy() to deploy an individual step.

revert

$engine->revert($tag);

Reverts the App::Sqitch::Plan::Tag from the database, including all of its associated steps.

revert_step

$engine->revert_step($step);

Used internally by revert() (and, by deploy() when a deploy fails) to revert an individual step.

is_deployed

say "Tag deployed"  if $engine->is_deployed($tag);
say "Step deployed" if $engine->is_deployed($step);

Convenience method that dispatches to is_deployed_tag() or is_deployed_step() as appropriate to its argument.

Abstract Instance Methods

These methods must be overridden in subclasses.

initialized

$engine->initialize unless $engine->initialized;

Returns true if the database has been initialized for Sqitch, and false if it has not.

initialize

$engine->initialize;

Initializes a database for Sqitch by installing the Sqitch metadata schema and/or tables. Should be overridden by subclasses. This implementation throws an exception

is_deployed_tag

say "Tag deployed"  if $engine->is_deployed_tag($tag);

Should return true if the tag has been deployed to the database, and false if it has not.

is_deployed_step

say "Step deployed"  if $engine->is_deployed_step($step);

Should return true if the step has been deployed to the database, and false if it has not.

begin_deploy_tag

$engine->begin_deploy_tag($tag);

Start deploying the tag. The engine may need to write the tag to the database, create locks to control the deployment, etc.

commit_deploy_tag

$engine->commit_deploy_tag($tag);

Commit a tag deployment. The engine should clean up anything started in begin_deploy_tag().

rollback_deploy_tag

$engine->rollback_deploy_tag($tag);

Roll back a tag deployment. The engine should remove the tag record and commit its changes.

log_deploy_step

$engine->log_deploy_step($step);

Should write to the database metadata and history the records necessary to indicate that the step has been deployed.

log_fail_step

$engine->log_fail_step($step);

Should write to the database event history a record reflecting that deployment of the step failed.

begin_revert_tag

$engine->begin_revert_tag($tag);

Start reverting the tag. The engine may need to update the database, create locks to control the reversion, etc.

commit_revert_tag

$engine->commit_revert_tag($tag);

Commit a tag reversion. The engine should clean up anything started in begin_revert_tag().

log_revert_step

$engine->log_revert_step($step);

Should write to and/or remove from the database metadata and history the records necessary to indicate that the step has been reverted.

check_requires

if ( my @requires = $engine->requires($step) ) {
    die "Step requires undeployed steps: @requires\n";
}

Returns the names of any steps required by the specified step that are not currently deployed to the database. If none are returned, the requirements are presumed to be satisfied.

check_conflicts

if ( my @conflicts = $engine->conflicts($step) ) {
    die "Step conflicts with previously deployed steps: @conflicts\n";
}

Returns the names of any currently-deployed steps that conflict with specified step. If none are returned, there are presumed to be no conflicts.

If any of the steps that conflict with the specified step have been deployed to the database, their names should be returned by this method. If no names are returned, it's because there are no conflicts.

current_tag_name

my $tag_name $engine->current_tag_name;

Returns one tag name from the most recently deployed tag.

run_file

$engine->run_file($file);

Should execute the commands in the specified file. This will generally be an SQL file to run through the engine's native client.

run_handle

$engine->run_handle($file_handle);

Should execute the commands in the specified file handle. The file handle's contents should be piped to the engine's native client.

deployed_steps_for

my @steps = $engine->deployed_steps_for($tag);

Should return a list of steps currently deployed to the database for the specified tag, in an order appropriate to satisfy dependencies.

See Also

sqitch

The Sqitch command-line client.

Author

David E. Wheeler <david@justatheory.com>

License

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.