1 package DBIx::Class::DeploymentHandler;
4 use Method::Signatures::Simple;
5 require DBIx::Class::Schema; # loaded for type constraint
6 require DBIx::Class::ResultSet; # loaded for type constraint
7 use Carp::Clan '^DBIx::Class::DeploymentHandler';
9 with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod';
10 with 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions';
13 use Moose::Util::TypeConstraints;
14 subtype 'DBIx::Class::DeploymentHandler::Databases'
15 => as 'ArrayRef[Str]';
17 coerce 'DBIx::Class::DeploymentHandler::Databases'
20 no Moose::Util::TypeConstraints;
24 isa => 'DBIx::Class::Schema',
27 handles => [qw( ddl_filename schema_version )],
30 has upgrade_directory => ( # configuration
37 has backup_directory => ( # configuration
40 predicate => 'has_backup_directory',
43 has do_backup => ( # configuration
50 isa => 'DBIx::Class::ResultSet',
53 handles => [qw( is_installed db_version )],
56 method _build_version_rs {
57 $self->schema->set_us_up_the_bomb;
58 $self->schema->resultset('__VERSION')
61 has databases => ( # configuration
63 isa => 'DBIx::Class::DeploymentHandler::Databases',
65 default => sub { [qw( MySQL SQLite PostgreSQL )] },
68 has sqltargs => ( # configuration
71 default => sub { {} },
74 method install($new_version) {
75 carp 'Install not possible as versions table already exists in database'
76 if $self->is_installed;
78 $new_version ||= $self->schema_version;
83 $self->version_rs->create({
84 version => $new_version,
86 # upgrade_sql => $upgrade_sql,
92 my $db_version = $self->db_version;
93 my $schema_version = $self->schema_version;
95 unless ($db_version) {
97 carp 'Upgrade not possible as database is unversioned. Please call install first.';
101 if ( $db_version eq $schema_version ) {
103 carp "Upgrade not necessary\n";
107 my @version_list = $self->ordered_schema_versions;
109 # remove all versions in list above the required version
110 while ( @version_list && ( $version_list[-1] ne $schema_version ) ) {
114 # remove all versions in list below the current version
115 while ( @version_list && ( $version_list[0] ne $db_version ) ) {
119 # check we have an appropriate list of versions
120 die if @version_list < 2;
123 while ( @version_list >= 2 ) {
124 $self->upgrade_single_step( $version_list[0], $version_list[1] );
129 __PACKAGE__->meta->make_immutable;
135 vim: ts=2 sw=2 expandtab