Name
App::Sqitch::Target - Sqitch deployment target
Synopsis
my $plan = App::Sqitch::Target->new(
sqitch => $sqitch,
name => 'development',
);
$target->engine->deploy;
Description
App::Sqitch::Target provides collects, in one place, the engine, plan, and file locations required to carry out Sqitch commands. All commands should instantiate a target to work with the plan or database.
Interface
Constructors
new
my $target = App::Sqitch::Target->new( sqitch => $sqitch );
Instantiates and returns an App::Sqitch::Target object. The most important parameters are sqitch
, name
, and uri
. The constructor tries really hard to figure out the proper name and URI during construction. If the uri
parameter is passed, this is straight-forward: if no name
is passed, name
will be set to the stringified format of the URI (minus the password, if present).
Otherwise, when no URI is passed, the name and URI are determined by taking the following steps:
If there is no name, get the engine key from
--engine
or thecore.engine
configuration option. If no key can be determined, an exception will be thrown.Use the key to look up the target name in the
engine.$engine.target
configuration option. If none is found, usedb:$key:
.If the name contains a colon (
:
), assume it is also the value for the URI.Otherwise, it should be the name of a configured target, so look for a URI in the
target.$name.uri
configuration option.
As a general rule, then, pass either a target name or URI string in the name
parameter, and Sqitch will do its best to find all the relevant target information. And if there is no name or URI, it will try to construct a reasonable default from the command-line options or engine configuration.
all_targets
Returns a list of all the targets defined by the local Sqitch configuration file. Done by examining the configuration object to find all defined targets and engines, as well as the default "core" target. Duplicates are removed and the list returned. This method takes two parameters:
sqitch
An App::Sqitch object. Required.
config
An App::Sqitch::Config object. If not passed, the object stored in the Sqitch object's
config
attribute will be used.
Accessors
sqitch
my $sqitch = $target->sqitch;
Returns the App::Sqitch object that instantiated the target.
name
target
my $name = $target->name;
$name = $target->target;
The name of the target. If there was no name specified, the URI will be used (minus the password, if there is one).
uri
my $uri = $target->uri;
The URI::db object encapsulating the database connection information.
username
my $username = $target->username;
Returns the target username, if any. The username is looked up from the URI.
password
my $password = $target->password;
Returns the target password, if any. The password is looked up from the URI or the $SQITCH_PASSWORD
environment variable.
engine
my $engine = $target->engine;
A App::Sqitch::Engine object to use for database interactions with the target.
registry
my $registry = $target->registry;
The name of the registry used by the database. The value comes from one of these options, searched in this order:
--registry
target.$name.registry
engine.$engine.registry
core.registry
Engine-specific default
client
my $client = $target->client;
Path to the engine command-line client. The value comes from one of these options, searched in this order:
--client
target.$name.client
engine.$engine.client
core.client
Engine-and-OS-specific default
top_dir
my $top_dir = $target->top_dir;
The path to the top directory of the project. This directory generally contains the plan file and subdirectories for deploy, revert, and verify scripts. The value comes from one of these options, searched in this order:
--top-dir
target.$name.top_dir
engine.$engine.top_dir
core.top_dir
.
plan_file
my $plan_file = $target->plan_file;
The path to the plan file. The value comes from one of these options, searched in this order:
--plan-file
target.$name.plan_file
engine.$engine.plan_file
core.plan_file
$top_dir
/sqitch.plan
deploy_dir
my $deploy_dir = $target->deploy_dir;
The path to the deploy directory of the project. This directory contains all of the deploy scripts referenced by changes in the plan_file
. The value comes from one of these options, searched in this order:
--dir deploy_dir=$deploy_dir
target.$name.deploy_dir
engine.$engine.deploy_dir
core.deploy_dir
$top_dir/deploy
revert_dir
my $revert_dir = $target->revert_dir;
The path to the revert directory of the project. This directory contains all of the revert scripts referenced by changes the plan_file
. The value comes from one of these options, searched in this order:
--dir revert_dir=$revert_dir
target.$name.revert_dir
engine.$engine.revert_dir
core.revert_dir
$top_dir/revert
verify_dir
my $verify_dir = $target->verify_dir;
The path to the verify directory of the project. This directory contains all of the verify scripts referenced by changes in the plan_file
. The value comes from one of these options, searched in this order:
--dir verify_dir=$verify_dir
target.$name.verify_dir
engine.$engine.verify_dir
core.verify_dir
$top_dir/verify
reworked_dir
my $reworked_dir = $target->reworked_dir;
The path to the reworked directory of the project. This directory contains subdirectories for reworked deploy, revert, and verify scripts. The value comes from one of these options, searched in this order:
--dir reworked_dir=$reworked_dir
target.$name.reworked_dir
engine.$engine.reworked_dir
core.reworked_dir
$top_dir
reworked_deploy_dir
my $reworked_deploy_dir = $target->reworked_deploy_dir;
The path to the reworked deploy directory of the project. This directory contains all of the reworked deploy scripts referenced by changes in the plan_file
. The value comes from one of these options, searched in this order:
--dir reworked_deploy_dir=$reworked_deploy_dir
target.$name.reworked_deploy_dir
engine.$engine.reworked_deploy_dir
core.reworked_deploy_dir
$reworked_dir/reworked_deploy
reworked_revert_dir
my $reworked_revert_dir = $target->reworked_revert_dir;
The path to the reworked revert directory of the project. This directory contains all of the reworked revert scripts referenced by changes the plan_file
. The value comes from one of these options, searched in this order:
--dir reworked_revert_dir=$reworked_revert_dir
target.$name.reworked_revert_dir
engine.$engine.reworked_revert_dir
core.reworked_revert_dir
$reworked_dir/reworked_revert
reworked_verify_dir
my $reworked_verify_dir = $target->reworked_verify_dir;
The path to the reworked verify directory of the project. This directory contains all of the reworked verify scripts referenced by changes in the plan_file
. The value comes from one of these options, searched in this order:
--dir reworked_verify_dir=$reworked_verify_dir
target.$name.reworked_verify_dir
engine.$engine.reworked_verify_dir
core.reworked_verify_dir
$reworked_dir/reworked_verify
extension
my $extension = $target->extension;
The file name extension to append to change names to create script file names. The value comes from one of these options, searched in this order:
--extension
target.$name.extension
engine.$engine.extension
core.extension
"sql"
engine_key
my $key = $target->engine_key;
The key defining which engine to use. This value defines the class loaded by engine
. Convenience method for $target->uri->canonical_engine
.
dsn
my $dsn = $target->dsn;
The DSN to use when connecting to the target via the DBI. Convenience method for $target->uri->dbi_dsn
.
username
my $username = $target->username;
The username to use when connecting to the target via the DBI. Convenience method for $target->uri->user
.
password
my $password = $target->password;
The password to use when connecting to the target via the DBI. Convenience method for $target->uri->password
.
See Also
- sqitch
-
The Sqitch command-line client.
Author
David E. Wheeler <david@justatheory.com>
License
Copyright (c) 2012-2015 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.