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