Commit | Line | Data |
b974984a |
1 | package DBIx::Class::DeploymentHandler; |
2 | |
3 | use Moose; |
4 | use Method::Signatures::Simple; |
12fdd461 |
5 | require DBIx::Class::Schema; # loaded for type constraint |
12fdd461 |
6 | require DBIx::Class::ResultSet; # loaded for type constraint |
e1f67607 |
7 | use Carp::Clan '^DBIx::Class::DeploymentHandler'; |
b974984a |
8 | |
334bced5 |
9 | with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod'; |
e70a1600 |
10 | with 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions'; |
2e68a8e1 |
11 | |
cf400f48 |
12 | BEGIN { |
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 |
23 | has 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 |
30 | has upgrade_directory => ( # configuration |
61847972 |
31 | isa => 'Str', |
32 | is => 'ro', |
33 | required => 1, |
4ea147c6 |
34 | default => 'sql', |
b974984a |
35 | ); |
36 | |
d3b45f46 |
37 | has backup_directory => ( # configuration |
61847972 |
38 | isa => 'Str', |
39 | is => 'ro', |
8bf3eee1 |
40 | predicate => 'has_backup_directory', |
b974984a |
41 | ); |
42 | |
d3b45f46 |
43 | has do_backup => ( # configuration |
61847972 |
44 | isa => 'Bool', |
45 | is => 'ro', |
46 | default => undef, |
b974984a |
47 | ); |
48 | |
12fdd461 |
49 | has 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 |
56 | has to_version => ( |
57 | is => 'ro', |
58 | lazy_build => 1, |
59 | ); |
60 | |
d3b45f46 |
61 | has 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 |
68 | has sqltargs => ( # configuration |
ecc3b6be |
69 | isa => 'HashRef', |
70 | is => 'ro', |
71 | default => sub { {} }, |
72 | ); |
73 | |
24f4524b |
74 | method 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) { |
d3b45f46 |
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 | |
b974984a |
91 | method upgrade { |
38bd9956 |
92 | while ( my $version_list = $self->next_version_set ) { |
24f4524b |
93 | $self->upgrade_single_step($version_list); |
b974984a |
94 | } |
95 | } |
96 | |
2e68a8e1 |
97 | __PACKAGE__->meta->make_immutable; |
98 | |
b974984a |
99 | 1; |
61847972 |
100 | |
101 | __END__ |
102 | |
2eaf903b |
103 | vim: ts=2 sw=2 expandtab |