View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Thomas Klausner > DBIx-SchemaChecksum-0.25 > DBIx::SchemaChecksum



Annotate this POD

View/Report Bugs
Module Version: 0.25   Source   Latest Release: DBIx-SchemaChecksum-1.102


DBIx::SchemaChecksum - Generate and compare checksums of database schematas


    my $sc = DBIx::SchemaChecksum->new( dsn => 'dbi:Pg:name=foo' );
    print $sc->checksum;


When you're dealing with several instances of the same database (eg. developer, testing, stage, production), it is crucial to make sure that all databases use the same schema. This can be quite an hair-pulling experience, and this module should help you keep your hair (if you're already bald, it won't make your hair grow back, sorry...)

DBIx::SchemaChecksum connects to your database, gets schema information (tables, columns, primary keys, foreign keys) and generates a SHA1 digest. This digest can then be used to easily verify schema consistency across different databases.

Caveat: The same schema might produce different checksums on different database versions.

DBIx::SchemaChecksum works with PostgreSQL 8.3 and SQLite (but see below). I assume that thanks to the abstraction provided by the DBI it works with most databases. If you try DBIx::SchemaChecksum with different database systems, I'd love to hear some feedback...

SQLite and column_info

DBD::SQLite doesn't really implement column_info, which is needed to generate the checksum. We use the monkey-patch included in to make it work


Please take a look at the scripts included in this distribution:

Calculates the checksum and prints it to STDOUT

Updates a schema based on the current checksum and SQL snippet files


Public Methods


Moose Object Builder which sets up the DB connection.


    my $checksum = $sc->checksum;

Return the checksum (as a SHA1 digest)


    my $schemadump = $self->schemadump;

Returns a string representation of the whole schema (as a Data::Dumper Dump).


    $self->apply_sql_snippets( $starting_checksum );

Applies SQL snippets in the correct order to the DB. Checks if the checksum after applying the snippets is correct. If it isn't correct rolls back the last change (if your DB supports transactions...)


    my $update_info = $self->build_update_path( '/path/to/sql/snippets' )

Builds the datastructure needed by apply_sql_update. build_update_path reads in all files ending in ".sql" in the directory passed in (or defaulting to $self->sqlsnippetdir). It builds something like a linked list of files, which are chained by their preSHA1sum and postSHA1sum.


    my ($pre, $post) = $self->get_checksums_from_snippet( $file );

Returns a list of the preSHA1sum and postSHA1sum for the given file.

The file has to contain this info in SQL comments, eg:

  -- preSHA1sum: 89049e457886a86886a4fdf1f905b69250a8236c
  -- postSHA1sum: d9a02517255045167053ea92dace728e1389f8ca

  alter table foo add column bar;

Attributes generated by Moose

All of this methods can also be set from the commandline. See MooseX::Getopts.


The database handle (DBH::db).


The dsn.


The user to use to connect to the DB.


The password to use to authenticate the user.


The database catalog searched for data. Not implemented by all DBs. See DBI::table_info

Default %.


An Arrayref containg names of schematas to include in checksum calculation. See DBI::table_info

Default %.


What kind of tables to include in checksum calculation. See DBI::table_info

Default table.


Be verbose or not. Default: 0


Thomas Klausner, <domm at>


Please report any bugs or feature requests to bug-dbix-schemachecksum at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc DBIx::SchemaChecksum

You can also look for information at:


Thanks to Klaus Ita and Armin Schreger for writing the core code. I just glued it together...

This module was written for revdev, a nice litte software company run by Koki, Domm ( and Maros (


Copyright 2008 Thomas Klausner,, all rights reserved.

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.

syntax highlighting: