[DBIx-Class-Devel] [sql-translator] Don't create a superfluous index for FK that is PK (#56)

Dagfinn Ilmari Mannsåker notifications at github.com
Wed Jun 24 22:35:41 GMT 2015


> @@ -457,11 +457,17 @@ sub create_table
>      #
>      my @constraint_defs;
>      my @constraints = $table->get_constraints;
> +
> +    # Get the primary key, if there is one. No need to create an index for an
> +    # FK that is also the PK. It may be a multi-field key, so generate a
> +    # suitable string for comparison.
> +    my $pk = join "\0", map $_->fields, grep $_->type eq PRIMARY_KEY, @constraints;

Here you're joining all the fields in the primary key, but below you're testing that against the first field in the foreign key, so this can't work at all for composite primary keys.

I don't if the current handling is actually correct for compound indexes and foreign keys, but either way, I think primary keys should be handled the same as normal indexes (i.e. just add each field to `%indexed_fields`).

---
Reply to this email directly or view it on GitHub:
https://github.com/dbsrgits/sql-translator/pull/56/files#r33204957
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class-devel/attachments/20150624/6bc3493e/attachment.htm>


More information about the DBIx-Class-Devel mailing list