with 'DBIx::Class::DeploymentHandler::HandlesDeploy';
use Carp 'carp';
+has schema => (
+ isa => 'DBIx::Class::Schema',
+ is => 'ro',
+ required => 1,
+ handles => [qw( schema_version )],
+);
+
has storage => (
isa => 'DBIx::Class::Storage',
is => 'ro',
default => sub { [qw( MySQL SQLite PostgreSQL )] },
);
-has schema => (
- isa => 'DBIx::Class::Schema',
- is => 'ro',
- required => 1,
- handles => [qw( schema_version )],
-);
-
has _filedata => (
isa => 'ArrayRef[Str]',
is => 'rw',
);
-method _ddl_filename($type, $versions, $dir) {
+# these two methods should go away once we switch to
+# DBIx::Migration::Directories
+method _ddl_schema_filename($type, $version, $dir) {
+ my $filename = ref $self->schema;
+ $filename =~ s/::/-/g;
+
+ $filename = File::Spec->catfile(
+ $dir, "$filename-schema-$version-$type.sql"
+ );
+
+ return $filename;
+}
+
+method _ddl_schema_diff_filename($type, $versions, $dir) {
my $filename = ref $self->schema;
$filename =~ s/::/-/g;
$filename = File::Spec->catfile(
- $dir, "$filename-" . join( q(-), @{$versions} ) . "-$type.sql"
+ $dir, "$filename-diff-" . join( q(-), @{$versions} ) . "-$type.sql"
);
return $filename;
my $sqltargs = $self->sqltargs;
my $version = $self->schema_version;
- my $filename = $self->_ddl_filename($type, [ $version ], $dir);
+ my $filename = $self->_ddl_schema_filename($type, $version, $dir);
if(-f $filename) {
my $file;
open $file, q(<), $filename
my $databases = $self->databases;
my $dir = $self->upgrade_directory;
my $sqltargs = $self->sqltargs;
+ my $version = $schema->schema_version;
+
unless( -d $dir ) {
carp "Upgrade directory $dir does not exist, using ./\n";
- $dir = "./";
+ $dir = './';
}
- my $version = $schema->schema_version;
my $sqlt = SQL::Translator->new({
- add_drop_table => 1,
+ add_drop_table => 1,
ignore_constraint_names => 1,
- ignore_index_names => 1,
- parser => 'SQL::Translator::Parser::DBIx::Class',
+ ignore_index_names => 1,
+ parser => 'SQL::Translator::Parser::DBIx::Class',
%{$sqltargs || {}}
});
$sqlt->{schema} = $sqlt_schema;
$sqlt->producer($db);
- my $filename = $self->_ddl_filename($db, [ $version ], $dir);
+ my $filename = $self->_ddl_schema_filename($db, $version, $dir);
if (-e $filename ) {
carp "Overwriting existing DDL file - $filename";
unlink $filename;
$sqlt->{schema} = $sqlt_schema;
$sqlt->producer($db);
- my $prefilename = $self->_ddl_filename($db, [ $from_version ], $dir);
+ my $prefilename = $self->_ddl_schema_filename($db, $from_version, $dir);
unless(-e $prefilename) {
carp("No previous schema file found ($prefilename)");
next;
}
- my $diff_file = $self->_ddl_filename($db, $version_set, $dir );
+ my $diff_file = $self->_ddl_schema_diff_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, [ $to_version ], $dir);
+ my $filename = $self->_ddl_schema_filename($db, $to_version, $dir);
my $out = $t->translate( $filename )
or $self->throw_exception ($t->error);
sub _upgrade_single_step {
my $self = shift;
my @version_set = @{ shift @_ };
- my $upgrade_file = $self->_ddl_filename(
+ my $upgrade_file = $self->_ddl_schema_diff_filename(
$self->storage->sqlt_type,
\@version_set,
$self->upgrade_directory,
my $version = $s->schema_version();
$handler->prepare_install();
- ok(-e 't/sql/DBICVersion-Schema-1.0-SQLite.sql', 'DDL for 1.0 got created successfully');
+ ok(-e 't/sql/DBICVersion-Schema-schema-1.0-SQLite.sql', 'DDL for 1.0 got created successfully');
dies_ok {
$s->resultset('Foo')->create({
$version = $s->schema_version();
$handler->prepare_install();
$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');
+ ok(-e 't/sql/DBICVersion-Schema-schema-2.0-SQLite.sql', 'DDL for 2.0 got created successfully');
+ ok(-e 't/sql/DBICVersion-Schema-diff-1.0-2.0-SQLite.sql', 'DDL for migration from 1.0 to 2.0 got created successfully');
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
$handler->prepare_install;
$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');
+ ok(-e 't/sql/DBICVersion-Schema-schema-3.0-SQLite.sql', 'DDL for 3.0 got created successfully');
+ ok(-e 't/sql/DBICVersion-Schema-diff-1.0-3.0-SQLite.sql', 'DDL for migration from 1.0 to 3.0 got created successfully');
+ ok(-e 't/sql/DBICVersion-Schema-diff-2.0-3.0-SQLite.sql', 'DDL for migration from 2.0 to 3.0 got created successfully');
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',