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';
12 use Moose::Util::TypeConstraints;
13 subtype 'DBIx::Class::DeploymentHandler::Databases'
14 => as 'ArrayRef[Str]';
16 coerce 'DBIx::Class::DeploymentHandler::Databases'
19 no Moose::Util::TypeConstraints;
23 isa => 'DBIx::Class::Schema',
26 handles => [qw( ddl_filename schema_version )],
29 has upgrade_directory => ( # configuration
36 has backup_directory => ( # configuration
39 predicate => 'has_backup_directory',
42 has do_backup => ( # configuration
49 isa => 'DBIx::Class::ResultSet',
52 handles => [qw( is_installed db_version )],
55 method _build_version_rs {
56 $self->schema->set_us_up_the_bomb;
57 $self->schema->resultset('__VERSION')
60 has databases => ( # configuration
62 isa => 'DBIx::Class::DeploymentHandler::Databases',
64 default => sub { [qw( MySQL SQLite PostgreSQL )] },
67 has sqltargs => ( # configuration
70 default => sub { {} },
73 method install($new_version) {
74 carp 'Install not possible as versions table already exists in database'
75 if $self->is_installed;
77 $new_version ||= $self->schema_version;
82 $self->version_rs->create({
83 version => $new_version,
85 # upgrade_sql => $upgrade_sql,
90 method ordered_schema_versions { undef }
93 my $db_version = $self->db_version;
94 my $schema_version = $self->schema_version;
96 unless ($db_version) {
98 carp 'Upgrade not possible as database is unversioned. Please call install first.';
102 if ( $db_version eq $schema_version ) {
104 carp "Upgrade not necessary\n";
108 my @version_list = $self->ordered_schema_versions ||
109 ( $db_version, $schema_version );
111 # remove all versions in list above the required version
112 while ( @version_list && ( $version_list[-1] ne $schema_version ) ) {
116 # remove all versions in list below the current version
117 while ( @version_list && ( $version_list[0] ne $db_version ) ) {
121 # check we have an appropriate list of versions
122 die if @version_list < 2;
125 while ( @version_list >= 2 ) {
126 $self->upgrade_single_step( $version_list[0], $version_list[1] );
131 __PACKAGE__->meta->make_immutable;
137 vim: ts=2 sw=2 expandtab