SQL-Admin
view release on metacpan or search on metacpan
t/02-driver-base-evaluate.t view on Meta::CPAN
} ],
}
});
{
ok (exists $cat->{table}{'bbb.aaa'}, 'alter table 2: exists');
my $obj = $cat->{table}{'bbb.aaa'};
ok ($obj->primary_key, 'alter table 2: primary key defined');
is ($obj->primary_key->fullname, 'bbb.aaa.primary_key.zzz.yyy', 'alter table 2: primary key name');
}
}
######################################################################
######################################################################
sub alter_table_unique { # ;
my $cat = $CAT->new;
$evl->evaluate ($cat, {
alter_table => {
table_name => { name => 'aaa', 'schema' => 'bbb' },
alter_table_actions => [ {
add_constraint => { unique_constraint => {
constraint_name => 'SQL051227180539060',
column_list => [ 'zzz', 'xxx' ]
} }
} ],
}});
{
ok (exists $cat->{table}{'bbb.aaa'}, 'alter table UQ-1: exists');
my $obj = $cat->{table}{'bbb.aaa'};
ok ($obj->unique, 'alter table UQ-1: unique defined');
my $map = $obj->unique;
is (ref $map, 'HASH', 'alter table UQ-1: unique is HASH');
my ($c) = values %$map;
is ($c->fullname, 'bbb.aaa.unique.zzz.xxx', 'alter table UQ-1: fullname');
is_deeply ($c->column_list, ['zzz', 'xxx'], 'alter table UQ-1: column list');
}
##################################################################
}
######################################################################
######################################################################
sub alter_table_foreign_key { # ;
my $cat = $CAT->new;
$evl->evaluate ($cat, {
alter_table => {
table_name => { name => 'aaa', 'schema' => 'bbb' },
alter_table_actions => [ {
add_constraint => { foreign_key_constraint => {
constraint_name => 'SQL050926155612920',
update_rule => 'no_action',
delete_rule => 'cascade',
referenced_table => { schema => 'bbb', name => 'rrr' },
referenced_column_list => [ 'zzz' ],
referencing_column_list => [ 'xxx' ]
} }
} ],
}
});
{
ok (exists $cat->{table}{'bbb.aaa'}, 'alter table FK-1: table exists');
my $obj = $cat->{table}{'bbb.aaa'};
ok ($obj->foreign_key, 'alter table FK-1: foreign_key defined');
my $map = $obj->foreign_key;
is (ref $map, 'HASH', 'alter table FK-1: foreign_key is HASH');
my ($c) = values %$map;
is ($c->fullname, 'bbb.aaa.foreign_key.xxx{bbb.rrr.zzz}', 'alter table FK-1: fullname');
is_deeply ($c->referenced_column_list, ['zzz'], 'alter table FK-1: referenced column list');
is_deeply ($c->referencing_column_list, ['xxx'], 'alter table FK-1: referencing column list');
is ($c->update_rule => 'no_action', 'alter table FK-1: update rule');
is ($c->delete_rule => 'cascade', 'alter table FK-1: delete rule');
}
}
######################################################################
######################################################################
sub alter_table_add_column { # ;
my $cat = $CAT->new;
$evl->evaluate ($cat, {
create_table => {
table_name => { name => 'aaa', schema => 'bbb' },
table_content => [ {
column_definition => {
column_name => 'caa',
data_type => 'int4',
column_not_null => 1,
}
} ],
}
}, {
alter_table => {
table_name => { name => 'aaa', schema => 'bbb' },
alter_table_actions => [ {
add_column => [ {
column_definition => {
data_type => 'int4',
column_not_null => 1,
column_name => 'operator_id',
default_clause => { integer => 0 }
}
} ]
} ]
},
});
}
######################################################################
######################################################################
sub main { # ;
create_sequence;
create_index;
create_table;
alter_table_set_hints;
alter_table_primary_key;
alter_table_unique;
alter_table_foreign_key;
alter_table_add_column;
# print Data::Dumper::Dumper ($cat);
}
######################################################################
######################################################################
main;
( run in 0.630 second using v1.01-cache-2.11-cpan-39bf76dae61 )