Thomas Klausner > DBIx-SchemaChecksum-1.001 > DBIx::SchemaChecksum

Download:
DBIx-SchemaChecksum-1.001.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.001   Source   Latest Release: DBIx-SchemaChecksum-1.005

NAME ^

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

VERSION ^

version 1.001

SYNOPSIS ^

    my $sc = DBIx::SchemaChecksum->new( dbh => $dbh );
    print $sc->checksum;

DESCRIPTION ^

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 gets schema information (tables, columns, primary keys, foreign keys and some more depending on your DBD) 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 is tested with PostgreSQL 8.3 to 9.1 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...

Scripts

Please take a look at the "scs" in bin script included in this distribution.

NAME ^

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

METHODS ^

Public Methods

schemadump

    my $schemadump = $self->schemadump;

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

build_update_path

    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.

get_checksums_from_snippet

    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;

dbh

Reas/set database handle (DBH::db).

catalog

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

Default %.

schemata

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

Default %.

sqlsnippetdir

Path to the directory where the sql change files are stored.

verbose

Be verbose or not. Default: 0

ACKNOWLEDGEMENTS ^

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

This module was written for revdev http://www.revdev.at, a nice litte software company run by Koki, Domm (http://search.cpan.org/~domm/) and Maros (http://search.cpan.org/~maros/).

AUTHORS ^

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2012 by Thomas Klausner, Maroš Kollár, Klaus Ita.

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

syntax highlighting: