++ed by:

2 PAUSE users

Dave Rolsky
and 1 contributors


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


version 0.11


  package Database::Migrator::SomeDB;

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

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


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.


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.


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.


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


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


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


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


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


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.


Dave Rolsky <autarch@urth.org>


This software is Copyright (c) 2014 by MaxMind, Inc..

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)