1 package SQL::Translator::Parser::MySQL;
5 SQL::Translator::Parser::MySQL - parser for MySQL
10 use SQL::Translator::Parser::MySQL;
12 my $translator = SQL::Translator->new;
13 $translator->parser("SQL::Translator::Parser::MySQL");
17 The grammar is influenced heavily by Tim Bunce's "mysql2ora" grammar.
19 Here's the word from the MySQL site
20 (http://www.mysql.com/doc/en/CREATE_TABLE.html):
22 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
23 [table_options] [select_statement]
27 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name LIKE old_table_name;
30 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
31 [PRIMARY KEY] [reference_definition]
32 or PRIMARY KEY (index_col_name,...)
33 or KEY [index_name] (index_col_name,...)
34 or INDEX [index_name] (index_col_name,...)
35 or UNIQUE [INDEX] [index_name] (index_col_name,...)
36 or FULLTEXT [INDEX] [index_name] (index_col_name,...)
37 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
38 [reference_definition]
42 TINYINT[(length)] [UNSIGNED] [ZEROFILL]
43 or SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
44 or MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
45 or INT[(length)] [UNSIGNED] [ZEROFILL]
46 or INTEGER[(length)] [UNSIGNED] [ZEROFILL]
47 or BIGINT[(length)] [UNSIGNED] [ZEROFILL]
48 or REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
49 or DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
50 or FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
51 or DECIMAL(length,decimals) [UNSIGNED] [ZEROFILL]
52 or NUMERIC(length,decimals) [UNSIGNED] [ZEROFILL]
53 or CHAR(length) [BINARY]
54 or VARCHAR(length) [BINARY]
67 or ENUM(value1,value2,value3,...)
68 or SET(value1,value2,value3,...)
74 REFERENCES tbl_name [(index_col_name,...)]
75 [MATCH FULL | MATCH PARTIAL]
76 [ON DELETE reference_option]
77 [ON UPDATE reference_option]
80 RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT
83 TYPE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM }
84 or ENGINE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM }
87 or [ DEFAULT ] CHARACTER SET charset_name
89 or COLLATE collation_name
93 or PACK_KEYS = {0 | 1 | DEFAULT}
94 or PASSWORD = "string"
95 or DELAY_KEY_WRITE = {0 | 1}
96 or ROW_FORMAT= { default | dynamic | fixed | compressed }
97 or RAID_TYPE= {1 | STRIPED | RAID0 } RAID_CHUNKS=# RAID_CHUNKSIZE=#
98 or UNION = (table_name,[table_name...])
99 or INSERT_METHOD= {NO | FIRST | LAST }
100 or DATA DIRECTORY="absolute path to directory"
101 or INDEX DIRECTORY="absolute path to directory"
104 A subset of the ALTER TABLE syntax that allows addition of foreign keys:
106 ALTER [IGNORE] TABLE tbl_name alter_specification [, alter_specification] ...
109 ADD [CONSTRAINT [symbol]]
110 FOREIGN KEY [index_name] (index_col_name,...)
111 [reference_definition]
113 A subset of INSERT that we ignore:
119 This parser takes a single optional parser_arg C<mysql_parser_version>, which
120 provides the desired version for the target database. Any statement in the processed
121 dump file, that is commented with a version higher than the one supplied, will be stripped.
123 Valid version specifiers for C<mysql_parser_version> are listed L<here|SQL::Translator::Utils/parse_mysql_version>
125 More information about the MySQL comment-syntax: L<http://dev.mysql.com/doc/refman/5.0/en/comments.html>
133 our $VERSION = '1.59';
136 $DEBUG = 0 unless defined $DEBUG;
139 use Storable qw(dclone);
140 use DBI qw(:sql_types);
141 use SQL::Translator::Utils qw/parse_mysql_version ddl_parser_instance/;
143 use base qw(Exporter);
144 our @EXPORT_OK = qw(parse);
146 our %type_mapping = ();
148 use constant DEFAULT_PARSER_VERSION => 30000;
150 our $GRAMMAR = << 'END_OF_GRAMMAR';
153 my ( $database_name, %tables, $table_order, @table_comments, %views,
154 $view_order, %procedures, $proc_order );
159 # The "eofile" rule makes the parser fail if any "statement" rule
160 # fails. Otherwise, the first successful match by a "statement"
161 # won't cause the failure needed to know that the parse, as a whole,
164 startrule : statement(s) eofile {
166 database_name => $database_name,
169 procedures => \%procedures,
186 use : /use/i WORD "$delimiter"
188 $database_name = $item[2];
189 @table_comments = ();
192 set : /set/i /[^;]+/ "$delimiter"
193 { @table_comments = () }
195 drop : /drop/i TABLE /[^;]+/ "$delimiter"
197 drop : /drop/i WORD(s) "$delimiter"
198 { @table_comments = () }
205 # MySQL strings, unlike common SQL strings, can be double-quoted or
206 # single-quoted, and you can escape the delmiters by doubling (but only the
207 # delimiter) or by backslashing.
209 /'(\\.|''|[^\\\'])*'/ |
210 /"(\\.|""|[^\\\"])*"/
211 # For reference, std sql str: /(?:(?:\')(?:[^\']*(?:(?:\'\')[^\']*)*)(?:\'))//
213 nonstring : /[^;\'"]+/
215 statement_body : string | nonstring
217 insert : /insert/i statement_body(s?) "$delimiter"
219 delimiter : /delimiter/i /[\S]+/
220 { $delimiter = $item[2] }
222 empty_statement : "$delimiter"
224 alter : ALTER TABLE table_name alter_specification(s /,/) "$delimiter"
226 my $table_name = $item{'table_name'};
227 die "Cannot ALTER table '$table_name'; it does not exist"
228 unless $tables{ $table_name };
229 for my $definition ( @{ $item[4] } ) {
230 $definition->{'extra'}->{'alter'} = 1;
231 push @{ $tables{ $table_name }{'constraints'} }, $definition;
235 alter_specification : ADD foreign_key_def
236 { $return = $item[2] }
238 create : CREATE /database/i WORD "$delimiter"
239 { @table_comments = () }
241 create : CREATE TEMPORARY(?) TABLE opt_if_not_exists(?) table_name '(' create_definition(s /,/) /(,\s*)?\)/ table_option(s?) "$delimiter"
243 my $table_name = $item{'table_name'};
244 die "There is more than one definition for $table_name"
245 if ($tables{$table_name});
247 $tables{ $table_name }{'order'} = ++$table_order;
248 $tables{ $table_name }{'table_name'} = $table_name;
250 if ( @table_comments ) {
251 $tables{ $table_name }{'comments'} = [ @table_comments ];
252 @table_comments = ();
256 for my $definition ( @{ $item[7] } ) {
257 if ( $definition->{'supertype'} eq 'field' ) {
258 my $field_name = $definition->{'name'};
259 $tables{ $table_name }{'fields'}{ $field_name } =
260 { %$definition, order => $i };
263 if ( $definition->{'is_primary_key'} ) {
264 push @{ $tables{ $table_name }{'constraints'} },
266 type => 'primary_key',
267 fields => [ $field_name ],
272 elsif ( $definition->{'supertype'} eq 'constraint' ) {
273 push @{ $tables{ $table_name }{'constraints'} }, $definition;
275 elsif ( $definition->{'supertype'} eq 'index' ) {
276 push @{ $tables{ $table_name }{'indices'} }, $definition;
280 if ( my @options = @{ $item{'table_option(s?)'} } ) {
281 for my $option ( @options ) {
282 my ( $key, $value ) = each %$option;
283 if ( $key eq 'comment' ) {
284 push @{ $tables{ $table_name }{'comments'} }, $value;
287 push @{ $tables{ $table_name }{'table_options'} }, $option;
295 opt_if_not_exists : /if not exists/i
297 create : CREATE UNIQUE(?) /(index|key)/i index_name /on/i table_name '(' field_name(s /,/) ')' "$delimiter"
299 @table_comments = ();
300 push @{ $tables{ $item{'table_name'} }{'indices'} },
303 type => $item[2][0] ? 'unique' : 'normal',
309 create : CREATE /trigger/i NAME not_delimiter "$delimiter"
311 @table_comments = ();
314 create : CREATE PROCEDURE NAME not_delimiter "$delimiter"
316 @table_comments = ();
317 my $func_name = $item[3];
319 my $sql = "$item[1] $item[2] $item[3] $item[4]";
321 $procedures{ $func_name }{'order'} = ++$proc_order;
322 $procedures{ $func_name }{'name'} = $func_name;
323 $procedures{ $func_name }{'owner'} = $owner;
324 $procedures{ $func_name }{'sql'} = $sql;
327 PROCEDURE : /procedure/i
330 create : CREATE replace(?) algorithm(?) /view/i NAME not_delimiter "$delimiter"
332 @table_comments = ();
333 my $view_name = $item[5];
334 my $sql = join(q{ }, grep { defined and length } $item[1], $item[2]->[0], $item[3]->[0])
335 . " $item[4] $item[5] $item[6]";
337 # Hack to strip database from function calls in SQL
338 $sql =~ s#`\w+`\.(`\w+`\()##g;
340 $views{ $view_name }{'order'} = ++$view_order;
341 $views{ $view_name }{'name'} = $view_name;
342 $views{ $view_name }{'sql'} = $sql;
345 replace : /or replace/i
347 algorithm : /algorithm/i /=/ WORD
349 $return = "$item[1]=$item[3]";
352 not_delimiter : /.*?(?=$delimiter)/is
354 create_definition : constraint
360 comment : /^\s*(?:#|-{2}).*\n/
362 my $comment = $item[1];
363 $comment =~ s/^\s*(#|--)\s*//;
364 $comment =~ s/\s*$//;
368 comment : /\/\*/ /.*?\*\//s
370 my $comment = $item[2];
371 $comment = substr($comment, 0, -2);
372 $comment =~ s/^\s*|\s*$//g;
376 field_comment : /^\s*(?:#|-{2}).*\n/
378 my $comment = $item[1];
379 $comment =~ s/^\s*(#|--)\s*//;
380 $comment =~ s/\s*$//;
385 field_comment2 : /comment/i /'.*?'/
387 my $comment = $item[2];
395 field : field_comment(s?) field_name data_type field_qualifier(s?) field_comment2(?) reference_definition(?) on_update(?) field_comment(s?)
397 my %qualifiers = map { %$_ } @{ $item{'field_qualifier(s?)'} || [] };
398 if ( my @type_quals = @{ $item{'data_type'}{'qualifiers'} || [] } ) {
399 $qualifiers{ $_ } = 1 for @type_quals;
402 my $null = defined $qualifiers{'not_null'}
403 ? $qualifiers{'not_null'} : 1;
404 delete $qualifiers{'not_null'};
406 my @comments = ( @{ $item[1] }, @{ $item[5] }, @{ $item[8] } );
409 supertype => 'field',
410 name => $item{'field_name'},
411 data_type => $item{'data_type'}{'type'},
412 size => $item{'data_type'}{'size'},
413 list => $item{'data_type'}{'list'},
415 constraints => $item{'reference_definition(?)'},
416 comments => [ @comments ],
422 field_qualifier : not_null
425 null => $item{'not_null'},
429 field_qualifier : default_val
432 default => $item{'default_val'},
436 field_qualifier : auto_inc
439 is_auto_inc => $item{'auto_inc'},
443 field_qualifier : primary_key
446 is_primary_key => $item{'primary_key'},
450 field_qualifier : unsigned
453 is_unsigned => $item{'unsigned'},
457 field_qualifier : /character set/i WORD
460 'CHARACTER SET' => $item[2],
464 field_qualifier : /collate/i WORD
471 field_qualifier : /on update/i CURRENT_TIMESTAMP
474 'ON UPDATE' => $item[2],
478 field_qualifier : /unique/i KEY(?)
485 field_qualifier : KEY
492 reference_definition : /references/i table_name parens_field_list(?) match_type(?) on_delete(?) on_update(?)
495 type => 'foreign_key',
496 reference_table => $item[2],
497 reference_fields => $item[3][0],
498 match_type => $item[4][0],
499 on_delete => $item[5][0],
500 on_update => $item[6][0],
504 match_type : /match full/i { 'full' }
506 /match partial/i { 'partial' }
508 on_delete : /on delete/i reference_option
512 /on update/i 'CURRENT_TIMESTAMP'
515 /on update/i reference_option
518 reference_option: /restrict/i |
536 data_type : WORD parens_value_list(s?) type_qualifier(s?)
539 my $size; # field size, applicable only to non-set fields
540 my $list; # set list, applicable only to sets (duh)
542 if ( uc($type) =~ /^(SET|ENUM)$/ ) {
556 qualifiers => $item[3],
560 parens_field_list : '(' field_name(s /,/) ')'
563 parens_value_list : '(' VALUE(s /,/) ')'
566 type_qualifier : /(BINARY|UNSIGNED|ZEROFILL)/i
571 create_index : /create/i /index/i
573 not_null : /not/i /null/i
579 unsigned : /unsigned/i { $return = 0 }
582 /default/i 'CURRENT_TIMESTAMP'
589 $item[2] =~ s/^\s*'|'\s*$//g or $item[2] =~ s/^\s*"|"\s*$//g;
595 $item[2] =~ s/b['"]([01]+)['"]/$1/g;
599 /default/i /[\w\d:.-]+/
604 auto_inc : /auto_increment/i { 1 }
606 primary_key : /primary/i /key/i { 1 }
608 constraint : primary_key_def
613 foreign_key_def : foreign_key_def_begin parens_field_list reference_definition
616 supertype => 'constraint',
617 type => 'foreign_key',
620 %{ $item{'reference_definition'} },
624 foreign_key_def_begin : /constraint/i /foreign key/i WORD
625 { $return = $item[3] }
627 /constraint/i NAME /foreign key/i
628 { $return = $item[2] }
630 /constraint/i /foreign key/i
634 { $return = $item[2] }
639 primary_key_def : primary_key index_type(?) '(' name_with_opt_paren(s /,/) ')' index_type(?)
642 supertype => 'constraint',
643 type => 'primary_key',
645 options => $item[2][0] || $item[6][0],
648 # In theory, and according to the doc, names should not be allowed here, but
649 # MySQL accept (and ignores) them, so we are not going to be less :)
650 | primary_key index_name_not_using(?) '(' name_with_opt_paren(s /,/) ')' index_type(?)
653 supertype => 'constraint',
654 type => 'primary_key',
656 options => $item[6][0],
660 unique_key_def : UNIQUE KEY(?) index_name_not_using(?) index_type(?) '(' name_with_opt_paren(s /,/) ')' index_type(?)
663 supertype => 'constraint',
667 options => $item[4][0] || $item[8][0],
671 normal_index : KEY index_name_not_using(?) index_type(?) '(' name_with_opt_paren(s /,/) ')' index_type(?)
674 supertype => 'index',
678 options => $item[3][0] || $item[7][0],
682 index_name_not_using : QUOTED_NAME
683 | /(\b(?!using)\w+\b)/ { $return = ($1 =~ /^using/i) ? undef : $1 }
685 index_type : /using (btree|hash|rtree)/i { $return = uc $1 }
687 fulltext_index : /fulltext/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
690 supertype => 'index',
692 name => $item{'index_name(?)'}[0],
697 spatial_index : /spatial/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) ')'
700 supertype => 'index',
702 name => $item{'index_name(?)'}[0],
707 name_with_opt_paren : NAME parens_value_list(s?)
708 { $item[2][0] ? "$item[1]($item[2][0][0])" : $item[1] }
712 KEY : /key/i | /index/i
714 table_option : /comment/i /=/ /'.*?'/
716 my $comment = $item[3];
719 $return = { comment => $comment };
721 | /(default )?(charset|character set)/i /\s*=?\s*/ WORD
723 $return = { 'CHARACTER SET' => $item[3] };
727 $return = { 'COLLATE' => $item[2] }
729 | /union/i /\s*=\s*/ '(' table_name(s /,/) ')'
731 $return = { $item[1] => $item[4] };
733 | WORD /\s*=\s*/ MAYBE_QUOTED_WORD
735 $return = { $item[1] => $item[3] };
738 MAYBE_QUOTED_WORD: /\w+/
752 TEMPORARY : /temporary/i
766 QUOTED_NAME : BACKTICK /[^`]+/ BACKTICK
768 | DOUBLE_QUOTE /[^"]+/ DOUBLE_QUOTE
774 VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/
778 # remove leading/trailing quotes
780 $val =~ s/^['"]|['"]$//g;
786 CURRENT_TIMESTAMP : /current_timestamp(\(\))?/i
788 { 'CURRENT_TIMESTAMP' }
793 my ( $translator, $data ) = @_;
795 # Enable warnings within the Parse::RecDescent module.
796 local $::RD_ERRORS = 1 unless defined $::RD_ERRORS; # Make sure the parser dies when it encounters an error
797 local $::RD_WARN = 1 unless defined $::RD_WARN; # Enable warnings. This will warn on unused rules &c.
798 local $::RD_HINT = 1 unless defined $::RD_HINT; # Give out hints to help fix problems.
800 local $::RD_TRACE = $translator->trace ? 1 : undef;
801 local $DEBUG = $translator->debug;
803 my $parser = ddl_parser_instance('MySQL');
805 # Preprocess for MySQL-specific and not-before-version comments
807 my $parser_version = parse_mysql_version(
808 $translator->parser_args->{mysql_parser_version}, 'mysql'
809 ) || DEFAULT_PARSER_VERSION;
812 s#/\*!(\d{5})?(.*?)\*/#($1 && $1 > $parser_version ? '' : $2)#es
814 # do nothing; is there a better way to write this? -- ky
817 my $result = $parser->startrule($data);
818 return $translator->error( "Parse failed." ) unless defined $result;
819 warn "Parse result:".Dumper( $result ) if $DEBUG;
821 my $schema = $translator->schema;
822 $schema->name($result->{'database_name'}) if $result->{'database_name'};
825 $result->{'tables'}{ $a }{'order'}
827 $result->{'tables'}{ $b }{'order'}
828 } keys %{ $result->{'tables'} };
830 for my $table_name ( @tables ) {
831 my $tdata = $result->{tables}{ $table_name };
832 my $table = $schema->add_table(
833 name => $tdata->{'table_name'},
834 ) or die $schema->error;
836 $table->comments( $tdata->{'comments'} );
839 $tdata->{'fields'}->{$a}->{'order'}
841 $tdata->{'fields'}->{$b}->{'order'}
842 } keys %{ $tdata->{'fields'} };
844 for my $fname ( @fields ) {
845 my $fdata = $tdata->{'fields'}{ $fname };
846 my $field = $table->add_field(
847 name => $fdata->{'name'},
848 data_type => $fdata->{'data_type'},
849 size => $fdata->{'size'},
850 default_value => $fdata->{'default'},
851 is_auto_increment => $fdata->{'is_auto_inc'},
852 is_nullable => $fdata->{'null'},
853 comments => $fdata->{'comments'},
854 ) or die $table->error;
856 $table->primary_key( $field->name ) if $fdata->{'is_primary_key'};
858 for my $qual ( qw[ binary unsigned zerofill list collate ],
859 'character set', 'on update' ) {
860 if ( my $val = $fdata->{ $qual } || $fdata->{ uc $qual } ) {
861 next if ref $val eq 'ARRAY' && !@$val;
862 $field->extra( $qual, $val );
866 if ( $fdata->{'has_index'} ) {
870 fields => $fdata->{'name'},
871 ) or die $table->error;
874 if ( $fdata->{'is_unique'} ) {
875 $table->add_constraint(
878 fields => $fdata->{'name'},
879 ) or die $table->error;
882 for my $cdata ( @{ $fdata->{'constraints'} } ) {
883 next unless $cdata->{'type'} eq 'foreign_key';
884 $cdata->{'fields'} ||= [ $field->name ];
885 push @{ $tdata->{'constraints'} }, $cdata;
890 for my $idata ( @{ $tdata->{'indices'} || [] } ) {
891 my $index = $table->add_index(
892 name => $idata->{'name'},
893 type => uc $idata->{'type'},
894 fields => $idata->{'fields'},
895 ) or die $table->error;
898 if ( my @options = @{ $tdata->{'table_options'} || [] } ) {
900 my @ignore_opts = $translator->parser_args->{'ignore_opts'}
901 ? split( /,/, $translator->parser_args->{'ignore_opts'} )
904 my $ignores = { map { $_ => 1 } @ignore_opts };
905 foreach my $option (@options) {
906 # make sure the option isn't in ignore list
907 my ($option_key) = keys %$option;
908 if ( !exists $ignores->{$option_key} ) {
909 push @cleaned_options, $option;
913 @cleaned_options = @options;
915 $table->options( \@cleaned_options ) or die $table->error;
918 for my $cdata ( @{ $tdata->{'constraints'} || [] } ) {
919 my $constraint = $table->add_constraint(
920 name => $cdata->{'name'},
921 type => $cdata->{'type'},
922 fields => $cdata->{'fields'},
923 reference_table => $cdata->{'reference_table'},
924 reference_fields => $cdata->{'reference_fields'},
925 match_type => $cdata->{'match_type'} || '',
926 on_delete => $cdata->{'on_delete'}
927 || $cdata->{'on_delete_do'},
928 on_update => $cdata->{'on_update'}
929 || $cdata->{'on_update_do'},
930 ) or die $table->error;
933 # After the constrains and PK/idxs have been created,
934 # we normalize fields
935 normalize_field($_) for $table->get_fields;
938 my @procedures = sort {
939 $result->{procedures}->{ $a }->{'order'}
941 $result->{procedures}->{ $b }->{'order'}
942 } keys %{ $result->{procedures} };
944 for my $proc_name ( @procedures ) {
945 $schema->add_procedure(
947 owner => $result->{procedures}->{$proc_name}->{owner},
948 sql => $result->{procedures}->{$proc_name}->{sql},
952 $result->{views}->{ $a }->{'order'}
954 $result->{views}->{ $b }->{'order'}
955 } keys %{ $result->{views} };
957 for my $view_name ( @views ) {
960 sql => $result->{'views'}->{$view_name}->{sql},
967 # Takes a field, and returns
968 sub normalize_field {
970 my ($size, $type, $list, $unsigned, $changed);
972 $size = $field->size;
973 $type = $field->data_type;
974 $list = $field->extra->{list} || [];
975 $unsigned = defined($field->extra->{unsigned});
977 if ( !ref $size && $size eq 0 ) {
978 if ( lc $type eq 'tinyint' ) {
979 $changed = $size != 4 - $unsigned;
980 $size = 4 - $unsigned;
982 elsif ( lc $type eq 'smallint' ) {
983 $changed = $size != 6 - $unsigned;
984 $size = 6 - $unsigned;
986 elsif ( lc $type eq 'mediumint' ) {
987 $changed = $size != 9 - $unsigned;
988 $size = 9 - $unsigned;
990 elsif ( $type =~ /^int(eger)?$/i ) {
991 $changed = $size != 11 - $unsigned || $type ne 'int';
993 $size = 11 - $unsigned;
995 elsif ( lc $type eq 'bigint' ) {
996 $changed = $size != 20;
999 elsif ( lc $type =~ /(float|double|decimal|numeric|real|fixed|dec)/ ) {
1000 my $old_size = (ref $size || '') eq 'ARRAY' ? $size : [];
1001 $changed = @$old_size != 2
1002 || $old_size->[0] != 8
1003 || $old_size->[1] != 2;
1008 if ( $type =~ /^tiny(text|blob)$/i ) {
1009 $changed = $size != 255;
1012 elsif ( $type =~ /^(blob|text)$/i ) {
1013 $changed = $size != 65_535;
1016 elsif ( $type =~ /^medium(blob|text)$/i ) {
1017 $changed = $size != 16_777_215;
1020 elsif ( $type =~ /^long(blob|text)$/i ) {
1021 $changed = $size != 4_294_967_295;
1022 $size = 4_294_967_295;
1025 if ( $field->data_type =~ /(set|enum)/i && !$field->size ) {
1026 my %extra = $field->extra;
1028 for my $len ( map { length } @{ $extra{'list'} || [] } ) {
1029 $longest = $len if $len > $longest;
1032 $size = $longest if $longest;
1037 # We only want to clone the field, not *everything*
1039 local $field->{table} = undef;
1040 $field->parsed_field( dclone( $field ) );
1041 $field->parsed_field->{table} = $field->table;
1043 $field->size( $size );
1044 $field->data_type( $type );
1045 $field->sql_data_type( $type_mapping{ lc $type } )
1046 if exists $type_mapping{ lc $type };
1047 $field->extra->{list} = $list if @$list;
1053 # -------------------------------------------------------------------
1054 # Where man is not nature is barren.
1056 # -------------------------------------------------------------------
1062 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>,
1063 Chris Mungall E<lt>cjm@fruitfly.orgE<gt>.
1067 Parse::RecDescent, SQL::Translator::Schema.