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, |
b974984a |
27 | ); |
28 | |
d3b45f46 |
29 | has upgrade_directory => ( # configuration |
61847972 |
30 | isa => 'Str', |
31 | is => 'ro', |
32 | required => 1, |
4ea147c6 |
33 | default => 'sql', |
b974984a |
34 | ); |
35 | |
d3b45f46 |
36 | has backup_directory => ( # configuration |
61847972 |
37 | isa => 'Str', |
38 | is => 'ro', |
8bf3eee1 |
39 | predicate => 'has_backup_directory', |
b974984a |
40 | ); |
41 | |
12fdd461 |
42 | has 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 |
50 | has 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 |
56 | has 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 |
63 | has sqltargs => ( # configuration |
ecc3b6be |
64 | isa => 'HashRef', |
65 | is => 'ro', |
66 | default => sub { {} }, |
67 | ); |
68 | |
24f4524b |
69 | method 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 |
86 | sub 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 |
99 | method backup { $self->storage->backup($self->backup_directory) } |
100 | |
2e68a8e1 |
101 | __PACKAGE__->meta->make_immutable; |
102 | |
b974984a |
103 | 1; |
61847972 |
104 | |
105 | __END__ |
106 | |
2eaf903b |
107 | vim: ts=2 sw=2 expandtab |