DBIx::SimpleMigration - extremely simple DBI migrations
This is a very simple module to simplify schema updates in a larger application. This will scan a directory of SQL files and execute them on a supplied DBI handle. Files are executed in order and inside transactions for safety. The module will create a table to track progress so new releases can add migrations as a SQL file and this will only deploy what is required.
Be sure this is the right tool for you. This is incredibly simple and doesn't have any verification or rollback capabilities. Before you use this, look at App::Sqitch or DBIx::Class::Migration as they're probably better choices.
use DBI; use DBIx::SimpleMigration; my $dbh = DBI->connect(...); my $migration = DBIx::SimpleMigration->new( source => './sql/', dbh => $dbh ); eval { $migration->apply }; if ($@) { # some error happened }
DBIx::SimpleMigration will die on error so if that's unacceptable for your use case, make sure to wrap in an eval.
eval
I primarily use PostgreSQL so that's the driver getting the most attention. Happy to take suggestions but if you're using another DBI driver and want locking or better support, feel free to create a ::Client::$driver package and send over a PR.
Questions, bugs, feedback are all welcome. Just create an issue under this project.
Cameron Daniel <cam.daniel@gmail.com>
To install DBIx::SimpleMigration, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::SimpleMigration
CPAN shell
perl -MCPAN -e shell install DBIx::SimpleMigration
For more information on module installation, please visit the detailed CPAN module installation guide.