NAME

DBIx::VersionedSchema - helps to manage database schema versions

SYNOPSIS

package MyVersions;
use base 'DBIx::VersionedSchema';

# Set the name of the table
__PACKAGE__->Name('my_schema_versions');

# Add first version
__PACKAGE__->add_version(sub {
	my $dbh = shift;
	$dbh->do(...);
});

# Add another one
__PACKAGE__->add_version(...);

package main;

my $vs = MyVersions->new($dbh);

# recreates / adds versions
$vs->run_updates;

DESCRIPTION

This module helps to evolve database schema in small increments called schema versions henceforth.

Each of those versions is perl function that you pass to add_version function. Those versions are replayed by calling run_updates function.

DBIx::VersionedSchema keeps track of applied versions by using database table. You should provide the name of this table by using Name property of your inheriting class.

The tracking table will be created on the first call to run_updates function.

METHODS

Name

This is per class method. It should be used to set the name of the tracking table.

add_version(function)

Adds another schema version as perl function. This function will run during run_updates call. Database handle will be provided to the function as an argument.

new(dbh)

Creates new instance. $dbh is the database handle which will be passed down to the schema changing functions.

current_version

Returns current schema version. Returns undef if no version tracking table has been found. Returns 0 if the table exists but no updates have been run yet.

run_updates

Runs the updates starting from the current schema version.

AUTHOR

Boris Sukholitko
boriss@gmail.com

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

Test::TempDatabase - for creation of temporary databases.