refactor DeployMethod stuff
[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,
4ea147c6 27 handles => [qw( ddl_filename schema_version )],
b974984a 28);
29
d3b45f46 30has upgrade_directory => ( # configuration
61847972 31 isa => 'Str',
32 is => 'ro',
33 required => 1,
4ea147c6 34 default => 'sql',
b974984a 35);
36
d3b45f46 37has backup_directory => ( # configuration
61847972 38 isa => 'Str',
39 is => 'ro',
8bf3eee1 40 predicate => 'has_backup_directory',
b974984a 41);
42
d3b45f46 43has do_backup => ( # configuration
61847972 44 isa => 'Bool',
45 is => 'ro',
46 default => undef,
b974984a 47);
48
12fdd461 49has version_rs => (
61847972 50 isa => 'DBIx::Class::ResultSet',
51 is => 'ro',
52 lazy_build => 1,
53 handles => [qw( is_installed db_version )],
12fdd461 54);
55
38bd9956 56has to_version => (
57 is => 'ro',
58 lazy_build => 1,
59);
60
d3b45f46 61has databases => ( # configuration
cf400f48 62 coerce => 1,
63 isa => 'DBIx::Class::DeploymentHandler::Databases',
64 is => 'ro',
9e401dc2 65 default => sub { [qw( MySQL SQLite PostgreSQL )] },
66);
67
d3b45f46 68has sqltargs => ( # configuration
ecc3b6be 69 isa => 'HashRef',
70 is => 'ro',
71 default => sub { {} },
72);
73
24f4524b 74method install {
12fdd461 75 carp 'Install not possible as versions table already exists in database'
ceef4ff5 76 if $self->is_installed;
b974984a 77
24f4524b 78 my $new_version = $self->to_version;
b974984a 79
80 if ($new_version) {
8a7847f1 81 $self->_deploy;
12fdd461 82
83 $self->version_rs->create({
61847972 84 version => $new_version,
85 # ddl => $ddl,
86 # upgrade_sql => $upgrade_sql,
12fdd461 87 });
b974984a 88 }
89}
90
7521a845 91sub upgrade {
92 while ( my $version_list = $_[0]->next_version_set ) {
93 $_[0]->_upgrade_single_step($version_list);
b974984a 94 }
95}
96
2e68a8e1 97__PACKAGE__->meta->make_immutable;
98
b974984a 991;
61847972 100
101__END__
102
2eaf903b 103vim: ts=2 sw=2 expandtab