mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-31 20:38:55 -06:00
adding tests
This commit is contained in:
@@ -247,8 +247,8 @@ func (t tabularDiffWriter) WriteSchemaDiff(ctx context.Context, toRoot *doltdb.R
|
||||
cli.Println(textdiff.LineDiff(fromCreateStmt, toCreateStmt))
|
||||
}
|
||||
|
||||
if len(td.FromFks) > 0 || len(td.ToFks) > 0 {
|
||||
for _, fk := range td.FromFks {
|
||||
for _, fk := range td.ToFks {
|
||||
if len(fk.ReferencedTableColumns) > 0 {
|
||||
cli.Println(fmt.Sprintf("resolved foreign key `%s` on table `%s`", fk.Name, fk.TableName))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,12 +449,97 @@ EOF
|
||||
[[ ! "$output" =~ "+ | 0" ]] || false
|
||||
}
|
||||
|
||||
@test "diff: with foreign key checks disabled" {
|
||||
@test "diff: new foreign key added and resolved" {
|
||||
dolt sql <<SQL
|
||||
create table parent (i int primary key);
|
||||
create table child (j int primary key, foreign key (j) references parent (i));
|
||||
SQL
|
||||
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ 'resolved foreign key' ]] || false
|
||||
}
|
||||
|
||||
@test "diff: new foreign key added and not resolved" {
|
||||
dolt sql <<SQL
|
||||
set foreign_key_checks=0;
|
||||
create table child (j int primary key, foreign key (j) references parent (i));
|
||||
create table parent (i int primary key);
|
||||
create table child (j int primary key, foreign key (j) references parent (i));
|
||||
SQL
|
||||
dolt add -A
|
||||
dolt commit -m "init commit"
|
||||
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ 'resolved foreign key' ]] || false
|
||||
}
|
||||
|
||||
@test "diff: existing foreign key that was resolved is deleted" {
|
||||
dolt sql <<SQL
|
||||
create table parent (i int primary key);
|
||||
create table child (j int primary key, constraint fk foreign key (j) references parent (i));
|
||||
SQL
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ 'resolved foreign key' ]] || false
|
||||
|
||||
dolt add -A
|
||||
dolt commit -m "init commit"
|
||||
dolt sql -q "alter table child drop foreign key fk"
|
||||
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ 'resolved foreign key' ]] || false
|
||||
}
|
||||
|
||||
@test "diff: existing foreign key that was not resolved is deleted" {
|
||||
dolt sql <<SQL
|
||||
set foreign_key_checks=0;
|
||||
create table parent (i int primary key);
|
||||
create table child (j int primary key, constraint fk foreign key (j) references parent (i));
|
||||
SQL
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ 'resolved foreign key' ]] || false
|
||||
|
||||
dolt add -A
|
||||
dolt commit -m "init commit"
|
||||
dolt sql -q "alter table child drop foreign key fk"
|
||||
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ 'resolved foreign key' ]] || false
|
||||
}
|
||||
|
||||
@test "diff: existing foreign key that was resolved is modified" {
|
||||
dolt sql <<SQL
|
||||
create table parent (i int primary key);
|
||||
create table child (j int primary key, constraint fk foreign key (j) references parent (i));
|
||||
SQL
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ 'resolved foreign key' ]] || false
|
||||
|
||||
dolt add -A
|
||||
dolt commit -m "init commit"
|
||||
dolt sql -q "alter table child drop foreign key fk"
|
||||
dolt sql -q "alter table child add constraint fk foreign key (j) references parent (i)"
|
||||
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ 'resolved foreign key' ]] || false
|
||||
}
|
||||
|
||||
@test "diff: existing foreign key is resolved" {
|
||||
dolt sql <<SQL
|
||||
set foreign_key_checks=0;
|
||||
create table parent (i int primary key);
|
||||
create table child (j int primary key, constraint fk foreign key (j) references parent (i));
|
||||
SQL
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ 'resolved foreign key' ]] || false
|
||||
|
||||
dolt add -A
|
||||
dolt commit -m "init commit"
|
||||
dolt sql -q "delete from parent where i = 0"
|
||||
|
||||
Reference in New Issue
Block a user