NAME

Module::Install::DiffCheck - Run diff commands looking for deployment problems

SYNOPSIS

Add statements like these to your Module::Install generated Makefile.PL:

diffcheck(
   before_diff_commands => [
      'Model/refresh_Schema.pl',
      'Model/mysqldump.pl root SuperSecret',
   ],
   diff_commands => [
      'svn diff --diff-cmd diff -x "-i -b -u" Model',
   ],
   ignore_lines => [
      qr/ *#/,              # Ignore comments
      qr/^\-\-/,            # Ignore comments
      qr/AUTO_INCREMENT/,   # These change all the time
   ],
);

That's it. Each before_diff_commands is executed, then each diff_commands is executed. Any diff output lines that don't match an ignore_lines regex cause a fatal error.

We use DBIx::Class::Schema::Loader, mysqldump, and Subversion, but you should be able to use any version control system, RDBMS, and ORM(s) that make you happy. And/or you could diff other files that have nothing to do with databases.

DESCRIPTION

If you use a version control system to deploy your applications you might find this module useful.

How we check our database schemas

Here, I describe the specifics of how we use this where I work, in case you find this practical example illustrative.

We commit all our database schemas into our version control system. Every time we deploy a specific release it is critical that the RDBMS schema on that server exactly matches the schema in our version control system. New tables may have been introduced, tables may have been altered, or old tables may have been removed. diffcheck() lists all errors and dies if it detects problems.

We use both DBIx::Class::Schema::Loader make_schema_at and mysqldump to store our schemas to disk. We then commit those files into our Subversion repository.

(DBIx::Class::Schema::Loader make_schema_at is slick. With 5 lines of code, you can flush an entire database into a static Schema/ directory. svn diff shows us what, if anything, has changed.)

Similarly, mysqldump output (or whatever utility dumps CREATE TABLE SQL out of your database) added to our SVN repository lets us run svn diff and see everything that changed.

So, assuming the DBA has already prepped the appropriate database changes (if any) for "sometag", our deployment goes like this:

svn checkout https://.../MyApp/tags/sometag MyApp
cd MyApp
perl Makefile.PL
make 
make install

All done. Module::Install has installed all our CPAN dependencies for us, all other custom log directories and what-not are ready to go, and our database schema(s) have been audited against the tag.

If the DBA forgot to prep the database, then perl Makefile.PL dies with a report about which part(s) of the diff_cmd results were considered fatal.

This module will not help you if you want to manage your schema versions down to individual "ALTER TABLE" statements which transform one tag to another tag. (Perhaps DBIx::Class::Schema::Versioned could help you with that level of granularity?) We don't get that fancy where I work.

METHODS

diffcheck

See SYNOPSIS above.

AUTHOR

Jay Hannah, <jay at jays.net>

BUGS

This module makes no attempt to work on Windows. Sorry. Patches welcome.

Please report any bugs or feature requests to bug-module-install-diffcheck at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Module-Install-DiffCheck. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

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

perldoc Module::Install::DiffCheck

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2009-2013 Jay Hannah, all rights reserved.