Module::Install::DiffCheck - Run diff commands looking for deployment problems
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.
before_diff_commands
diff_commands
ignore_lines
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.
If you use a version control system to deploy your applications you might find this module useful.
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.
make_schema_at
mysqldump
(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.)
svn diff
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.
CREATE TABLE
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.
Makefile.PL
diff_cmd
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.
See SYNOPSIS above.
Jay Hannah, <jay at jays.net>
<jay at jays.net>
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.
bug-module-install-diffcheck at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Module::Install::DiffCheck
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Module-Install-DiffCheck
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Module-Install-DiffCheck
CPAN Ratings
http://cpanratings.perl.org/d/Module-Install-DiffCheck
Search CPAN
http://search.cpan.org/dist/Module-Install-DiffCheck
Version control
http://github.com/jhannah/module-install-diffcheck, http://svn.ali.as/cpan/trunk/Module-Install/lib/Module/Install/
Copyright 2009-2013 Jay Hannah, all rights reserved.
To install Module::Install::DiffCheck, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Module::Install::DiffCheck
CPAN shell
perl -MCPAN -e shell install Module::Install::DiffCheck
For more information on module installation, please visit the detailed CPAN module installation guide.