DeployMethod should not know anything about versioning
[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
12fdd461 42has version_rs => (
61847972 43 isa => 'DBIx::Class::ResultSet',
44 is => 'ro',
e217d19c 45 lazy_build => 1, # builder comes from another role...
46 # which is... probably not how we want it
47 handles => [qw( is_installed )],
12fdd461 48);
49
e217d19c 50has to_version => ( # configuration
38bd9956 51 is => 'ro',
e217d19c 52 lazy_build => 1, # builder comes from another role...
53 # which is... probably not how we want it
38bd9956 54);
55
d3b45f46 56has databases => ( # configuration
cf400f48 57 coerce => 1,
58 isa => 'DBIx::Class::DeploymentHandler::Databases',
59 is => 'ro',
9e401dc2 60 default => sub { [qw( MySQL SQLite PostgreSQL )] },
61);
62
d3b45f46 63has sqltargs => ( # configuration
ecc3b6be 64 isa => 'HashRef',
65 is => 'ro',
66 default => sub { {} },
67);
68
24f4524b 69method install {
12fdd461 70 carp 'Install not possible as versions table already exists in database'
ceef4ff5 71 if $self->is_installed;
b974984a 72
24f4524b 73 my $new_version = $self->to_version;
b974984a 74
75 if ($new_version) {
8a7847f1 76 $self->_deploy;
12fdd461 77
78 $self->version_rs->create({
61847972 79 version => $new_version,
80 # ddl => $ddl,
81 # upgrade_sql => $upgrade_sql,
12fdd461 82 });
b974984a 83 }
84}
85
7521a845 86sub upgrade {
c3aec7c9 87 my $self = shift;
88 while ( my $version_list = $self->next_version_set ) {
89 $self->_upgrade_single_step($version_list);
90
91 $self->version_rs->create({
92 version => $version_list->[-1],
93 # ddl => $ddl,
94 # upgrade_sql => $upgrade_sql,
95 });
b974984a 96 }
97}
98
e217d19c 99method backup { $self->storage->backup($self->backup_directory) }
100
2e68a8e1 101__PACKAGE__->meta->make_immutable;
102
b974984a 1031;
61847972 104
105__END__
106
2eaf903b 107vim: ts=2 sw=2 expandtab