DBIx-Schema-Migration

 view release on metacpan or  search on metacpan

lib/DBIx/Schema/Migration.pm  view on Meta::CPAN


=head2 DANCER2

The main idea behind this module is the creation of simple commands 
for the cli, as well as easy integration with large applications.

It can be used with dancer easily, just create migration.pl in your
app root and put this code inside:

    use Dancer2;
    use Dancer2::Plugin::Database;
    use DBIx::Schema::Migration;

    my $dir = config->{migrations}->{directory};

    # Instantinating Migration object.
    my $migration = DBIx::Schema::Migration->new( {
        dbh => database,
        dir => $dir,
    } );

    # CLI logic.
    my ($action, $num) = @ARGV;

    SWITCH: for ($action) { 
        if (/up/)   { $migration->up($num);   last SWITCH; }
        if (/down/) { $migration->down($num); last SWITCH; }
        if (/init/) { $migration->init();     last SWITCH; }
    }

Now you can run migrations simply:

    perl migration.pl up
    perl migration.pl down
    perl migration.pl init

=head2 CONFIGURATION

=over 4

=item dbh

Database handler.

=item dir 

Path to migrations directory, full or relative.

=back

=head2 METHODS

=head3 up($num)

Will apply $num migrations or all of them if $num is not specified.

=head3 down($num)

Will reverse $num migrations or all of them if $num is not specified.

=head1 BUGS AND LIMITATIONS

If you find one, please let me know.

=head1 SOURCE CODE REPOSITORY

https://github.com/AlexP007/DBIx-Schema-Migration - fork or add pr.

=head1 AUTHOR

Alexander Panteleev <alexpan at cpan dot org>.

=head1 LICENSE AND COPYRIGHT

This software is copyright (c) 2021 by Alexander Panteleev.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 1.524 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )