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 | |
41863428 |
9 | use DBIx::Class::DeploymentHandler::Types; |
973d060d |
10 | with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod', |
11 | 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions', |
12 | 'DBIx::Class::DeploymentHandler::WithStandardVersionStorage'; |
2e68a8e1 |
13 | |
cf400f48 |
14 | |
b974984a |
15 | has schema => ( |
61847972 |
16 | isa => 'DBIx::Class::Schema', |
17 | is => 'ro', |
18 | required => 1, |
b539a216 |
19 | handles => ['schema_version'], |
b974984a |
20 | ); |
21 | |
d3b45f46 |
22 | has upgrade_directory => ( # configuration |
61847972 |
23 | isa => 'Str', |
24 | is => 'ro', |
25 | required => 1, |
4ea147c6 |
26 | default => 'sql', |
b974984a |
27 | ); |
28 | |
d3b45f46 |
29 | has backup_directory => ( # configuration |
61847972 |
30 | isa => 'Str', |
31 | is => 'ro', |
8bf3eee1 |
32 | predicate => 'has_backup_directory', |
b974984a |
33 | ); |
34 | |
e217d19c |
35 | has to_version => ( # configuration |
38bd9956 |
36 | is => 'ro', |
6bbb6ce7 |
37 | lazy_build => 1, |
38bd9956 |
38 | ); |
39 | |
b539a216 |
40 | sub _build_to_version { $_[0]->schema->schema_version } |
41 | |
d3b45f46 |
42 | has databases => ( # configuration |
cf400f48 |
43 | coerce => 1, |
44 | isa => 'DBIx::Class::DeploymentHandler::Databases', |
45 | is => 'ro', |
9e401dc2 |
46 | default => sub { [qw( MySQL SQLite PostgreSQL )] }, |
47 | ); |
48 | |
d3b45f46 |
49 | has sqltargs => ( # configuration |
ecc3b6be |
50 | isa => 'HashRef', |
51 | is => 'ro', |
52 | default => sub { {} }, |
53 | ); |
54 | |
24f4524b |
55 | method install { |
84afdcb3 |
56 | croak 'Install not possible as versions table already exists in database' |
973d060d |
57 | if $self->version_storage_is_installed; |
b974984a |
58 | |
566925df |
59 | my $ddl = $self->_deploy; |
b974984a |
60 | |
566925df |
61 | $self->version_storage->add_database_version({ |
62 | version => $self->to_version, |
63 | ddl => $ddl, |
64 | }); |
b974984a |
65 | } |
66 | |
7521a845 |
67 | sub upgrade { |
c3aec7c9 |
68 | my $self = shift; |
69 | while ( my $version_list = $self->next_version_set ) { |
70 | $self->_upgrade_single_step($version_list); |
71 | |
973d060d |
72 | $self->add_database_version({ |
c3aec7c9 |
73 | version => $version_list->[-1], |
74 | # ddl => $ddl, |
75 | # upgrade_sql => $upgrade_sql, |
76 | }); |
b974984a |
77 | } |
78 | } |
79 | |
e217d19c |
80 | method backup { $self->storage->backup($self->backup_directory) } |
81 | |
2e68a8e1 |
82 | __PACKAGE__->meta->make_immutable; |
83 | |
b974984a |
84 | 1; |
61847972 |
85 | |
86 | __END__ |
87 | |
2eaf903b |
88 | vim: ts=2 sw=2 expandtab |