Remove the length limit on identifiers - it doesn't belong in DBIx::Class
[dbsrgits/DBIx-Class.git] / lib / SQL / Translator / Parser / DBIx / Class.pm
index 1b6266f..4610e20 100644 (file)
@@ -96,28 +96,14 @@ sub parse {
         $table->primary_key($source->primary_columns);
 
         my @primary = $source->primary_columns;
-        foreach my $field (@primary) {
-          my $index = $table->add_index(
-                                        name   => $field,
-                                        fields => [$field],
-                                        type   => 'NORMAL',
-                                       );
-        }
         my %unique_constraints = $source->unique_constraints;
         foreach my $uniq (sort keys %unique_constraints) {
             if (!$source->compare_relationship_keys($unique_constraints{$uniq}, \@primary)) {
                 $table->add_constraint(
                             type             => 'unique',
-                            name             => _create_unique_symbol($uniq),
+                            name             => $uniq,
                             fields           => $unique_constraints{$uniq}
                 );
-
-               my $index = $table->add_index(
-                            name   => _create_unique_symbol(join('_', @{$unique_constraints{$uniq}})),
-                            fields => $unique_constraints{$uniq},
-                            type   => 'NORMAL',
-               );
-
             }
         }
 
@@ -179,9 +165,7 @@ sub parse {
                 if (scalar(@keys)) {
                   $table->add_constraint(
                                     type             => 'foreign_key',
-                                    name             => _create_unique_symbol($table->name
-                                                                            . '_fk_'
-                                                                            . join('_', @keys)),
+                                    name             => join('_', $table->name, 'fk', @keys),
                                     fields           => \@keys,
                                     reference_fields => \@refkeys,
                                     reference_table  => $rel_table,
@@ -191,7 +175,7 @@ sub parse {
                   );
                     
                   my $index = $table->add_index(
-                                    name   => _create_unique_symbol(join('_', @keys)),
+                                    name   => join('_', $table->name, 'idx', @keys),
                                     fields => \@keys,
                                     type   => 'NORMAL',
                   );
@@ -211,31 +195,4 @@ sub parse {
     return 1;
 }
 
-# TODO - is there a reasonable way to pass configuration?
-# Default of 64 comes from mysql's limit.
-our $MAX_SYMBOL_LENGTH    ||= 64;
-our $COLLISION_TAG_LENGTH ||= 8;
-
-# -------------------------------------------------------------------
-# $resolved_name = _create_unique_symbol($desired_name)
-#
-# If desired_name is really long, it will be truncated in a way that
-# has a high probability of leaving it unique.
-# -------------------------------------------------------------------
-sub _create_unique_symbol {
-    my $desired_name = shift;
-    return $desired_name if 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;
-}
-
 1;