with 'DBIx::Class::DeploymentHandler::HandlesDeploy';
+with 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+ interface_role => 'DBIx::Class::DeploymentHandler::HandlesMigrationSchema',
+ class_name => 'DBIx::Class::DeploymentHandler::MigrationSchema::SchemaLoader',
+ delegate_name => 'schema_provider',
+ attributes_to_assume => ['schema'],
+ attributes_to_copy => [qw( schema )],
+ };
+
has ignore_ddl => (
isa => 'Bool',
is => 'ro',
# this will probably never get called as the DBICDH
# will be passing down a schema_version normally, which
# is built the same way, but we leave this in place
-sub _build_schema_version {
+sub _build_schema_version {
my $self = shift;
- $self->schema->schema_version
+ $self->schema->schema_version
}
sub __ddl_consume_with_prefix {
my ($self, $sql) = @_;
my $storage = $self->storage;
- $sql = [grep {
- $_ && # remove blank lines
- !/^(BEGIN|BEGIN TRANSACTION|COMMIT)/ # strip txn's
- } map {
- s/^\s+//; s/\s+$//; # trim whitespace
- join '', grep { !/^--/ } split /\n/ # remove comments
- } @$sql];
+ $sql = [ _split_sql_chunk( @$sql ) ];
Dlog_trace { "Running SQL $_" } $sql;
foreach my $line (@{$sql}) {
return join "\n", @$sql
}
+# split a chunk o' SQL into statements
+sub _split_sql_chunk {
+ my @sql = map { split /;\n/, $_ } @_;
+
+ for ( @sql ) {
+ # strip transactions
+ s/^(?:BEGIN|BEGIN TRANSACTION|COMMIT).*//mgi;
+
+ # trim whitespaces
+ s/^\s+|\s+$//mg;
+
+ # remove comments
+ s/^--.*//gm;
+
+ # remove blank lines
+ s/^\n//mg;
+
+ # put on single line
+ s/\n/ /g;
+ }
+
+ return @sql;
+}
+
sub _run_sql {
my ($self, $filename) = @_;
log_debug { "Running SQL from $filename" };
if ($@) {
croak "$filename failed to compile: $@";
} elsif (ref $fn eq 'CODE') {
- $fn->($self->schema, $versions)
+ $fn->($self->migration_schema, $versions)
} else {
croak "$filename should define an anonymouse sub that takes a schema but it didn't!";
}
my ($self, $file) = @_;
return unless $file;
+ local $/ = undef; #sluuuuuurp
+
open my $fh, '<', $file;
- my @data = split /;\n/, join '', <$fh>;
- close $fh;
-
- @data = grep {
- $_ && # remove blank lines
- !/^(BEGIN|BEGIN TRANSACTION|COMMIT)/ # strip txn's
- } map {
- s/^\s+//; s/\s+$//; # trim whitespace
- join '', grep { !/^--/ } split /\n/ # remove comments
- } @data;
-
- return \@data;
+ return [ _split_sql_chunk( <$fh> ) ];
}
sub downgrade_single_step {