# 0.08_04 2006-11-10
# -----------------------------------------------------------
+* Patched MySQL producer to name constraints sanely, thanks Ash
* Added patch to Producer::DB2 to avoid dependency issues with foreign keys
* Added patch to remove single quotes for numeric default values in Producer::DB2
* Fixed Parser::SQLite to require a semicolon after a create trigger statement
package SQL::Translator::Producer::MySQL;
# -------------------------------------------------------------------
-# $Id: MySQL.pm,v 1.51 2006-11-09 18:19:05 schiffbruechige Exp $
+# $Id: MySQL.pm,v 1.52 2006-11-27 19:28:04 schiffbruechige Exp $
# -------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
use strict;
use warnings;
use vars qw[ $VERSION $DEBUG ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.51 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.52 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
{
my ($c, $options) = @_;
- my $qf = $options->{quote_field_names} || '';
- my $qt = $options->{quote_table_names} || '';
+ my $qf = $options->{quote_field_names} || '';
+ my $qt = $options->{quote_table_names} || '';
+ my $counter = ($options->{fk_name_counter} ||= {});
my @fields = $c->fields or next;
# Make sure FK field is indexed or MySQL complains.
#
+ $counter->{$c->table} ||= {};
my $def = join(' ',
- map { $_ || () } 'CONSTRAINT', $qt . $c->table . '_' . $c->name . $qt, 'FOREIGN KEY'
- );
+ map { $_ || () }
+ 'CONSTRAINT',
+ $qt . join('_', $c->table,
+ $c->name,
+ ($counter->{$c->table}{$c->name}++ || ())
+ ) . $qt,
+ 'FOREIGN KEY'
+ );
$def .= ' ('.$qf . join( "$qf, $qf", @fields ) . $qf . ')';
data_type: int
order: 1
is_not_null: 1
+ foo2:
+ name: foo2
+ data_type: int
+ order: 2
+ is_not_null: 1
constraints:
- type: PRIMARY_KEY
fields:
type: FOREIGN_KEY
fields: foo
name: fk_thing
+ - reference_table: thing
+ type: FOREIGN_KEY
+ fields: foo2
+ name: fk_thing
EOSCHEMA
"CREATE TABLE `thing2` (
`id` integer,
`foo` integer,
+ `foo2` integer,
INDEX (`id`),
INDEX (`foo`),
+ INDEX (`foo2`),
PRIMARY KEY (`id`, `foo`),
- CONSTRAINT `thing2_fk_thing` FOREIGN KEY (`foo`) REFERENCES `thing` (`id`)
+ CONSTRAINT `thing2_fk_thing` FOREIGN KEY (`foo`) REFERENCES `thing` (`id`),
+ CONSTRAINT `thing2_fk_thing_1` FOREIGN KEY (`foo2`) REFERENCES `thing` (`id`)
) Type=InnoDB;\n\n",
"SET foreign_key_checks=1;\n\n"