DBIx-Class-Migration
view release on metacpan or search on metacpan
lib/DBIx/Class/Migration.pm view on Meta::CPAN
=head3 OPTIONAL: Specify dbic_dh_args
Optionally, you can specify additional arguments to the constructor for the
L</dbic_dh> attribute. Useful arguments might include additional C<databases>
we should build fixtures for, C<to_version> and C<force_overwrite>.
See L<DBIx::Class::DeploymentHandler/> for more information on supported init
arguments. See L</dbic_dh> for how we merge default arguments with your custom
arguments.
=head3 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.
=head2 version
Prints to STDOUT a message regarding the version of L<DBIC:Migration> that you
are currently running.
=head2 status
Returns the state of the deployed database (if it is deployed) and the state
of the current C<schema> version. Sends this as a string to STDOUT
=head2 prepare
Creates a C<fixtures> and C<migrations> directory under L</target_dir> (if they
don't already exist) and makes deployment files for the current schema. If
deployment files exist, will fail unless you L</overwrite_migrations>.
The C<migrations> directory reflects a directory structure as documented in
L<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.
=head2 install
Installs either the current schema version (if already prepared) or the target
version specified via any C<to_version> flags sent as an L<dbic_dh_args> to the
database which is connected via L</schema>.
If you try to install to a database that has already been installed, you'll get
an error. See L</drop_tables>.
=head2 upgrade
Run upgrade files to bring the database into sync with the current schema
version.
=head2 downgrade
Run down files to bring the database down to the previous version from what is
installed to the database
=head2 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).
=head2 delete_table_rows
Does a C<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.
=head2 dump_named_sets
Given an array of fixture set names, dump them for the current database version.
=head2 dump_all_sets
Takes no arguments just dumps all the sets we can find for the current database
version.
=head2 make_schema
Given an existing database, reverse engineer a L<DBIx::Class> Schema in the
L</target_dir> (under C<dumped_db>). You can use this if you need to bootstrap
your DBIC files.
=head2 populate
Given an array of fixture set names, populate the current database version with
the matching sets for that version.
Skips the table C<dbix_class_deploymenthandler_versions>, so you don't lose
deployment info (this is different from L</drop_tables> which does delete it.)
=head2 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 L</target_dir> called C<db-diagram-vXXX.png> where C<XXX> is he current
C<schema> version.
This is using the Graphviz producer (L<SQL::Translator::Producer::GraphViz>)
which in turn requires L<Graphviz>. Since this is not always trivial to
install, I do not require it. You will need to add it manually to your
C<Makefile.PL> or C<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 L<DBIx::Class::Migration>. Consider this command a 'freebee' and
please don't depend on it in your custom code.
=head2 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 0.563 second using v1.01-cache-2.11-cpan-437f7b0c052 )