X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer%2FSQL%2FMySQL.pm;h=55c1c0c09aa1d3b4e2c49bb0d303ce18e9ea28e6;hb=HEAD;hp=5b4167bd44c1bb1d3b069d0c1534382f9475dc5f;hpb=94f42333839a60b9b165bd1f23125503f6a3cda7;p=dbsrgits%2FSQL-Translator-2.0-ish.git diff --git a/lib/SQL/Translator/Producer/SQL/MySQL.pm b/lib/SQL/Translator/Producer/SQL/MySQL.pm index 5b4167b..55c1c0c 100644 --- a/lib/SQL/Translator/Producer/SQL/MySQL.pm +++ b/lib/SQL/Translator/Producer/SQL/MySQL.pm @@ -131,8 +131,8 @@ role SQL::Translator::Producer::SQL::MySQL { for my $meth (qw/table reference_table/) { my $table = $schema->get_table($c->$meth) || next; # This normalizes the types to ENGINE and returns the value if its there - next if $extra_to_options->($table, 'mysql_table_type', ['ENGINE', 'TYPE']); - $table->options({ 'ENGINE' => 'InnoDB' }); + next if $extra_to_options->($table, 'mysql_table_type', ['ENGINE', 'TYPE']); +# $table->options( [ { ENGINE => 'InnoDB' } ] ); } } # foreach constraints @@ -161,7 +161,7 @@ role SQL::Translator::Producer::SQL::MySQL { my $schema = $translator->schema; my $show_warnings = $translator->show_warnings || 0; my $producer_args = $translator->producer_args; - my $mysql_version = $self->parse_mysql_version ($producer_args->{mysql_version}, 'perl') || 0; + my $mysql_version = $translator->engine_version ($producer_args->{mysql_version}, 'perl') || 0; my $max_id_length = $producer_args->{mysql_max_id_length} || $DEFAULT_MAX_ID_LENGTH; my ($qt, $qf, $qc) = ('','', ''); @@ -208,9 +208,7 @@ role SQL::Translator::Producer::SQL::MySQL { }); } } - - - #warn "@table_defs\n"; + push @table_defs, "SET foreign_key_checks=1"; return wantarray ? ($create ? $create : (), @create, @table_defs) : ($create . join('', map { $_ ? "$_;\n\n" : () } (@create, @table_defs))); } @@ -253,13 +251,10 @@ role SQL::Translator::Producer::SQL::MySQL { if( my $sql = $view->sql ){ $create .= " AS (\n ${sql}\n )"; } - # $create .= ""; return $create; } method create_table($table, $options) { -# my ($table, $options) = @_; - my $qt = $options->{quote_table_names} || ''; my $qf = $options->{quote_field_names} || ''; @@ -338,7 +333,7 @@ role SQL::Translator::Producer::SQL::MySQL { my $collate = $table->extra->{'mysql_collate'}; my $union = undef; - for my $t1_option_ref ($table->_options) { + for my $t1_option_ref ($table->options) { my($key, $value) = %{$t1_option_ref}; $table_type_defined = 1 if uc $key eq 'ENGINE' or uc $key eq 'TYPE'; @@ -463,17 +458,16 @@ role SQL::Translator::Producer::SQL::MySQL { # Default? XXX Need better quoting! my $default = $field->default_value; -=cut - if ( defined $default ) { - SQL::Translator::Producer->_apply_default_value( - \$field_def, - $default, - [ - 'NULL' => \'NULL', - ], - ); - } -=cut + +# if ( defined $default ) { +# SQL::Translator::Producer->_apply_default_value( +# \$field_def, +# $default, +# [ +# 'NULL' => \'NULL', +# ], +# ); +# } if ( my $comments = $field->comments ) { $field_def .= qq[ comment '$comments']; @@ -803,62 +797,23 @@ HEADER_COMMENT return $header_comment; } - method parse_mysql_version($v?, $target?) { - return undef unless $v; + use constant COLLISION_TAG_LENGTH => 8; - $target ||= 'perl'; + method truncate_id_uniquely(Str $desired_name, Int $max_symbol_length) { + use Digest::SHA1 qw(sha1_hex); + return $desired_name + unless defined $desired_name && length $desired_name > $max_symbol_length; - my @vers; + my $truncated_name = substr $desired_name, 0, + $max_symbol_length - COLLISION_TAG_LENGTH - 1; - # X.Y.Z style - if ( $v =~ / ^ (\d+) \. (\d{1,3}) (?: \. (\d{1,3}) )? $ /x ) { - push @vers, $1, $2, $3; - } - - # XYYZZ (mysql) style - elsif ( $v =~ / ^ (\d) (\d{2}) (\d{2}) $ /x ) { - push @vers, $1, $2, $3; - } - - # XX.YYYZZZ (perl) style or simply X - elsif ( $v =~ / ^ (\d+) (?: \. (\d{3}) (\d{3}) )? $ /x ) { - push @vers, $1, $2, $3; - } - else { - #how do I croak sanely here? - die "Unparseable MySQL version '$v'"; - } + # Hex isn't the most space-efficient, but it skirts around allowed + # charset issues + my $digest = sha1_hex($desired_name); + my $collision_tag = substr $digest, 0, COLLISION_TAG_LENGTH; - if ($target eq 'perl') { - return sprintf ('%d.%03d%03d', map { $_ || 0 } (@vers) ); - } - elsif ($target eq 'mysql') { - return sprintf ('%d%02d%02d', map { $_ || 0 } (@vers) ); - } - else { - #how do I croak sanely here? - die "Unknown version target '$target'"; - } + return $truncated_name + . '_' + . $collision_tag; } - -use constant COLLISION_TAG_LENGTH => 8; - -method truncate_id_uniquely(Str $desired_name, Int $max_symbol_length) { - return $desired_name - unless defined $desired_name && length $desired_name > $max_symbol_length; - - my $truncated_name = substr $desired_name, 0, - $max_symbol_length - COLLISION_TAG_LENGTH - 1; - - # Hex isn't the most space-efficient, but it skirts around allowed - # charset issues - my $digest = sha1_hex($desired_name); - my $collision_tag = substr $digest, 0, COLLISION_TAG_LENGTH; - - return $truncated_name - . '_' - . $collision_tag; -} - - }