Pg::DatabaseManager::TestMigrations - Test your database migrations
version 0.05
use Pg::DatabaseManager::TestMigrations qw( test_migrations ); use Test::More; test_migrations( min_version => 3, max_version => 6, sql_file_pattern => 't/schemas/MyApp.sql.v%{version}', ); done_testing();
This module provides a single exportable subroutine for testing migrations.
This module provides one exportable subroutine, test_migrations:
test_migrations
This subroutine will test your migrations. It requires a number of parameters:
min_version
The minimum database version to test. Required.
max_version
The maximum database version to test. Required.
sql_file_pattern
This should be a string that contains the pattern "%{version}, for example something like "path/to/schemas/MyApp.sql.v%{version}".
Internally, the code will replace "%{version}" with each version number to find the appropriate sql file.
Required.
class
This is the database manager class to use. This defaults to Pg::DatabaseManager, but you can use your own subclass if needed.
db_name
The database name to use when testing migrations. This defaults to "MigrationTest" but you can use any version you like.
You can also pass any parameter that the database manager class accepts, such as username, password, db_encoding, etc.
username
password
db_encoding
The tests are done by creating each version of the database from scratch, using the appropriate SQL file, then dumping the resulting database with pg_dump. Then the code recreates each version and runs the migrations from that version to the max version, comparing the output of pg_dump after each migration.
It uses Test::Differences to compare the dumped databases.
See Pg::DatabaseManager for details on reporting bugs.
Dave Rolsky <autarch@urth.org>
This software is Copyright (c) 2011 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Pg::DatabaseManager, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pg::DatabaseManager
CPAN shell
perl -MCPAN -e shell install Pg::DatabaseManager
For more information on module installation, please visit the detailed CPAN module installation guide.