DBIx-Class-Migration

 view release on metacpan or  search on metacpan

README.mkdn  view on Meta::CPAN

### OPTIONAL: Specify dbic\_dh\_args

Optionally, you can specify additional arguments to the constructor for the
["dbic\_dh"](#dbic_dh) attribute.  Useful arguments might include additional `databases`
we should build fixtures for, `to_version` and `force_overwrite`.

See ["" in DBIx::Class::DeploymentHandler](https://metacpan.org/pod/DBIx::Class::DeploymentHandler) for more information on supported init
arguments.  See ["dbic\_dh"](#dbic_dh) for how we merge default arguments with your custom
arguments.

### Other Initial Arguments

For normal usage the remaining init args are probably not particularly useful
and reflect a desire for long term code flexibility and clean design.

## version

Prints to STDOUT a message regarding the version of [DBIC:Migration](DBIC:Migration) that you
are currently running.

## status

Returns the state of the deployed database (if it is deployed) and the state
of the current `schema` version.  Sends this as a string to STDOUT

## prepare

Creates a `fixtures` and `migrations` directory under ["target\_dir"](#target_dir) (if they
don't already exist) and makes deployment files for the current schema.  If
deployment files exist, will fail unless you ["overwrite\_migrations"](#overwrite_migrations).

The `migrations` directory reflects a directory structure as documented in
[DBIx::Class::DeploymentHandler](https://metacpan.org/pod/DBIx::Class::DeploymentHandler).

If this is the first version, we create directories and initial DLL, etc.  For
versions greater than 1, we will also generate diffs and copy any fixture
configs etc (as well as generating a fresh 'all\_table.json' fixture config). For
safety reasons, we never overwrite any fixture configs.

## install

Installs either the current schema version (if already prepared) or the target
version specified via any `to_version` flags sent as an [dbic\_dh\_args](https://metacpan.org/pod/dbic_dh_args) to the
database which is connected via ["schema"](#schema).

If you try to install to a database that has already been installed, you'll get
an error.  See ["drop\_tables"](#drop_tables).

## upgrade

Run upgrade files to bring the database into sync with the current schema
version.

## downgrade

Run down files to bring the database down to the previous version from what is
installed to the database

## drop\_tables

Drops all the tables in the connected database with no backup or recovery.  For
real! (Make sure you are not connected to Prod, for example).

## delete\_table\_rows

Does a `delete` on each table in the database, which clears out all your data
but preserves tables.  For Real!  You might want this if you need to load
and unload fixture sets during testing, or perhaps to get rid of data that
accumulated in the database while running an app in development, before dumping
fixtures.

## dump\_named\_sets

Given an array of fixture set names, dump them for the current database version.

## dump\_all\_sets

Takes no arguments just dumps all the sets we can find for the current database
version.

## make\_schema

Given an existing database, reverse engineer a [DBIx::Class](https://metacpan.org/pod/DBIx::Class) Schema in the
["target\_dir"](#target_dir) (under `dumped_db`).  You can use this if you need to bootstrap
your DBIC files.

## populate

Given an array of fixture set names, populate the current database version with
the matching sets for that version.

Skips the table `dbix_class_deploymenthandler_versions`, so you don't lose
deployment info (this is different from ["drop\_tables"](#drop_tables) which does delete it.)

## diagram

Experimental feature.  Although not specifically a migration task, I find it
useful to output visuals of my databases.  This command will place a file in
your ["target\_dir"](#target_dir) called `db-diagram-vXXX.png` where `XXX` is he current
`schema` version.

This is using the Graphviz producer ([SQL::Translator::Producer::GraphViz](https://metacpan.org/pod/SQL::Translator::Producer::GraphViz))
which in turn requires [Graphviz](https://metacpan.org/pod/Graphviz).  Since this is not always trivial to
install, I do not require it.  You will need to add it manually to your
`Makefile.PL` or `dist.ini` and manage it yourself.

This feature is experimental and currently does not offer any options, as I
am still determining the best way to meet the need without exceeding the
scope of [DBIx::Class::Migration](https://metacpan.org/pod/DBIx::Class::Migration).  Consider this command a 'freebee' and
please don't depend on it in your custom code.

## install\_if\_needed

If the database is not installed, do so.  Accepts a hash of callbacks or
instructions to perform should installation be needed/

    $migration->install_if_needed(
      on_install => sub {
        my ($schema, $local_migration) = @_;
        DBIx::Class::Migration::Population->new(
          schema=>shift)->populate('all_tables');



( run in 1.487 second using v1.01-cache-2.11-cpan-437f7b0c052 )