Dlog should work thanks to new release of L::C
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / DeployMethod / SQL / Translator.pm
1 package DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator;
2 use Moose;
3
4 # ABSTRACT: Manage your SQL and Perl migrations in nicely laid out directories
5
6 use autodie;
7 use Carp qw( carp croak );
8 use Log::Contextual::WarnLogger;
9 use Log::Contextual qw(:log :dlog), -default_logger => Log::Contextual::WarnLogger->new({
10    env_prefix => 'DBICDH'
11 });
12
13 use Method::Signatures::Simple;
14 use Try::Tiny;
15
16 use SQL::Translator;
17 require SQL::Translator::Diff;
18
19 require DBIx::Class::Storage;   # loaded for type constraint
20 use DBIx::Class::DeploymentHandler::Types;
21
22 use File::Path 'mkpath';
23 use File::Spec::Functions;
24
25 with 'DBIx::Class::DeploymentHandler::HandlesDeploy';
26
27 has schema => (
28   isa      => 'DBIx::Class::Schema',
29   is       => 'ro',
30   required => 1,
31 );
32
33 has storage => (
34   isa        => 'DBIx::Class::Storage',
35   is         => 'ro',
36   lazy_build => 1,
37 );
38
39 method _build_storage {
40   my $s = $self->schema->storage;
41   $s->_determine_driver;
42   $s
43 }
44
45 has sql_translator_args => (
46   isa => 'HashRef',
47   is  => 'ro',
48   default => sub { {} },
49 );
50 has script_directory => (
51   isa      => 'Str',
52   is       => 'ro',
53   required => 1,
54   default  => 'sql',
55 );
56
57 has databases => (
58   coerce  => 1,
59   isa     => 'DBIx::Class::DeploymentHandler::Databases',
60   is      => 'ro',
61   default => sub { [qw( MySQL SQLite PostgreSQL )] },
62 );
63
64 has txn_wrap => (
65   is => 'ro',
66   isa => 'Bool',
67   default => 1,
68 );
69
70 has schema_version => (
71   is => 'ro',
72   isa => 'Str',
73   lazy_build => 1,
74 );
75
76 # this will probably never get called as the DBICDH
77 # will be passing down a schema_version normally, which
78 # is built the same way, but we leave this in place
79 method _build_schema_version { $self->schema->schema_version }
80
81 has _json => (
82   is => 'ro',
83   lazy_build => 1,
84 );
85
86 sub _build__json { require JSON; JSON->new->pretty }
87
88 method __ddl_consume_with_prefix($type, $versions, $prefix) {
89   my $base_dir = $self->script_directory;
90
91   my $main    = catfile( $base_dir, $type      );
92   my $generic = catfile( $base_dir, '_generic' );
93   my $common  =
94     catfile( $base_dir, '_common', $prefix, join q(-), @{$versions} );
95
96   my $dir;
97   if (-d $main) {
98     $dir = catfile($main, $prefix, join q(-), @{$versions})
99   } elsif (-d $generic) {
100     $dir = catfile($generic, $prefix, join q(-), @{$versions});
101   } else {
102     croak "neither $main or $generic exist; please write/generate some SQL";
103   }
104
105   opendir my($dh), $dir;
106   my %files = map { $_ => "$dir/$_" } grep { /\.(?:sql|pl|sql-\w+)$/ && -f "$dir/$_" } readdir $dh;
107   closedir $dh;
108
109   if (-d $common) {
110     opendir my($dh), $common;
111     for my $filename (grep { /\.(?:sql|pl)$/ && -f catfile($common,$_) } readdir $dh) {
112       unless ($files{$filename}) {
113         $files{$filename} = catfile($common,$filename);
114       }
115     }
116     closedir $dh;
117   }
118
119   return [@files{sort keys %files}]
120 }
121
122 method _ddl_preinstall_consume_filenames($type, $version) {
123   $self->__ddl_consume_with_prefix($type, [ $version ], 'preinstall')
124 }
125
126 method _ddl_schema_consume_filenames($type, $version) {
127   $self->__ddl_consume_with_prefix($type, [ $version ], 'schema')
128 }
129
130 method _ddl_schema_produce_filename($type, $version) {
131   my $dirname = catfile( $self->script_directory, $type, 'schema', $version );
132   mkpath($dirname) unless -d $dirname;
133
134   return catfile( $dirname, '001-auto.sql-json' );
135 }
136
137 method _ddl_schema_up_consume_filenames($type, $versions) {
138   $self->__ddl_consume_with_prefix($type, $versions, 'up')
139 }
140
141 method _ddl_schema_down_consume_filenames($type, $versions) {
142   $self->__ddl_consume_with_prefix($type, $versions, 'down')
143 }
144
145 method _ddl_schema_up_produce_filename($type, $versions) {
146   my $dir = $self->script_directory;
147
148   my $dirname = catfile( $dir, $type, 'up', join q(-), @{$versions});
149   mkpath($dirname) unless -d $dirname;
150
151   return catfile( $dirname, '001-auto.sql-json' );
152 }
153
154 method _ddl_schema_down_produce_filename($type, $versions, $dir) {
155   my $dirname = catfile( $dir, $type, 'down', join q(-), @{$versions} );
156   mkpath($dirname) unless -d $dirname;
157
158   return catfile( $dirname, '001-auto.sql-json');
159 }
160
161 method _run_sql_array($sql) {
162   my $storage = $self->storage;
163
164   $sql = [grep {
165     $_ && # remove blank lines
166     !/^(BEGIN|BEGIN TRANSACTION|COMMIT)/ # strip txn's
167   } map {
168     s/^\s+//; s/\s+$//; # trim whitespace
169     join '', grep { !/^--/ } split /\n/ # remove comments
170   } @$sql];
171
172   Dlog_trace { "[DBICDH] Running SQL $_" } $sql;
173   foreach my $line (@{$sql}) {
174     $storage->_query_start($line);
175     # the whole reason we do this is so that we can see the line that was run
176     try {
177       $storage->dbh_do (sub { $_[1]->do($line) });
178     }
179     catch {
180       die "$_ (running line '$line')"
181     }
182     $storage->_query_end($line);
183   }
184   return join "\n", @$sql
185 }
186
187 method _run_sql($filename) {
188   log_debug { "[DBICDH] Running SQL from $filename" };
189   return $self->_run_sql_array($self->_read_sql_file($filename));
190 }
191
192 method _run_perl($filename) {
193   log_debug { "[DBICDH] Running Perl from $filename" };
194   my $filedata = do { local( @ARGV, $/ ) = $filename; <> };
195
196   no warnings 'redefine';
197   my $fn = eval "$filedata";
198   use warnings;
199   Dlog_trace { "[DBICDH] Running Perl $_" } $fn;
200
201   if ($@) {
202     carp "$filename failed to compile: $@";
203   } elsif (ref $fn eq 'CODE') {
204     $fn->($self->schema)
205   } else {
206     carp "$filename should define an anonymouse sub that takes a schema but it didn't!";
207   }
208 }
209
210 method _run_serialized_sql($filename, $type) {
211   if (lc $type eq 'json') {
212     return $self->_run_sql_array($self->_json->decode(
213       do { local( @ARGV, $/ ) = $filename; <> } # slurp
214     ))
215   } else {
216     croak "$type is not one of the supported serialzed types"
217   }
218 }
219
220 method _run_sql_and_perl($filenames) {
221   my @files   = @{$filenames};
222   my $guard   = $self->schema->txn_scope_guard if $self->txn_wrap;
223
224   my $sql = '';
225   for my $filename (@files) {
226     if ($filename =~ /\.sql$/) {
227        $sql .= $self->_run_sql($filename)
228     } elsif ( $filename =~ /\.sql-(\w+)$/ ) {
229        $sql .= $self->_run_serialized_sql($filename, $1)
230     } elsif ( $filename =~ /\.pl$/ ) {
231        $self->_run_perl($filename)
232     } else {
233       croak "A file ($filename) got to deploy that wasn't sql or perl!";
234     }
235   }
236
237   $guard->commit if $self->txn_wrap;
238
239   return $sql;
240 }
241
242 sub deploy {
243   my $self = shift;
244   my $version = (shift @_ || {})->{version} || $self->schema_version;
245   log_info { "[DBICDH] deploying version $version" };
246
247   return $self->_run_sql_and_perl($self->_ddl_schema_consume_filenames(
248     $self->storage->sqlt_type,
249     $version,
250   ));
251 }
252
253 sub preinstall {
254   my $self         = shift;
255   my $args         = shift;
256   my $version      = $args->{version}      || $self->schema_version;
257   log_info { "[DBICDH] preinstalling version $version" };
258   my $storage_type = $args->{storage_type} || $self->storage->sqlt_type;
259
260   my @files = @{$self->_ddl_preinstall_consume_filenames(
261     $storage_type,
262     $version,
263   )};
264
265   for my $filename (@files) {
266     # We ignore sql for now (till I figure out what to do with it)
267     if ( $filename =~ /^(.+)\.pl$/ ) {
268       my $filedata = do { local( @ARGV, $/ ) = $filename; <> };
269
270       no warnings 'redefine';
271       my $fn = eval "$filedata";
272       use warnings;
273
274       if ($@) {
275         carp "$filename failed to compile: $@";
276       } elsif (ref $fn eq 'CODE') {
277         $fn->()
278       } else {
279         carp "$filename should define an anonymous sub but it didn't!";
280       }
281     } else {
282       croak "A file ($filename) got to preinstall_scripts that wasn't sql or perl!";
283     }
284   }
285 }
286
287 sub _prepare_install {
288   my $self      = shift;
289   my $sqltargs  = { %{$self->sql_translator_args}, %{shift @_} };
290   my $to_file   = shift;
291   my $schema    = $self->schema;
292   my $databases = $self->databases;
293   my $dir       = $self->script_directory;
294   my $version   = $self->schema_version;
295
296   my $sqlt = SQL::Translator->new({
297     no_comments             => 1,
298     add_drop_table          => 1,
299     ignore_constraint_names => 1,
300     ignore_index_names      => 1,
301     parser                  => 'SQL::Translator::Parser::DBIx::Class',
302     %{$sqltargs}
303   });
304
305   my $sqlt_schema = $sqlt->translate( data => $schema )
306     or croak($sqlt->error);
307
308   foreach my $db (@$databases) {
309     $sqlt->reset;
310     $sqlt->{schema} = $sqlt_schema;
311     $sqlt->producer($db);
312
313     my $filename = $self->$to_file($db, $version, $dir);
314     if (-e $filename ) {
315       carp "Overwriting existing DDL file - $filename";
316       unlink $filename;
317     }
318
319     my $sql = $self->_generate_final_sql($sqlt);
320     if(!$sql) {
321       carp("Failed to translate to $db, skipping. (" . $sqlt->error . ")");
322       next;
323     }
324     open my $file, q(>), $filename;
325     print {$file} $sql;
326     close $file;
327   }
328 }
329
330 method _generate_final_sql($sqlt) {
331   my @output = $sqlt->translate;
332   $self->_json->encode(\@output);
333 }
334
335 sub _resultsource_install_filename {
336   my ($self, $source_name) = @_;
337   return sub {
338     my ($self, $type, $version) = @_;
339     my $dirname = catfile( $self->script_directory, $type, 'schema', $version );
340     mkpath($dirname) unless -d $dirname;
341
342     return catfile( $dirname, "001-auto-$source_name.sql-json" );
343   }
344 }
345
346 sub install_resultsource {
347   my ($self, $args) = @_;
348   my $source          = $args->{result_source};
349   my $version         = $args->{version};
350   log_info { '[DBICDH] installing_resultsource ' . $source->source_name . ", version $version" };
351   my $rs_install_file =
352     $self->_resultsource_install_filename($source->source_name);
353
354   my $files = [
355      $self->$rs_install_file(
356       $self->storage->sqlt_type,
357       $version,
358     )
359   ];
360   $self->_run_sql_and_perl($files);
361 }
362
363 sub prepare_resultsource_install {
364   my $self = shift;
365   my $source = (shift @_)->{result_source};
366   log_info { '[DBICDH] preparing install for resultsource ' . $source->source_name };
367
368   my $filename = $self->_resultsource_install_filename($source->source_name);
369   $self->_prepare_install({
370       parser_args => { sources => [$source->source_name], }
371     }, $filename);
372 }
373
374 sub prepare_deploy {
375   log_info { '[DBICDH] preparing deploy' };
376   my $self = shift;
377   $self->_prepare_install({}, '_ddl_schema_produce_filename');
378 }
379
380 sub prepare_upgrade {
381   my ($self, $args) = @_;
382   log_info {
383      '[DBICDH] preparing upgrade ' .
384      "from $args->{from_version} to $args->{to_version}"
385   };
386   $self->_prepare_changegrade(
387     $args->{from_version}, $args->{to_version}, $args->{version_set}, 'up'
388   );
389 }
390
391 sub prepare_downgrade {
392   my ($self, $args) = @_;
393   log_info {
394      '[DBICDH] preparing downgrade ' .
395      "from $args->{from_version} to $args->{to_version}"
396   };
397   $self->_prepare_changegrade(
398     $args->{from_version}, $args->{to_version}, $args->{version_set}, 'down'
399   );
400 }
401
402 method _prepare_changegrade($from_version, $to_version, $version_set, $direction) {
403   my $schema    = $self->schema;
404   my $databases = $self->databases;
405   my $dir       = $self->script_directory;
406   my $sqltargs  = $self->sql_translator_args;
407
408   my $schema_version = $self->schema_version;
409
410   $sqltargs = {
411     add_drop_table => 1,
412     no_comments => 1,
413     ignore_constraint_names => 1,
414     ignore_index_names => 1,
415     %{$sqltargs}
416   };
417
418   my $sqlt = SQL::Translator->new( $sqltargs );
419
420   $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
421   my $sqlt_schema = $sqlt->translate( data => $schema )
422     or croak($sqlt->error);
423
424   foreach my $db (@$databases) {
425     $sqlt->reset;
426     $sqlt->{schema} = $sqlt_schema;
427     $sqlt->producer($db);
428
429     my $prefilename = $self->_ddl_schema_produce_filename($db, $from_version, $dir);
430     unless(-e $prefilename) {
431       carp("No previous schema file found ($prefilename)");
432       next;
433     }
434     my $diff_file_method = "_ddl_schema_${direction}_produce_filename";
435     my $diff_file = $self->$diff_file_method($db, $version_set, $dir );
436     if(-e $diff_file) {
437       carp("Overwriting existing $direction-diff file - $diff_file");
438       unlink $diff_file;
439     }
440
441     my $source_schema;
442     {
443       my $t = SQL::Translator->new({
444          %{$sqltargs},
445          debug => 0,
446          trace => 0,
447       });
448
449       $t->parser( $db ) # could this really throw an exception?
450         or croak($t->error);
451
452       my $sql = $self->_default_read_sql_file_as_string($prefilename);
453       my $out = $t->translate( \$sql )
454         or croak($t->error);
455
456       $source_schema = $t->schema;
457
458       $source_schema->name( $prefilename )
459         unless  $source_schema->name;
460     }
461
462     # The "new" style of producers have sane normalization and can support
463     # diffing a SQL file against a DBIC->SQLT schema. Old style ones don't
464     # And we have to diff parsed SQL against parsed SQL.
465     my $dest_schema = $sqlt_schema;
466
467     unless ( "SQL::Translator::Producer::$db"->can('preprocess_schema') ) {
468       my $t = SQL::Translator->new({
469          %{$sqltargs},
470          debug => 0,
471          trace => 0,
472       });
473
474       $t->parser( $db ) # could this really throw an exception?
475         or croak($t->error);
476
477       my $filename = $self->_ddl_schema_produce_filename($db, $to_version, $dir);
478       my $sql = $self->_default_read_sql_file_as_string($filename);
479       my $out = $t->translate( \$sql )
480         or croak($t->error);
481
482       $dest_schema = $t->schema;
483
484       $dest_schema->name( $filename )
485         unless $dest_schema->name;
486     }
487
488     open my $file, q(>), $diff_file;
489     print {$file}
490       $self->_generate_final_diff($source_schema, $dest_schema, $db, $sqltargs);
491     close $file;
492   }
493 }
494
495 method _generate_final_diff($source_schema, $dest_schema, $db, $sqltargs) {
496   $self->_json->encode([
497      SQL::Translator::Diff::schema_diff(
498         $source_schema, $db,
499         $dest_schema,   $db,
500         $sqltargs
501      )
502   ])
503 }
504
505 method _read_sql_file($file) {
506   return unless $file;
507
508   open my $fh, '<', $file;
509   my @data = split /;\n/, join '', <$fh>;
510   close $fh;
511
512   return \@data;
513 }
514
515 method _default_read_sql_file_as_string($file) {
516   return join q(), map "$_;\n", @{$self->_json->decode(
517     do { local( @ARGV, $/ ) = $file; <> } # slurp
518   )};
519 }
520
521 sub downgrade_single_step {
522   my $self = shift;
523   my $version_set = (shift @_)->{version_set};
524   Dlog_info { qq([DBICDH] downgrade_single_step'ing $_) } $version_set;
525
526   my $sql = $self->_run_sql_and_perl($self->_ddl_schema_down_consume_filenames(
527     $self->storage->sqlt_type,
528     $version_set,
529   ));
530
531   return ['', $sql];
532 }
533
534 sub upgrade_single_step {
535   my $self = shift;
536   my $version_set = (shift @_)->{version_set};
537   Dlog_info { qq([DBICDH] upgrade_single_step'ing $_) } $version_set;
538
539   my $sql = $self->_run_sql_and_perl($self->_ddl_schema_up_consume_filenames(
540     $self->storage->sqlt_type,
541     $version_set,
542   ));
543   return ['', $sql];
544 }
545
546 __PACKAGE__->meta->make_immutable;
547
548 1;
549
550 # vim: ts=2 sw=2 expandtab
551
552 __END__
553
554 =head1 DESCRIPTION
555
556 This class is the meat of L<DBIx::Class::DeploymentHandler>.  It takes
557 care of generating serialized sql files representing schemata as well
558 as serialized sql files to move from one version of a schema to the rest.
559 One of the hallmark features of this class is that it allows for multiple sql
560 files for deploy and upgrade, allowing developers to fine tune deployment.
561 In addition it also allows for perl files to be run
562 at any stage of the process.
563
564 For basic usage see L<DBIx::Class::DeploymentHandler::HandlesDeploy>.  What's
565 documented here is extra fun stuff or private methods.
566
567 =head1 DIRECTORY LAYOUT
568
569 Arguably this is the best feature of L<DBIx::Class::DeploymentHandler>.  It's
570 heavily based upon L<DBIx::Migration::Directories>, but has some extensions and
571 modifications, so even if you are familiar with it, please read this.  I feel
572 like the best way to describe the layout is with the following example:
573
574  $sql_migration_dir
575  |- SQLite
576  |  |- down
577  |  |  `- 2-1
578  |  |     `- 001-auto.sql-json
579  |  |- schema
580  |  |  `- 1
581  |  |     `- 001-auto.sql-json
582  |  `- up
583  |     |- 1-2
584  |     |  `- 001-auto.sql-json
585  |     `- 2-3
586  |        `- 001-auto.sql-json
587  |- _common
588  |  |- down
589  |  |  `- 2-1
590  |  |     `- 002-remove-customers.pl
591  |  `- up
592  |     `- 1-2
593  |        `- 002-generate-customers.pl
594  |- _generic
595  |  |- down
596  |  |  `- 2-1
597  |  |     `- 001-auto.sql-json
598  |  |- schema
599  |  |  `- 1
600  |  |     `- 001-auto.sql-json
601  |  `- up
602  |     `- 1-2
603  |        |- 001-auto.sql-json
604  |        `- 002-create-stored-procedures.sql
605  `- MySQL
606     |- down
607     |  `- 2-1
608     |     `- 001-auto.sql-json
609     |- preinstall
610     |  `- 1
611     |     |- 001-create_database.pl
612     |     `- 002-create_users_and_permissions.pl
613     |- schema
614     |  `- 1
615     |     `- 001-auto.sql-json
616     `- up
617        `- 1-2
618           `- 001-auto.sql-json
619
620 So basically, the code
621
622  $dm->deploy(1)
623
624 on an C<SQLite> database that would simply run
625 C<$sql_migration_dir/SQLite/schema/1/001-auto.sql-json>.  Next,
626
627  $dm->upgrade_single_step([1,2])
628
629 would run C<$sql_migration_dir/SQLite/up/1-2/001-auto.sql-json> followed by
630 C<$sql_migration_dir/_common/up/1-2/002-generate-customers.pl>.
631
632 C<.pl> files don't have to be in the C<_common> directory, but most of the time
633 they should be, because perl scripts are generally be database independent.
634
635 C<_generic> exists for when you for some reason are sure that your SQL is
636 generic enough to run on all databases.  Good luck with that one.
637
638 Note that unlike most steps in the process, C<preinstall> will not run SQL, as
639 there may not even be an database at preinstall time.  It will run perl scripts
640 just like the other steps in the process, but nothing is passed to them.
641 Until people have used this more it will remain freeform, but a recommended use
642 of preinstall is to have it prompt for username and password, and then call the
643 appropriate C<< CREATE DATABASE >> commands etc.
644
645 =head1 SERIALIZED SQL
646
647 The SQL that this module generates and uses is serialized into an array of
648 SQL statements.  The reason being that some databases handle multiple
649 statements in a single execution differently.  Generally you do not need to
650 worry about this as these are scripts generated for you.  If you find that
651 you are editing them on a regular basis something is wrong and you either need
652 to submit a bug or consider writing extra serialized SQL or Perl scripts to run
653 before or after the automatically generated script.
654
655 B<NOTE:> Currently the SQL is serialized into JSON.  I am willing to merge in
656 patches that will allow more serialization formats if you want that feature,
657 but if you do send me a patch for that realize that I do not want to add YAML
658 support or whatever, I would rather add a generic method of adding any
659 serialization format.
660
661 =head1 PERL SCRIPTS
662
663 A perl script for this tool is very simple.  It merely needs to contain an
664 anonymous sub that takes a L<DBIx::Class::Schema> as it's only argument.
665 A very basic perl script might look like:
666
667  #!perl
668
669  use strict;
670  use warnings;
671
672  sub {
673    my $schema = shift;
674
675    $schema->resultset('Users')->create({
676      name => 'root',
677      password => 'root',
678    })
679  }
680
681 =attr schema
682
683 The L<DBIx::Class::Schema> (B<required>) that is used to talk to the database
684 and generate the DDL.
685
686 =attr storage
687
688 The L<DBIx::Class::Storage> that is I<actually> used to talk to the database
689 and generate the DDL.  This is automatically created with L</_build_storage>.
690
691 =attr sql_translator_args
692
693 The arguments that get passed to L<SQL::Translator> when it's used.
694
695 =attr script_directory
696
697 The directory (default C<'sql'>) that scripts are stored in
698
699 =attr databases
700
701 The types of databases (default C<< [qw( MySQL SQLite PostgreSQL )] >>) to
702 generate files for
703
704 =attr txn_wrap
705
706 Set to true (which is the default) to wrap all upgrades and deploys in a single
707 transaction.
708
709 =attr schema_version
710
711 The version the schema on your harddrive is at.  Defaults to
712 C<< $self->schema->schema_version >>.
713
714 =begin comment
715
716 =head2 __ddl_consume_with_prefix
717
718  $dm->__ddl_consume_with_prefix( 'SQLite', [qw( 1.00 1.01 )], 'up' )
719
720 This is the meat of the multi-file upgrade/deploy stuff.  It returns a list of
721 files in the order that they should be run for a generic "type" of upgrade.
722 You should not be calling this in user code.
723
724 =head2 _ddl_schema_consume_filenames
725
726  $dm->__ddl_schema_consume_filenames( 'SQLite', [qw( 1.00 )] )
727
728 Just a curried L</__ddl_consume_with_prefix>.  Get's a list of files for an
729 initial deploy.
730
731 =head2 _ddl_schema_produce_filename
732
733  $dm->__ddl_schema_produce_filename( 'SQLite', [qw( 1.00 )] )
734
735 Returns a single file in which an initial schema will be stored.
736
737 =head2 _ddl_schema_up_consume_filenames
738
739  $dm->_ddl_schema_up_consume_filenames( 'SQLite', [qw( 1.00 )] )
740
741 Just a curried L</__ddl_consume_with_prefix>.  Get's a list of files for an
742 upgrade.
743
744 =head2 _ddl_schema_down_consume_filenames
745
746  $dm->_ddl_schema_down_consume_filenames( 'SQLite', [qw( 1.00 )] )
747
748 Just a curried L</__ddl_consume_with_prefix>.  Get's a list of files for a
749 downgrade.
750
751 =head2 _ddl_schema_up_produce_filenames
752
753  $dm->_ddl_schema_up_produce_filename( 'SQLite', [qw( 1.00 1.01 )] )
754
755 Returns a single file in which the sql to upgrade from one schema to another
756 will be stored.
757
758 =head2 _ddl_schema_down_produce_filename
759
760  $dm->_ddl_schema_down_produce_filename( 'SQLite', [qw( 1.00 1.01 )] )
761
762 Returns a single file in which the sql to downgrade from one schema to another
763 will be stored.
764
765 =head2 _resultsource_install_filename
766
767  my $filename_fn = $dm->_resultsource_install_filename('User');
768  $dm->$filename_fn('SQLite', '1.00')
769
770 Returns a function which in turn returns a single filename used to install a
771 single resultsource.  Weird interface is convenient for me.  Deal with it.
772
773 =head2 _run_sql_and_perl
774
775  $dm->_run_sql_and_perl([qw( list of filenames )])
776
777 Simply put, this runs the list of files passed to it.  If the file ends in
778 C<.sql> it runs it as sql and if it ends in C<.pl> it runs it as a perl file.
779
780 Depending on L</txn_wrap> all of the files run will be wrapped in a single
781 transaction.
782
783 =head2 _prepare_install
784
785  $dm->_prepare_install({ add_drop_table => 0 }, sub { 'file_to_create' })
786
787 Generates the sql file for installing the database.  First arg is simply
788 L<SQL::Translator> args and the second is a coderef that returns the filename
789 to store the sql in.
790
791 =head2 _prepare_changegrade
792
793  $dm->_prepare_changegrade('1.00', '1.01', [qw( 1.00 1.01)], 'up')
794
795 Generates the sql file for migrating from one schema version to another.  First
796 arg is the version to start from, second is the version to go to, third is the
797 L<version set|DBIx::Class::DeploymentHandler/VERSION SET>, and last is the
798 direction of the changegrade, be it 'up' or 'down'.
799
800 =head2 _read_sql_file
801
802  $dm->_read_sql_file('foo.sql')
803
804 Reads a sql file and returns lines in an C<ArrayRef>.  Strips out comments,
805 transactions, and blank lines.
806
807 =end comment