The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Database::Migrator::Core - Core role for Database::Migrator implementation classes

VERSION

version 0.14

SYNOPSIS

  package Database::Migrator::SomeDB;

  use Moose;
  with 'Database::Migrator::Core';

  sub _build_database_exists { }
  sub _build_dbh             { }
  sub _create_database       { }

DESCRIPTION

This role implements the bulk of the migration logic, leaving a few details up to DBMS-specific classes.

You can then subclass these DBMS-specific classes to provide defaults for various attributes, or to override some of the implementation.

PUBLIC ATTRIBUTES

This role defines the following public attributes. These attributes may be provided via the command line or you can set defaults for them in a subclass.

  • database

    The name of the database that will be created or migrated. This is required.

  • username, password, host, port

    These parameters are used when connecting to the database. They are all optional.

  • migration_table

    The name of the table which stores the name of applied migrations. This is required.

  • migrations_dir

    The directory containing migrations. This is required, but it is okay if the directory is empty.

  • schema_file

    The full path to the file containing the initial schema for the database. This will be used to create the database if it doesn't already exist. This is required.

  • verbose

    This affects the verbosity of output logging. Defaults to false.

  • quiet

    If this is true, then no output will logged at all. Defaults to false.

  • dry_run

    If this is true, no migrations are actually run. Instead, the code just logs what it would do. Defaults to false.

METHODS

This role provide just one public method, create_or_update_database().

It will create a new database if none exists.

It will run all unapplied migrations on this schema once it does exist.

REQUIRED METHODS

If you want to create your own implementation class, you must implement the following methods. All of these methods should throw an error

$migration->_create_database()

This should create an empty database. This role will take care of executing the DDL for defining the schema.

$migration->_driver_name()

This return a string containing the DBI driver name, such as "mysql" or "Pg".

$migration->_drop_database()

This should drop the database. Right now it is only used for testing.

$migration->_run_ddl($ddl)

Given a string containing one or more DDL statements, this method must run that DDL against the database.

OVERRIDEABLE ATTRIBUTES AND METHODS

There are a number of attributes methods in this role that you may wish to override in a custom subclass of an implementation.

For any attribute where you provide a default value, make sure to also set required => 0 as well.

  • database attribute

    You can provide a default database name.

  • username, password, host, and port attributes

    You can provide a default values for these connection attributes.

  • migration_table

    You can provide a default table name.

  • migrations_dir

    You can provide a default directory.

  • schema_file

    You can provide a default file name.

  • _build_logger()

    You must return an object with debug() and info() methods.

SUPPORT

Bugs may be submitted through https://github.com/maxmind/Database-Migrator/issues.

AUTHOR

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 - 2018 by MaxMind, Inc.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)