Dave Rolsky

NAME

Pg::DatabaseManager::TestMigrations - Test your database migrations

VERSION

version 0.06

SYNOPSIS

  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();

DESCRIPTION

This module provides a single exportable subroutine for testing migrations.

SUBROUTINES

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.

HOW IT WORKS

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.

BUGS

See Pg::DatabaseManager for details on reporting bugs.

AUTHOR

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2011 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)