insert ddl into database; fix tests to ingore that
[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',
6bbb6ce7 46 lazy_build => 1,
38bd9956 47);
48
b539a216 49sub _build_to_version { $_[0]->schema->schema_version }
50
d3b45f46 51has databases => ( # configuration
cf400f48 52 coerce => 1,
53 isa => 'DBIx::Class::DeploymentHandler::Databases',
54 is => 'ro',
9e401dc2 55 default => sub { [qw( MySQL SQLite PostgreSQL )] },
56);
57
d3b45f46 58has sqltargs => ( # configuration
ecc3b6be 59 isa => 'HashRef',
60 is => 'ro',
61 default => sub { {} },
62);
63
24f4524b 64method install {
12fdd461 65 carp 'Install not possible as versions table already exists in database'
973d060d 66 if $self->version_storage_is_installed;
b974984a 67
566925df 68 my $ddl = $self->_deploy;
b974984a 69
566925df 70 $self->version_storage->add_database_version({
71 version => $self->to_version,
72 ddl => $ddl,
73 });
b974984a 74}
75
7521a845 76sub upgrade {
c3aec7c9 77 my $self = shift;
78 while ( my $version_list = $self->next_version_set ) {
79 $self->_upgrade_single_step($version_list);
80
973d060d 81 $self->add_database_version({
c3aec7c9 82 version => $version_list->[-1],
83 # ddl => $ddl,
84 # upgrade_sql => $upgrade_sql,
85 });
b974984a 86 }
87}
88
e217d19c 89method backup { $self->storage->backup($self->backup_directory) }
90
2e68a8e1 91__PACKAGE__->meta->make_immutable;
92
b974984a 931;
61847972 94
95__END__
96
2eaf903b 97vim: ts=2 sw=2 expandtab