=head1 Name

sqitch-rebase - Revert and redeploy database changes

=head1 Synopsis

  sqitch rebase [options] [<database>]
  sqitch rebase [options] [<database>] --onto-change <change>
  sqitch rebase [options] [<database>] --onto-change <change> --upto-change <change>
  sqitch rebase [options] [<database>] <change>
  sqitch rebase [options] [<database>] <change> --upto-change <change>
  sqitch rebase [options] [<database>] <change> <change>

=head1 Description

Revert and redeploy changes to the database. It's effectively a shortcut for
running L<C<sqitch revert>|sqitch-revert> and L<C<sqitch deploy>|sqitch-deploy>
in succession.

More specifically, starting from the current deployment state, changes will be
reverted in reverse the order of application. All changes will be reverted
unless a change is specified, either via C<--onto> or with no option flag, in
which case changes will be reverted back to that change. If nothing needs to
be reverted, a message will be emitted explaining why and nothing will be
reverted.

Once the revert finishes, changes will be deployed starting from the deployed
state through the rest of the deployment plan. They will run to the latest
change in the plan, unless a change is specified, either via C<--upto> or with
no option flag, in which case changes will be deployed up-to and including
that change.

If the database has not been deployed to, or its state already matches the
specified change, no reverts will be run. And if, at that point, the database
is up-to-date, no deploys will be run.

The C<< <database> >> parameter specifies the database to which to connect,
and may also be specified as the C<--target> option. It can be target name,
a URI, an engine name, or plan file path.

=head1 Options

=over

=item C<-t>

=item C<--target>

The target database to which to connect. This option can be either a URI or
the name of a target in the configuration.

=item C<--onto-change>

=item C<--onto>

Specify the reversion change. Defaults to reverting all changes. See
L<sqitchchanges> for the various ways in which changes can be specified.

=item C<--upto-change>

=item C<--upto>

Specify the deployment change. Defaults to the last point in the plan. See
L<sqitchchanges> for the various ways in which changes can be specified.

=item C<--mode>

Specify the reversion mode to use in case of deploy failure. Possible values
are:

=over

=item C<all>

In the event of failure, revert all deployed changes, back to
C<--onto-change>. This is the default.

=item C<tag>

In the event of failure, revert all deployed changes to the last
successfully-applied tag. If no tags were applied, all changes will be
reverted to C<--onto-change>.

=item C<change>

In the event of failure, no changes will be reverted. This is on the
assumption that a change is atomic, and thus may may be deployed again.

=back

=item C<--verify>

Verify each change by running its verify script, if there is one, immediate
after deploying it. If a verify test fails, the deploy will be considered to
have failed and the appropriate reversion will be carried out, depending on
the value of C<--mode>.

=item C<--no-verify>

Don't verify each change. This is the default.

=item C<-s>

=item C<--set>

Set a variable name and value for use by the database engine client, if it
supports variables. The format must be C<name=value>, e.g.,
C<--set defuser='Homer Simpson'>. Overrides any values loaded from
L</configuration Variables>.

=item C<-e>

=item C<--set-deploy>

Set a variable name and value for use by the database engine client when
deploying, if it supports variables. The format must be C<name=value>, e.g.,
C<--set defuser='Homer Simpson'>. Overrides any values from C<--set> or values
loaded from L</configuration Variables>.

=item C<-r>

=item C<--set-revert>

Sets a variable name to be used by the database engine client during when
reverting, if it supports variables. The format must be C<name=value>, e.g.,
C<--set defuser='Homer Simpson'>. Overrides any values from C<--set> or values
loaded from L</configuration Variables>.

=item C<--log-only>

Log the changes as if they were deployed and reverted, but without actually
running the deploy and revert scripts.

=item C<-y>

Disable the prompt that normally asks whether or not to execute the revert.

=item C<--registry>

  sqitch rebase --registry registry

The name of the Sqitch registry schema or database in which sqitch stores its
own data.

=item C<--db-client>

=item C<--client>

  sqitch rebase --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 database engine.

=item C<-d>

=item C<--db-name>

  sqitch rebase --db-name widgets
  sqitch rebase -d bricolage

Name of the database. In general, L<targets|sqitch-target> and URIs are
preferred, but this option can be used to override the database name in a
target.

=item C<-u>

=item C<--db-user>

=item C<--db-username>

  sqitch rebase --db-username root
  sqitch rebase --db-user postgres
  sqitch rebase -u Mom

User name to use when connecting to the database. Does not apply to all
engines. In general, L<targets|sqitch-target> and URIs are preferred, but this
option can be used to override the user name in a target.

=item C<-h>

=item C<--db-host>

  sqitch rebase --db-host db.example.com
  sqitch rebase -h appdb.example.net

Host name to use when connecting to the database. Does not apply to all
engines. In general, L<targets|sqitch-target> and URIs are preferred, but this
option can be used to override the host name in a target.

=item C<-p>

=item C<--db-port>

  sqitch rebase --db-port 7654
  sqitch rebase -p 5431

Port number to connect to. Does not apply to all engines. In general,
L<targets|sqitch-target> and URIs are preferred, but this option can be used
to override the port in a target.

=item C<--plan-file>

=item C<-f>

  sqitch rebase --plan-file my.plan

Path to the deployment plan file. Overrides target, engine, and core
configuration values. Defaults to F<$top_dir/sqitch.plan>.

=back

=head1 Configuration Variables

=over

=item C<[deploy.variables]>

=item C<[revert.variables]>

A section defining database client variables. These variables are useful if
your database engine supports variables in scripts, such as PostgreSQL's
L<C<psql>
variables|https://www.postgresql.org/docs/current/static/app-psql.html#APP-PSQL-INTERPOLATION>,
Vertica's L<C<vsql>
variables|https://my.vertica.com/docs/7.1.x/HTML/index.htm#Authoring/ConnectingToHPVertica/vsql/Variables.htm>,
MySQL's L<user
variables|https://dev.mysql.com/doc/refman/5.6/en/user-variables.html>,
SQL*Plus's L<C<DEFINE>
variables|https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12017.htm>,
and Snowflake's L<SnowSQL
variables|https://docs.snowflake.net/manuals/user-guide/snowsql-use.html#using-variables>.

May be overridden by C<--set>, C<--set-deploy>, C<--set-revert>, or target and
engine configuration. Variables are merged in the following priority order:

=over

=item C<--set-revert>

Used only while reverting changes.

=item C<--set-deploy>

Used only while deploying changes.

=item C<--set>

Used while reverting and deploying changes.

=item C<target.$target.variables>

Used while reverting and deploying changes.

=item C<engine.$engine.variables>

Used while reverting and deploying changes.

=item C<revert.variables>

Used only while reverting changes.

=item C<deploy.variables>

Used while reverting and deploying changes.

=item C<core.variables>

Used while reverting and deploying changes.

=back

=item C<rebase.verify>

=item C<deploy.verify>

Boolean indicating whether or not to verify each change after deploying it.

=item C<rebase.mode>

=item C<deploy.mode>

Deploy mode. The supported values are the same as for the C<--mode> option.

=item C<[rebase.no_prompt]>

=item C<[revert.no_prompt]>

A boolean value indicating whether or not to disable the prompt before
executing the revert. The C<rebase.no_prompt> variable takes precedence over
C<revert.no_prompt>, and both may of course be overridden by C<-y>.

=item C<[rebase.prompt_accept]>

=item C<[revert.prompt_accept]>

A boolean value indicating whether default reply to the prompt before
executing the revert should be "yes" or "no". The C<rebase.prompt_accept>
variable takes precedence over C<revert.prompt_accept>, and both default to
true, meaning to accept the revert by default.

=back

=head1 Sqitch

Part of the L<sqitch> suite.