comments for clarity and move backup stuff out of DM
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler.pm
CommitLineData
b974984a 1package DBIx::Class::DeploymentHandler;
2
3use Moose;
4use Method::Signatures::Simple;
12fdd461 5require DBIx::Class::Schema; # loaded for type constraint
12fdd461 6require DBIx::Class::ResultSet; # loaded for type constraint
e1f67607 7use Carp::Clan '^DBIx::Class::DeploymentHandler';
b974984a 8
334bced5 9with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod';
e70a1600 10with 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions';
2e68a8e1 11
cf400f48 12BEGIN {
13 use Moose::Util::TypeConstraints;
14 subtype 'DBIx::Class::DeploymentHandler::Databases'
15 => as 'ArrayRef[Str]';
16
17 coerce 'DBIx::Class::DeploymentHandler::Databases'
18 => from 'Str'
19 => via { [$_] };
20 no Moose::Util::TypeConstraints;
21}
22
b974984a 23has schema => (
61847972 24 isa => 'DBIx::Class::Schema',
25 is => 'ro',
26 required => 1,
b974984a 27);
28
d3b45f46 29has upgrade_directory => ( # configuration
61847972 30 isa => 'Str',
31 is => 'ro',
32 required => 1,
4ea147c6 33 default => 'sql',
b974984a 34);
35
d3b45f46 36has backup_directory => ( # configuration
61847972 37 isa => 'Str',
38 is => 'ro',
8bf3eee1 39 predicate => 'has_backup_directory',
b974984a 40);
41
d3b45f46 42has do_backup => ( # configuration
61847972 43 isa => 'Bool',
44 is => 'ro',
45 default => undef,
b974984a 46);
47
12fdd461 48has version_rs => (
61847972 49 isa => 'DBIx::Class::ResultSet',
50 is => 'ro',
e217d19c 51 lazy_build => 1, # builder comes from another role...
52 # which is... probably not how we want it
53 handles => [qw( is_installed )],
12fdd461 54);
55
e217d19c 56has to_version => ( # configuration
38bd9956 57 is => 'ro',
e217d19c 58 lazy_build => 1, # builder comes from another role...
59 # which is... probably not how we want it
38bd9956 60);
61
d3b45f46 62has databases => ( # configuration
cf400f48 63 coerce => 1,
64 isa => 'DBIx::Class::DeploymentHandler::Databases',
65 is => 'ro',
9e401dc2 66 default => sub { [qw( MySQL SQLite PostgreSQL )] },
67);
68
d3b45f46 69has sqltargs => ( # configuration
ecc3b6be 70 isa => 'HashRef',
71 is => 'ro',
72 default => sub { {} },
73);
74
24f4524b 75method install {
12fdd461 76 carp 'Install not possible as versions table already exists in database'
ceef4ff5 77 if $self->is_installed;
b974984a 78
24f4524b 79 my $new_version = $self->to_version;
b974984a 80
81 if ($new_version) {
8a7847f1 82 $self->_deploy;
12fdd461 83
84 $self->version_rs->create({
61847972 85 version => $new_version,
86 # ddl => $ddl,
87 # upgrade_sql => $upgrade_sql,
12fdd461 88 });
b974984a 89 }
90}
91
7521a845 92sub upgrade {
93 while ( my $version_list = $_[0]->next_version_set ) {
94 $_[0]->_upgrade_single_step($version_list);
b974984a 95 }
96}
97
e217d19c 98method backup { $self->storage->backup($self->backup_directory) }
99
2e68a8e1 100__PACKAGE__->meta->make_immutable;
101
b974984a 1021;
61847972 103
104__END__
105
2eaf903b 106vim: ts=2 sw=2 expandtab