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.
Migraine
migraine_*
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:
%options
version
Specifies the version to migrate to (instead of just using the latest one)
before_migrate
after_migrate
Subroutines 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_act
Specifies that no migrations should be actually executed in the DB. The hooks will be executed, though.
skip_missing_migrations
Specifies 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.
$id
migrate
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:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of Opera Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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.
To install Migraine, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Migraine
CPAN shell
perl -MCPAN -e shell install Migraine
For more information on module installation, please visit the detailed CPAN module installation guide.