$DEBUG = 0 unless defined $DEBUG;
$WARN = 0 unless defined $WARN;
-our %used_identifiers = ();
our $max_id_length = 30;
-our %global_names;
-our %truncated;
+my %global_names;
sub produce {
my $translator = shift;
debug("PKG: Beginning production\n");
+ %global_names = (); #reset
+
my @create = ();
push @create, header_comment unless ($no_comments);
$create[0] .= "\n\nBEGIN TRANSACTION" unless $no_txn;
# -------------------------------------------------------------------
sub mk_name {
- my ($basename, $type, $scope, $critical) = @_;
- my $basename_orig = $basename;
- my $max_name = !$max_id_length
- ? length($type) + 1
- : $type
- ? $max_id_length - (length($type) + 1)
- : $max_id_length;
- $basename = substr( $basename, 0, $max_name )
- if length( $basename ) > $max_name;
- $basename =~ s/\./_/g;
- my $name = $type ? "${type}_$basename" : $basename;
-
- if ( $basename ne $basename_orig and $critical ) {
- my $show_type = $type ? "+'$type'" : "";
- warn "Truncating '$basename_orig'$show_type to $max_id_length ",
- "character limit to make '$name'\n" if $WARN;
- $truncated{ $basename_orig } = $name;
- }
+ my ($name, $scope, $critical) = @_;
$scope ||= \%global_names;
if ( my $prev = $scope->{ $name } ) {
my ($index, $options) = @_;
my $name = $index->name;
- $name = mk_name($index->table->name, $name);
+ $name = mk_name($name);
my $type = $index->type eq 'UNIQUE' ? "UNIQUE " : '';
my ($c, $options) = @_;
my $name = $c->name;
- $name = mk_name($c->table->name, $name);
+ $name = mk_name($name);
my @fields = $c->fields;
(my $index_table_name = $c->table->name) =~ s/^.+?\.//; # table name may not specify schema
warn "removing schema name from '" . $c->table->name . "' to make '$index_table_name'\n" if $WARN;