my $schema = $self->schema;
my $type = $self->storage->sqlt_type;
my $sqltargs = $self->sqltargs;
- my $version = $self->schema_version || '1.x';
+ my $version = $self->schema_version;
my $filename = $self->_ddl_filename($type, [ $version ], $dir);
if(-f $filename) {
$dir = "./";
}
- my $version = $schema->schema_version || '1.x';
- my $schema_version = $schema->schema_version || '1.x';
- $version ||= $schema_version;
+ my $version = $schema->schema_version;
- $sqltargs = {
+ my $sqlt = SQL::Translator->new({
add_drop_table => 1,
ignore_constraint_names => 1,
ignore_index_names => 1,
+ parser => 'SQL::Translator::Parser::DBIx::Class',
%{$sqltargs || {}}
- };
-
- my $sqlt = SQL::Translator->new( $sqltargs );
+ });
- $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
my $sqlt_schema = $sqlt->translate({ data => $schema })
or $self->throw_exception ($sqlt->error);
$sqlt->producer($db);
my $filename = $self->_ddl_filename($db, [ $version ], $dir);
- if (-e $filename && ($version eq $schema_version )) {
- # if we are dumping the current version, overwrite the DDL
+ if (-e $filename ) {
carp "Overwriting existing DDL file - $filename";
unlink $filename;
}
}
sub prepare_update {
- my ($self, $version, $preversion) = @_;
- # this should be:
- #
- # $from_version ||= $db_version
- # $to_version ||= $schema_version
- # $version_set ||= [$from_version, $to_version];
- #
+ my ($self, $from_version, $to_version, $version_set) = @_;
+
+ $from_version ||= $self->db_version;
+ $to_version ||= $self->schema_version;
+
# for updates prepared automatically (rob's stuff)
# one would want to explicitly set $version_set to
# [$to_version]
+ $version_set ||= [$from_version, $to_version];
my $schema = $self->schema;
my $databases = $self->databases;
my $dir = $self->upgrade_directory;
$dir = "./";
}
- my $schema_version = $schema->schema_version || '1.x';
- $version ||= $schema_version;
+ my $schema_version = $schema->schema_version;
$sqltargs = {
add_drop_table => 1,
$sqlt->{schema} = $sqlt_schema;
$sqlt->producer($db);
- my $prefilename = $self->_ddl_filename($db, [ $preversion ], $dir);
+ my $prefilename = $self->_ddl_filename($db, [ $from_version ], $dir);
unless(-e $prefilename) {
carp("No previous schema file found ($prefilename)");
next;
}
- my $diff_file = $self->_ddl_filename($db, [ $preversion, $version ], $dir );
+ my $diff_file = $self->_ddl_filename($db, $version_set, $dir );
if(-e $diff_file) {
carp("Overwriting existing diff file - $diff_file");
unlink $diff_file;
$t->parser( $db ) # could this really throw an exception?
or $self->throw_exception ($t->error);
- my $filename = $self->_ddl_filename($db, [ $version ], $dir);
+ my $filename = $self->_ddl_filename($db, [ $to_version ], $dir);
my $out = $t->translate( $filename )
or $self->throw_exception ($t->error);
$version = $s->schema_version();
$handler->prepare_install();
- $handler->prepare_update($version, '1.0');
+ $handler->prepare_update('1.0', $version);
ok(-e 't/sql/DBICVersion-Schema-2.0-SQLite.sql', 'DDL for 2.0 got created successfully');
ok(-e 't/sql/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'DDL for migration from 1.0 to 2.0 got created successfully');
dies_ok {
$version = $s->schema_version();
$handler->prepare_install;
- $handler->prepare_update( $version, '1.0');
- $handler->prepare_update( $version, '2.0');
+ $handler->prepare_update( '1.0', $version );
+ $handler->prepare_update( '2.0', $version );
ok(-e 't/sql/DBICVersion-Schema-3.0-SQLite.sql', 'DDL for 3.0 got created successfully');
ok(-e 't/sql/DBICVersion-Schema-1.0-3.0-SQLite.sql', 'DDL for migration from 1.0 to 3.0 got created successfully');
ok(-e 't/sql/DBICVersion-Schema-2.0-3.0-SQLite.sql', 'DDL for migration from 2.0 to 3.0 got created successfully');