Use serialized sql instead of vanilla sql
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / DeployMethod / SQL / Translator / Deprecated.pm
CommitLineData
3c1b5ee8 1package DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::Deprecated;
2use Moose;
9deabd1f 3
4# ABSTRACT: (DEPRECATED) Use this if you are stuck in the past
5
3c1b5ee8 6use Method::Signatures::Simple;
7
42c2fec3 8use File::Spec::Functions;
1f0d0633 9require SQL::Translator::Diff;
42c2fec3 10
3c1b5ee8 11extends 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator',
12
42c2fec3 13method _ddl_schema_consume_filenames($type, $version) {
3885a58b 14 return [$self->_ddl_schema_produce_filename($type, $version)]
42c2fec3 15}
16
17method _ddl_schema_produce_filename($type, $version) {
3c1b5ee8 18 my $filename = ref $self->schema;
19 $filename =~ s/::/-/g;
20
42c2fec3 21 $filename = catfile(
91adde75 22 $self->script_directory, "$filename-$version-$type.sql"
3c1b5ee8 23 );
24
42c2fec3 25 return $filename;
3c1b5ee8 26}
27
42c2fec3 28method _ddl_schema_up_produce_filename($type, $versions, $dir) {
3c1b5ee8 29 my $filename = ref $self->schema;
30 $filename =~ s/::/-/g;
31
42c2fec3 32 $filename = catfile(
91adde75 33 $self->script_directory, "$filename-" . join( q(-), @{$versions} ) . "-$type.sql"
3c1b5ee8 34 );
35
42c2fec3 36 return $filename;
3c1b5ee8 37}
38
42c2fec3 39method _ddl_schema_up_consume_filenames($type, $versions) {
3885a58b 40 return [$self->_ddl_schema_up_produce_filename($type, $versions)]
42c2fec3 41}
42
1f0d0633 43method _generate_final_diff($source_schema, $dest_schema, $db, $sqltargs) {
44 scalar SQL::Translator::Diff::schema_diff(
45 $source_schema, $db,
46 $dest_schema, $db,
47 $sqltargs
48 )
49}
50
51method _default_read_sql_file_as_string($file) {
52 do { local( @ARGV, $/ ) = $file; <> } # slurp
53}
54
55method _generate_final_sql($sqlt) { scalar $sqlt->translate }
56
42c2fec3 57__PACKAGE__->meta->make_immutable;
58
3c1b5ee8 591;
3885a58b 60
e52174e3 61# vim: ts=2 sw=2 expandtab
62
3885a58b 63__END__
64
bcc72297 65=head1 DESCRIPTION
66
67All this module does is override a few parts of
68L<DBIx::Class::DeployMethd::SQL::Translator> so that the files generated with
69L<DBIx::Class::Schema::Versioned> will work with this out of the box.
70
71=head1 DEPRECATED
72
73I begrudgingly made this module (and other related modules) to keep porting
74from L<DBIx::Class::Schema::Versioned> relatively simple. I will make changes
75to ensure that it works with output from L<DBIx::Class::Schema::Versioned> etc,
76but I will not add any new features to it.
77
78Once I hit major version 1 usage of this module will emit a warning.
79On version 2 it will be removed entirely.
80
3885a58b 81=head1 THIS SUCKS
82
83Yeah, this old Deprecated thing is a drag. It can't do downgrades, it can only
84use a single .sql file for migrations, it has no .pl support. You should
85totally switch! Here's how:
86
87 my $init_part = ref $schema;
88 $init_part =~ s/::/-/g;
89 opendir my $dh, 'sql';
90 for (readdir $dh) {
91 if (/\Q$init_part\E-(.*)-(.*)(?:-(.*))?/) {
92 if (defined $3) {
93 cp $_, $dh->deploy_method->_ddl_schema_up_produce_filename($3, [$1, $2]);
94 } else {
95 cp $_, $dh->deploy_method->_ddl_schema_produce_filename($2, $1);
96 }
97 }
98 }
99
bcc72297 100=head1 OVERRIDDEN METHODS
101
102=over
103
104=item *
105
106L<DBIx::Class::DeployMethod::SQL::Translator/_ddl_schema_consume_filenames>
107
108=item *
109
110L<DBIx::Class::DeployMethod::SQL::Translator/_ddl_schema_produce_filename>
111
112=item *
113
114L<DBIx::Class::DeployMethod::SQL::Translator/_ddl_schema_up_produce_filename>
115
116=item *
117
118L<DBIx::Class::DeployMethod::SQL::Translator/_ddl_schema_up_consume_filenames>
119
120=back
121