From: Ash Berlin Date: Thu, 31 Jan 2008 11:37:09 +0000 (+0000) Subject: Document significance of preproces_schema method X-Git-Tag: v0.11008~345 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=934e1b39156523c2bcf1d4de8f426458df864f01;p=dbsrgits%2FSQL-Translator.git Document significance of preproces_schema method --- diff --git a/META.yml b/META.yml index 06f6236..48dcb35 100644 --- a/META.yml +++ b/META.yml @@ -236,7 +236,7 @@ provides: Test::SQL::Translator: file: lib/Test/SQL/Translator.pm version: 1.08 -generated_by: Module::Build version 0.28 +generated_by: Module::Build version 0.2808 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 diff --git a/lib/SQL/Translator/Diff.pm b/lib/SQL/Translator/Diff.pm index 3f71bfa..5cbb0b0 100644 --- a/lib/SQL/Translator/Diff.pm +++ b/lib/SQL/Translator/Diff.pm @@ -79,8 +79,8 @@ sub compute_differences { die $@ if $@; if (my $preprocess = $producer_class->can('preprocess_schema')) { - $producer_class->$preprocess($source_schema); - $producer_class->$preprocess($target_schema); + $preprocess->($source_schema); + $preprocess->($target_schema); } my %src_tables_checked = (); @@ -482,9 +482,6 @@ thrown. =item * C (optional) - -=back - If the producer supports C, it will be called with the table to alter and a hash, the keys of which will be the method names listed above; values will be arrays of fields or constraints to operate on. In the @@ -498,11 +495,31 @@ I.e. the hash might look something like the following: alter_field => [ [$old_field, $new_field] ] } + +=item * C (optional) + +C is called by the Diff code to allow the producer to +normalize any data it needs to first. For example, the MySQL producer uses +this method to ensure that FK contraint names are unique. + +Basicaly any changes that need to be made to produce the SQL file for the +schema should be done here, so that a diff between a parsed SQL file and (say) +a parsed DBIx::Class::Schema object will be sane. + +(As an aside, DBIx::Class, for instance, uses the presence of a +C function on the producer to know that it can diff between +the previous SQL file and its own internal representation. Without this method +on th producer it will diff the two SQL files which is slower, but known to +work better on old-style producers.) + +=back + + =head1 AUTHOR Original Author(s) unknown. -Refactor and more comprehensive tests by Ash Berlin C<< ash@cpan.org >>. +Refactor/re-write and more comprehensive tests by Ash Berlin C<< ash@cpan.org >>. Redevelopment sponsored by Takkle Inc. diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index 4bf2b65..9b65bb7 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -126,7 +126,7 @@ my %translate = ( sub preprocess_schema { - my ($class, $schema) = @_; + my ($schema) = @_; # extra->{mysql_table_type} used to be the type. It belongs in options, so # move it if we find it. Return Engine type if found in extra or options @@ -226,7 +226,7 @@ sub produce { # \todo Don't set if MySQL 3.x is set on command line $create .= "SET foreign_key_checks=0;\n\n"; - __PACKAGE__->preprocess_schema($schema); + preprocess_schema($schema); # # Generate sql diff --git a/lib/SQL/Translator/Producer/SQLite.pm b/lib/SQL/Translator/Producer/SQLite.pm index 149ba7b..a228653 100644 --- a/lib/SQL/Translator/Producer/SQLite.pm +++ b/lib/SQL/Translator/Producer/SQLite.pm @@ -423,6 +423,9 @@ sub rename_table { } +# No-op. Just here to signify that we are a new style parser. +sub preproces_schema { } + 1; =pod