NAME

DB::SQL::Migrations::Advanced - apply/rollback migrations from a directory

SYNOPSIS

    use DB::SQL::Migrations::Advanced;
    my $migrator = DB::SQL::Migrations::Advanced->new(
        dbh     => $some_db_handle,
        folder  => $some_path,
    );

    $migrator->run;

    use DB::SQL::Migrations::Advanced;
    my $migrator = DB::SQL::Migrations::Advanced->new(
        dbh         => $some_db_handle,
        folder      => $some_path,
        rollback    => 1,
        steps       => 3,
    );

    $migrator->run;

DESCRIPTION

DB::SQL::Migrations::Advanced provides a nice way to apply migrations from a directory. It has the ability to also rollback migrations.

ATTRIBUTES

DB::SQL::Migrations::Advanced inherits all attributes from Mojo::Base and implements the following new ones.

applied_migrations

    Tell list of already applied migrations.

batch

    Tell value for the last batch of migrations.

dbh

    A database handler. (required)

folder

    Tell name of the folder that holds the migration files.
    Defaults to 'db_migrations'.

migration_files_in_order

    Migration files in alphabetical order.

pending_migrations

    Migrations that needs to be applied.

rollback

    Tell if you are looking to rollback some migrations.
    Defaults to 0.

steps

    In case you are looking to rollback mirations, you can specify how many steps.
    Defaults to 1.

table

    The name of the table that records the applied migrations.
    Defaults to 'schema_migrations'.

METHODS

DB::SQL::Migrations::Advanced inherits all methods from Mojo::Base and implements the following new ones.

apply

    $migrator->apply

Apply all pending migrations.

create_migrations_table

    $migrator->create_migrations_table

Create migrations table if not exists.

revert

    $migrator->revert

Revert migrations.

run

    $migrator->run

Run migrations. Will decide if it needs to apply/rollback based on given attributes.

_insert_into_schema_migrations

    $migrator->_insert_into_schema_migrations($filename)

Record migration filename as being applied.

_migration_key

    my $migration_key = $migrator->_migration_key($filename)

Retrieve the migration_key for a filename.

_revert_migration

    $migrator->_revert_migration($filename)

Revert migrations from filename.

_remove_from_schema_migrations

    $migrator->_remove_from_schema_migrations($filename)

Remove migration filename from table.

_run_migration

    $migrator->_run_migration($sql)

Run an sql.

_sql

    my $sql = $migrator->_sql($filename)

Retrieve the sql that needs to be run from a migration filename, based on apply/rollback.

AUTHOR

Adrian Crisan, <adrian.crisan88@gmail.com>