
Migraine - DB schema MIGRAtor that takes headache out of the game

use Migraine;
$migrator = Migraine->new($dsn);
$migrator = Migraine->new($dsn, user => 'dbuser', password => 's3kr3t');
$migrator = Migraine->new($dsn, migrations_dir => 'migrations');
$migrator->migrate; # Latest version
$migrator->migrate(version => $v); # Custom version
$migrator->migrate(before_migrate => sub {
my ($version, $path) = @_;
# ...
});
$migrator->migrate(after_migrate => sub {
my ($version, $path) = @_
# ...
});

DB schema migrator (migraine) implementation module. See migraine for more details.
To be able to know the current version of the DB schema in a given database, the Migraine module maintains certain meta information in it, in special tables called migraine_*. These tables shouldn't be deleted or modified in any way.

Returns a DB handler.
Returns if the migraine metadata is already present in the target database (needed for migraine to work).
Returns if the migraine metadata is already present in the target database, and that it's the correct format/version.
Returns the migraine metadata version for the target database.
Creates the migraine metadata in the target metadata, if it's not already there.
Upgrades the migraine metadata if it's an older version. If it doesn't exist at all, it's created. It dies if the metadata has a future version.
Returns the latest migration version in the specified migrations dir.
This method is deprecated. Now, thinking in terms of the version of the database is obsolete: now a database has a list of migrations applied to it. It returns the highest id of the applied migrations. It returns 0 if the migraine metadata is not in place.
Returns if the given migration is already applied.
Migrates the database. The valid keys for the %options hash are:
versionSpecifies the version to migrate to (instead of just using the latest one)
before_migrate, after_migrateSubroutines to be executed before and after each migration. When they are called, they are passed two parameters: the version of the migration to be/just executed, and the path for the migration file to be/just executed.
no_actSpecifies that no migrations should be actually executed in the DB. The hooks will be executed, though.
skip_missing_migrationsSpecifies that if a migration doesn't exist (or there is more than one migration with the same id or something similar) it will just be skipped instead of producing an error and stopping execution.
Applies the given migration ($id). Supports the following options: before_migrate, after_migrate, no_act and skip_missing_migrations. See the migrate documentation for details.
Returns the list of migration ids that have been already applied.
Returns a list of strings representing version ranges of applied migrations. For example, if the applied migration list is (1,2,3,8,10,11), it will return ("1-3","8","10-11").

0.54

This code is offered under the Open Source BSD license.
Copyright (c) 2009, Opera Software. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.