I dont thing version storage can be in charge of installing itself
[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
973d060d 9with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod',
10 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions',
11 'DBIx::Class::DeploymentHandler::WithStandardVersionStorage';
2e68a8e1 12
cf400f48 13BEGIN {
14 use Moose::Util::TypeConstraints;
15 subtype 'DBIx::Class::DeploymentHandler::Databases'
16 => as 'ArrayRef[Str]';
17
18 coerce 'DBIx::Class::DeploymentHandler::Databases'
19 => from 'Str'
20 => via { [$_] };
21 no Moose::Util::TypeConstraints;
22}
23
b974984a 24has schema => (
61847972 25 isa => 'DBIx::Class::Schema',
26 is => 'ro',
27 required => 1,
b539a216 28 handles => ['schema_version'],
b974984a 29);
30
d3b45f46 31has upgrade_directory => ( # configuration
61847972 32 isa => 'Str',
33 is => 'ro',
34 required => 1,
4ea147c6 35 default => 'sql',
b974984a 36);
37
d3b45f46 38has backup_directory => ( # configuration
61847972 39 isa => 'Str',
40 is => 'ro',
8bf3eee1 41 predicate => 'has_backup_directory',
b974984a 42);
43
e217d19c 44has to_version => ( # configuration
38bd9956 45 is => 'ro',
e217d19c 46 lazy_build => 1, # builder comes from another role...
47 # which is... probably not how we want it
38bd9956 48);
49
b539a216 50sub _build_to_version { $_[0]->schema->schema_version }
51
d3b45f46 52has databases => ( # configuration
cf400f48 53 coerce => 1,
54 isa => 'DBIx::Class::DeploymentHandler::Databases',
55 is => 'ro',
9e401dc2 56 default => sub { [qw( MySQL SQLite PostgreSQL )] },
57);
58
d3b45f46 59has sqltargs => ( # configuration
ecc3b6be 60 isa => 'HashRef',
61 is => 'ro',
62 default => sub { {} },
63);
64
24f4524b 65method install {
12fdd461 66 carp 'Install not possible as versions table already exists in database'
973d060d 67 if $self->version_storage_is_installed;
b974984a 68
24f4524b 69 my $new_version = $self->to_version;
b974984a 70
71 if ($new_version) {
8a7847f1 72 $self->_deploy;
12fdd461 73
973d060d 74 $self->add_database_version({
61847972 75 version => $new_version,
76 # ddl => $ddl,
77 # upgrade_sql => $upgrade_sql,
12fdd461 78 });
b974984a 79 }
80}
81
7521a845 82sub upgrade {
c3aec7c9 83 my $self = shift;
84 while ( my $version_list = $self->next_version_set ) {
85 $self->_upgrade_single_step($version_list);
86
973d060d 87 $self->add_database_version({
c3aec7c9 88 version => $version_list->[-1],
89 # ddl => $ddl,
90 # upgrade_sql => $upgrade_sql,
91 });
b974984a 92 }
93}
94
e217d19c 95method backup { $self->storage->backup($self->backup_directory) }
96
2e68a8e1 97__PACKAGE__->meta->make_immutable;
98
b974984a 991;
61847972 100
101__END__
102
2eaf903b 103vim: ts=2 sw=2 expandtab