if ( $fdata->{is_unique} ) {
push @{ $tdata->{constraints} }, { name => '', type => 'UNIQUE', fields => [ $fdata->{name} ] };
-# my $constraint = Constraint->new({ name => '', type => 'UNIQUE' });
-# $constraint->add_column($table->get_column($fdata->{name}));
-# $table->add_constraint($constraint);
}
for my $cdata ( @{ $fdata->{constraints} } ) {
for my $cdata ( @{ $tdata->{constraints} || [] } ) {
my $constraint;
if (uc $cdata->{type} eq 'PRIMARY_KEY') {
- $constraint = PrimaryKey->new({ name => $cdata->{name} || 'primary_key', table => $table });
- $constraint->add_column($table->get_column($_)) for @{$cdata->{fields}};
- $table->get_column($_)->is_primary_key(1) for @{$cdata->{fields}};
+ $constraint = PrimaryKey->new({ name => $cdata->{name} || '', table => $table });
+ $table->get_column($_)->is_primary_key(1) for @{$cdata->{fields}};
} elsif (uc $cdata->{type} eq 'FOREIGN_KEY') {
- $constraint = ForeignKey->new({ name => $cdata->{name} || 'foreign_key',
+ $constraint = ForeignKey->new({ name => $cdata->{name} || '',
table => $table,
reference_table => $cdata->{reference_table},
reference_columns => $cdata->{reference_fields},
$table->get_column($_)->is_foreign_key(1) for @{$cdata->{fields}};
$table->get_column($_)->foreign_key_reference($constraint) for @{$cdata->{fields}};
} else {
- $constraint = Constraint->new({ name => $cdata->{name} || 'constraint', type => uc $cdata->{type}, table => $table });
- $constraint->add_column($table->get_column($_)) for @{$cdata->{fields}};
+ $constraint = Constraint->new({ name => $cdata->{name} || '', type => uc $cdata->{type}, table => $table });
}
+ $constraint->add_column($table->get_column($_)) for @{$cdata->{fields}};
$table->add_constraint($constraint);
-
-# my $constraint = $table->add_constraint(
-# name => $cdata->{'name'},
-# type => $cdata->{'type'},
-# fields => $cdata->{'fields'},
-# reference_table => $cdata->{'reference_table'},
-# reference_fields => $cdata->{'reference_fields'},
-# match_type => $cdata->{'match_type'} || '',
-# on_delete => $cdata->{'on_delete'}
-# || $cdata->{'on_delete_do'},
-# on_update => $cdata->{'on_update'}
-# || $cdata->{'on_update_do'},
-# ) or die $table->error;
}
# After the constrains and PK/idxs have been created,