Subject: | Generated SQL with ignore_ddl has empty lines, causes errors |
With ignore_ddl set, I've been getting errors like:
Failed database installation: DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::try {...} (): DBI Exception: DBD::mysql::db do failed: Query was empty [for Statement ""] at /home/lianna/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/x86_64-linux/Moose/Meta/Method/Delegation.pm line 113
(running line '') at /home/lianna/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm line 254.
The cause is visible with tracing on:
[DBICDH] [info] deploying version 1
[DBICDH] [trace] generating SQL from Serialized SQL Files: [
"..snip../migrations/_source/deploy/1/001-auto-__VERSION.yml",
"..snip../migrations/_source/deploy/1/001-auto.yml"
]
[DBICDH] [trace] Running SQL [
"",
"SET foreign_key_checks=0",
"CREATE TABLE `dbix_class_deploymenthandler_versions` ( `id` integer NOT NULL auto_increment, `version` varchar(50) NOT NULL, `ddl` text NULL, `upgrade_sql` text NULL, PRIMARY KEY (`id`), UNIQUE `dbix_class_deploymenthandler_versions_version` (`version`) )",
"SET foreign_key_checks=1",
"",
<snip>
A proper fix would presumably fix the SQL generation to remove the empty lines altogether, but I haven't looked into that. As a quick fix, this works for me:
--- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm
+++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm
@@ -242,6 +242,7 @@ sub _run_sql_array {
Dlog_trace { "Running SQL $_" } $sql;
foreach my $line (@{$sql}) {
+ next if $line eq '';
$storage->_query_start($line);
# the whole reason we do this is so that we can see the line that was run
try {