[Dbix-class] SQL::Translator 0.08 Unique/Index clash problem

Jon jon+dbix at youramigo.com
Wed Jan 31 04:06:28 GMT 2007


With SQL::Translator 0.07, a DBIx::Class declaration such as this:

__PACKAGE__->add_columns('plugin_id' => {
                             'data_type' => 'integer',
			     'is_nullable' => 0,
			     'is_auto_increment' => 1,
			 },
			 'class' => {
                             'data_type' => 'varchar',
			     'size' => 100,
			     'is_nullable' => 0,
			     'is_auto_increment' => 0,
			 },
			 );
__PACKAGE__->set_primary_key('plugin_id');
__PACKAGE__->add_unique_constraint('class' => [ 'class' ]);

would result in SQL that looks like this:

  plugin_id integer NOT NULL auto_increment,
  class varchar(100) NOT NULL,
  PRIMARY KEY (plugin_id),
  UNIQUE (class)

and life was good.  After upgrading to SQL::Translator 0.08, I get:

  `plugin_id` integer NOT NULL auto_increment,
  `class` varchar(100) NOT NULL,
  INDEX (`plugin_id`),
  INDEX (`class`),
  PRIMARY KEY (`plugin_id`),
  UNIQUE `class` (`class`)

which results in the error:

Duplicate key name 'class' at /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Storage/DBI.pm line 1120.

If I change the name of the key to class_xx, I get

  `plugin_id` integer NOT NULL auto_increment,
  `class` varchar(100) NOT NULL,
  INDEX (`plugin_id`),
  INDEX (`class`),
  PRIMARY KEY (`plugin_id`),
  UNIQUE `class_xx` (`class`)

which is gets around the error but is wasteful of MySQL resources.

It seems to me that the old version got it right, and the new one is
wrong.

I have the same problem whether using SQL::Translator directly or using
the 'deploy' method.

I don't really know whether its a problem with SQL::Translator or the
way DBIx::Class uses it, so here I am appealing to the wisdom of the
list.

Other than downgrading to 0.07, is anyone aware of a fix for this?

Thanks,






More information about the Dbix-class mailing list