Revision history for {{$dist->name}}
{{$NEXT}}
+ - change method args to named args
+ - document method args
- preconnect should not connect to the database
0.001000_09 2010-05-15 23:19:05 CST6CDT
sub upgrade {
my $self = shift;
while ( my $version_list = $self->next_version_set ) {
- my ($ddl, $upgrade_sql) = @{$self->upgrade_single_step($version_list)||[]};
+ my ($ddl, $upgrade_sql) = @{
+ $self->upgrade_single_step({ version_set => $version_list })
+ ||[]};
$self->add_database_version({
version => $version_list->[-1],
sub downgrade {
my $self = shift;
while ( my $version_list = $self->previous_version_set ) {
- $self->downgrade_single_step($version_list);
+ $self->downgrade_single_step({ version_set => $version_list });
# do we just delete a row here? I think so but not sure
$self->delete_database_version({ version => $version_list->[-1] });
sub deploy {
my $self = shift;
- my $version = shift || $self->schema_version;
+ my $version = (shift @_ || {})->{version} || $self->schema_version;
return $self->_run_sql_and_perl($self->_ddl_schema_consume_filenames(
$self->storage->sqlt_type,
}
sub install_resultsource {
- my ($self, $source, $version) = @_;
-
+ my ($self, $args) = @_;
+ my $source = $args->{result_source};
+ my $version = $args->{version};
my $rs_install_file =
$self->_resultsource_install_filename($source->source_name);
sub prepare_resultsource_install {
my $self = shift;
- my $source = shift;
+ my $source = (shift @_)->{result_source};
my $filename = $self->_resultsource_install_filename($source->source_name);
$self->_prepare_install({
}
sub prepare_upgrade {
- my ($self, $from_version, $to_version, $version_set) = @_;
- $self->_prepare_changegrade($from_version, $to_version, $version_set, 'up');
+ my ($self, $args) = @_;
+ $self->_prepare_changegrade(
+ $args->{from_version}, $args->{to_version}, $args->{version_set}, 'up'
+ );
}
sub prepare_downgrade {
- my ($self, $from_version, $to_version, $version_set) = @_;
-
- $self->_prepare_changegrade($from_version, $to_version, $version_set, 'down');
+ my ($self, $args) = @_;
+ $self->_prepare_changegrade(
+ $args->{from_version}, $args->{to_version}, $args->{version_set}, 'down'
+ );
}
method _prepare_changegrade($from_version, $to_version, $version_set, $direction) {
sub downgrade_single_step {
my $self = shift;
- my $version_set = shift @_;
+ my $version_set = (shift @_)->{version_set};
my $sql = $self->_run_sql_and_perl($self->_ddl_schema_down_consume_filenames(
$self->storage->sqlt_type,
sub upgrade_single_step {
my $self = shift;
- my $version_set = shift @_;
+ my $version_set = (shift @_)->{version_set};
my $sql = $self->_run_sql_and_perl($self->_ddl_schema_up_consume_filenames(
$self->storage->sqlt_type,
=method preinstall
- $dh->preinstall
+ $dh->preinstall({
+ version => 1,
+ storage_type => 'SQLite'
+ });
Run scripts before deploying to the database
=method deploy
- $dh->deploy
+ $dh->deploy({ version => 1 })
Deploy the schema to the database.
=method prepare_resultsource_install
- $dh->prepare_resultsource_install($resultset->result_source)
+ $dh->prepare_resultsource_install({
+ result_source => $resultset->result_source,
+ })
Takes a L<DBIx::Class::ResultSource> and generates a single migration file to
create the resultsource's table.
=method install_resultsource
- $dh->prepare_resultsource_install($resultset->result_source);
+ $dh->install_resultsource({
+ result_source => $resultset->result_source,
+ version => 1,
+ })
Takes a L<DBIx::Class::ResultSource> and runs a single migration file to
deploy the resultsource's table.
=method prepare_upgrade
- $dh->prepare_upgrade(1, 2, [1, 2]);
+ $dh->prepare_upgrade({
+ from_version => 1,
+ to_version => 2,
+ version_set => [1, 2]
+ });
Takes two versions and a version set. This basically is supposed to generate
the needed C<SQL> to migrate up from the first version to the second version.
=method prepare_downgrade
- $dh->prepare_downgrade(2, 1, [1, 2]);
+ $dh->prepare_downgrade({
+ from_version => 1,
+ to_version => 2,
+ version_set => [1, 2]
+ });
Takes two versions and a version set. This basically is supposed to generate
the needed C<SQL> to migrate down from the first version to the second version.
=method upgrade_single_step
- my ($ddl, $sql) = @{$dh->upgrade_single_step($version_set)||[]}
+ my ($ddl, $sql) = @{
+ $dh->upgrade_single_step({ version_set => $version_set })
+ ||[]}
Call a single upgrade migration. Takes a version set as an argument.
Optionally return C<< [ $ddl, $upgrade_sql ] >> where C<$ddl> is the DDL for
around prepare_upgrade => sub {
my $orig = shift;
my $self = shift;
+ my $args = shift || {};
- my $from_version = shift || $self->database_version;
- my $to_version = shift || $self->schema_version;
- my $version_set = shift || [$from_version, $to_version];
+ $args->{from_version} ||= $self->database_version;
+ $args->{to_version} ||= $self->schema_version;
+ $args->{version_set} ||= [$args->{from_version}, $args->{to_version}];
- $self->$orig($from_version, $to_version, $version_set);
+ $self->$orig($args);
};
my $orig = shift;
my $self = shift;
- my $from_version = shift || $self->database_version;
- my $to_version = shift || $self->schema_version;
- my $version_set = shift || [$from_version, $to_version];
+ my $args = shift || {};
- $self->$orig($from_version, $to_version, $version_set);
+ $args->{from_version} ||= $self->database_version;
+ $args->{to_version} ||= $self->schema_version;
+ $args->{version_set} ||= [$args->{from_version}, $args->{to_version}];
+
+ $self->$orig($args);
};
around install_resultsource => sub {
my $version = $s->schema_version();
$handler->prepare_deploy();
- $handler->prepare_upgrade(1, $version);
+ $handler->prepare_upgrade({ from_version => 1, to_version => $version });
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
my $version = $s->schema_version();
$handler->prepare_deploy;
- $handler->prepare_upgrade( 2, $version );
+ $handler->prepare_upgrade({ from_version => 2, to_version => $version });
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly');
my $version = $s->schema_version();
- $handler->prepare_downgrade(3, $version);
+ $handler->prepare_downgrade({ from_version => 3, to_version => $version });
lives_ok {
$s->resultset('Foo')->create({
bar => 'frew',
my $version = $s->schema_version();
$handler->prepare_deploy();
- $handler->prepare_upgrade(1, $version);
+ $handler->prepare_upgrade({ from_version => 1, to_version => $version} );
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
my $version = $s->schema_version();
$handler->prepare_deploy;
- $handler->prepare_upgrade( 2, $version );
+ $handler->prepare_upgrade({ from_version => 2, to_version => $version });
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
ok($handler, 'DBIx::Class::DeploymentHandler w/2 instantiates correctly');
my $version = $s->schema_version();
- $handler->prepare_downgrade(3, $version);
+ $handler->prepare_downgrade({ from_version => 3, to_version => $version });
lives_ok {
$s->resultset('Foo')->create({
bar => 'frew',
my $version = $s->schema_version();
$handler->prepare_deploy();
- $handler->prepare_upgrade('1.0', $version);
+ $handler->prepare_upgrade({ from_version => '1.0', to_version => $version });
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
my $version = $s->schema_version();
$handler->prepare_deploy;
- $handler->prepare_upgrade( '2.0', $version );
+ $handler->prepare_upgrade({ from_version => '2.0', to_version => $version });
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
catfile(qw( t sql SQLite preinstall 1.0 003-semiautomatic.pl ));
print {$prerun} "sub {use File::Touch; touch(q(foobar));}";
close $prerun;
- $dm->preinstall('1.0');
+ $dm->preinstall({ version => '1.0' });
ok -e 'foobar';
'2.0 schema gets generated properly'
);
mkpath(catfile(qw( t sql SQLite up 1.0-2.0 )));
- $dm->prepare_upgrade(qw(1.0 2.0), [qw(1.0 2.0)]);
+ $dm->prepare_upgrade({
+ from_version => '1.0',
+ to_version => '2.0',
+ version_set => [qw(1.0 2.0)]
+ });
{
my $warned = 0;
local $SIG{__WARN__} = sub{$warned = 1};
- $dm->prepare_upgrade(qw(0.0 1.0), [qw(0.0 1.0)]);
+ $dm->prepare_upgrade({
+ from_version => '0.0',
+ to_version => '1.0',
+ version_set => [qw(0.0 1.0)]
+ });
ok( $warned, 'prepare_upgrade with a bogus preversion warns' );
}
ok(
'1.0-2.0 diff gets generated properly and default start and end versions get set'
);
mkpath(catfile(qw( t sql SQLite down 2.0-1.0 )));
- $dm->prepare_downgrade($version, '1.0', [$version, '1.0']);
+ $dm->prepare_downgrade({
+ from_version => $version,
+ to_version => '1.0',
+ version_set => [$version, '1.0']
+ });
ok(
-f catfile(qw( t sql SQLite down 2.0-1.0 001-auto.sql )),
'2.0-1.0 diff gets generated properly'
|;
close $common_pl;
- $dm->upgrade_single_step([qw( 1.0 2.0 )]);
+ $dm->upgrade_single_step({ version_set => [qw( 1.0 2.0 )] });
is( $s->resultset('Foo')->search({
bar => 'hello',
baz => 'world',
baz => 'frew',
})
} 'schema is deployed';
- $dm->downgrade_single_step([qw( 2.0 1.0 )]);
+ $dm->downgrade_single_step({ version_set => [qw( 2.0 1.0 )] });
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
baz => 'frew',
})
} 'schema is downgrayyed';
- $dm->upgrade_single_step([qw( 1.0 2.0 )]);
+ $dm->upgrade_single_step({ version_set => [qw( 1.0 2.0 )] });
}
VERSION3: {
-f catfile(qw( t sql SQLite schema 3.0 001-auto.sql )),
'2.0 schema gets generated properly'
);
- $dm->prepare_downgrade($version, '1.0', [$version, '1.0']);
+ $dm->prepare_downgrade({
+ from_version => $version,
+ to_version => '1.0',
+ version_set => [$version, '1.0']
+ });
ok(
-f catfile(qw( t sql SQLite down 3.0-1.0 001-auto.sql )),
'3.0-1.0 diff gets generated properly'
);
- $dm->prepare_upgrade( '1.0', $version, ['1.0', $version] );
+ $dm->prepare_upgrade({
+ from_version => '1.0',
+ to_version => $version,
+ version_set => ['1.0', $version]
+ });
ok(
-f catfile(qw( t sql SQLite up 1.0-3.0 001-auto.sql )),
'1.0-3.0 diff gets generated properly'
);
- $dm->prepare_upgrade( '2.0', $version, ['2.0', $version]);
+ $dm->prepare_upgrade({
+ from_version => '2.0',
+ to_version => $version,
+ version_set => ['2.0', $version]
+ });
{
my $warned = 0;
local $SIG{__WARN__} = sub{$warned = 1};
- $dm->prepare_upgrade( '2.0', $version, ['2.0', $version] );
+ $dm->prepare_upgrade({
+ from_version => '2.0',
+ to_version => $version,
+ version_set => ['2.0', $version]
+ });
ok( $warned, 'prepare_upgrade warns if you clobber an existing upgrade file' );
}
ok(
biff => 'frew',
})
} 'schema not deployed';
- $dm->upgrade_single_step([qw( 2.0 3.0 )]);
+ $dm->upgrade_single_step({ version_set => [qw( 2.0 3.0 )] });
lives_ok {
$s->resultset('Foo')->create({
bar => 'frew',
rmtree(catfile(qw( t sql SQLite )));
rmtree(catfile(qw( t sql _generic )));
dies_ok {
- $dm->upgrade_single_step([qw( 2.0 3.0 )]);
+ $dm->upgrade_single_step({ version_set => [qw( 2.0 3.0 )] });
} 'dies when sql dir does not exist';
}
done_testing;
$version = $s->schema_version;
$dm->prepare_deploy;
- $dm->prepare_upgrade('1.0', $version, ['1.0', $version]);
+ $dm->prepare_upgrade({
+ from_version => '1.0',
+ to_version => $version,
+ version_set => ['1.0', $version]
+ });
dies_ok {
$s->resultset('Foo')->create({
bar => 'frew',
baz => 'frew',
})
} 'schema not uppgrayyed';
- $dm->upgrade_single_step(['1.0', $version]);
+ $dm->upgrade_single_step({ version_set => ['1.0', $version] });
lives_ok {
$s->resultset('Foo')->create({
bar => 'frew',
my $vs = Standard->new({ schema => $s });
-$dm->prepare_resultsource_install(
- $vs->version_rs->result_source
-);
+$dm->prepare_resultsource_install({
+ result_source => $vs->version_rs->result_source
+});
ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' );
ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' );
-$dm->install_resultsource(
- $vs->version_rs->result_source,
- '1.0',
-);
+$dm->install_resultsource({
+ result_source => $vs->version_rs->result_source,
+ version => '1.0',
+});
ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' );