sub _build_schema {
my ($self) = @_;
$self->ensure_class_loaded($self->schema_class);
- warn Dumper $self->connect_info();
- return $self->schema_class->connect($self->connect_info()}, $self->connect_info->[3], { ignore_version => 1} );
+ $self->connect_info->[3]->{ignore_version} =1;
+ #warn Dumper ($self->connect_info(), $self->connect_info->[3], {ignore_version => 1 });
+ return $self->schema_class->connect(@{$self->connect_info()} ); # , $self->connect_info->[3], { ignore_version => 1} );
}
has 'connect_info' => (
);
sub create {
- my ($self, $sqlt_type, ) = @_;
+ my ($self, $sqlt_type, $sqlt_args) = @_;
if ($self->has_preversion) {
print "attempting to create diff file for ".$self->preversion."\n";
}
# create the dir if does not exist
$self->sql_dir->mkpath() if ( ! -d $self->sql_dir);
- $schema->create_ddl_dir( $sqlt_type, (defined $schema->schema_version ? $schema->schema_version : ""), $self->sql_dir->stringify, $self->preversion );
+ $schema->create_ddl_dir( $sqlt_type, (defined $schema->schema_version ? $schema->schema_version : ""), $self->sql_dir->stringify, $self->preversion, $sqlt_args );
}
sub upgrade {
}
sub deploy {
- my ($self) = @_;
+ my ($self, $args) = @_;
my $schema = $self->schema();
if (!$schema->get_db_version() ) {
# schema is unversioned
- $schema->deploy();
+# warn "going to deploy";
+# warn Dumper $schema->deployment_statements();
+
+ $schema->deploy( $args, $self->sql_dir)
+ or die "could not deploy schema";
} else {
warn "there already is a database with a version here, try upgrade instead";
}
use Path::Class;
use FindBin qw($Bin);
+
+use Module::Load;
+
use lib dir($Bin,'..', '..','lib')->stringify;
use lib dir($Bin,'..', 'lib')->stringify;
my $sql_dir = dir($Bin,"var","sql");
-
{ # create the schema
+# make sure we are clean
+clean_dir($sql_dir);
+
+# create a DBICTest so we can steal its connect info
my $schema = DBICTest->init_schema(
no_deploy=>1,
no_populate=>1,
);
- clean_dir($sql_dir);
+
+
my $admin = DBIx::Class::Admin->new(
schema_class=> "DBICTest::Schema",
sql_dir=> $sql_dir,
connect_info => $schema->storage->connect_info()
);
-
+isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql';
}
-
{ # upgrade schema
my $schema = DBICTest->init_schema(
- no_deploy=>1,
- no_populate=>1,
- );
+ no_deploy => 1,
+ no_populat => 1,
+ sqlite_use_file => 1,
+);
- clean_dir($sql_dir);
-use DBICVersionOrig;
+clean_dir($sql_dir);
+load 'DBICVersionOrig';
my $admin = DBIx::Class::Admin->new(
schema_class => 'DBICVersion::Schema',
sql_dir => $sql_dir,
connect_info => $schema->storage->connect_info(),
);
-lives_ok { $admin->create($schema->storage->sqlt_type()); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
-lives_ok { $admin->deploy(); } 'Can Deploy schema';
+lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
+lives_ok { $admin->deploy( ) } 'Can Deploy schema';
+
+# connect to now deployed schema
+lives_ok { $schema = DBICVersion::Schema->connect(@{$schema->storage->connect_info()}); } 'Connect to deployed Database';
+
+is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
+
+
+load 'DBICVersionNew';
+
+$admin = DBIx::Class::Admin->new(
+ schema_class => 'DBICVersion::Schema',
+ sql_dir => $sql_dir,
+ connect_info => $schema->storage->connect_info(),
+);
+
+$admin->upgrade();
+
}
sub clean_dir {
my ($dir) =@_;
foreach my $file ($dir->children) {
+ # skip any hidden files
+ next if ($file =~ /^\./);
unlink $file;
}
}