mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-20 11:22:31 -05:00
Merge pull request #2194 from dolthub/zachmu/fk-checks-test
Added a test for disabling foreign keys during SQL export
This commit is contained in:
@@ -196,9 +196,9 @@ func valueAsSqlString(ti typeinfo.TypeInfo, value types.Value) (string, error) {
|
||||
return "TRUE", nil
|
||||
}
|
||||
return "FALSE", nil
|
||||
case typeinfo.UuidTypeIdentifier, typeinfo.TimeTypeIdentifier, typeinfo.YearTypeIdentifier, typeinfo.DatetimeTypeIdentifier, typeinfo.EnumTypeIdentifier:
|
||||
case typeinfo.UuidTypeIdentifier, typeinfo.TimeTypeIdentifier, typeinfo.YearTypeIdentifier, typeinfo.DatetimeTypeIdentifier:
|
||||
return singleQuote + *str + singleQuote, nil
|
||||
case typeinfo.BlobStringTypeIdentifier, typeinfo.VarBinaryTypeIdentifier, typeinfo.InlineBlobTypeIdentifier:
|
||||
case typeinfo.BlobStringTypeIdentifier, typeinfo.VarBinaryTypeIdentifier, typeinfo.InlineBlobTypeIdentifier, typeinfo.JSONTypeIdentifier, typeinfo.EnumTypeIdentifier, typeinfo.SetTypeIdentifier:
|
||||
return quoteAndEscapeString(*str), nil
|
||||
case typeinfo.VarStringTypeIdentifier:
|
||||
s, ok := value.(types.String)
|
||||
|
||||
@@ -127,9 +127,85 @@ if rows[2] != "9,8,7,6,5,4".split(","):
|
||||
dolt sql < export.sql
|
||||
|
||||
run dolt status
|
||||
|
||||
[[ "$output" =~ "working tree clean" ]] || false
|
||||
|
||||
# set columns
|
||||
dolt sql <<SQL
|
||||
create table sets (a varchar(10) primary key, b set('one','two','three'));
|
||||
insert into sets values ('abc', 'one,two'), ('def', 'two,three');
|
||||
SQL
|
||||
|
||||
dolt commit -am "Checkpoint"
|
||||
|
||||
dolt table export sets -f export.sql
|
||||
dolt sql < export.sql
|
||||
|
||||
run dolt status
|
||||
|
||||
[[ "$output" =~ "working tree clean" ]] || false
|
||||
|
||||
# json columns
|
||||
dolt sql -q "create table json_vals (a varchar(10) primary key, b json)"
|
||||
dolt sql <<SQL
|
||||
insert into json_vals values ('abc', '{"key": "value"}'), ('def', '[{"a": "b"},{"conjuction": "it\'s"}]');
|
||||
SQL
|
||||
dolt commit -am "Checkpoint"
|
||||
|
||||
dolt table export json_vals -f export.sql
|
||||
dolt sql < export.sql
|
||||
|
||||
run dolt status
|
||||
|
||||
[[ "$output" =~ "working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "export-tables: broken SQL escaping" {
|
||||
dolt sql <<SQL
|
||||
create table sets (a varchar(10) primary key, b set('one','two','three\'s'));
|
||||
insert into sets values ('abc', 'one,two'), ('def', 'two,three\'s');
|
||||
SQL
|
||||
|
||||
dolt commit -am "Checkpoint"
|
||||
|
||||
dolt table export sets -f export.sql
|
||||
|
||||
skip "Export embeds single quote in string without escaping it https://github.com/dolthub/dolt/issues/2197"
|
||||
|
||||
dolt sql < export.sql
|
||||
|
||||
run dolt status
|
||||
|
||||
[[ "$output" =~ "working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "export-tables: SQL with foreign keys" {
|
||||
dolt sql <<SQL
|
||||
create table one (a int primary key, b int);
|
||||
create table two (c int primary key, d int);
|
||||
insert into one values (1,1), (2,2);
|
||||
insert into two values (1,1), (2,2);
|
||||
alter table one add foreign key (b) references two (c);
|
||||
alter table two add foreign key (d) references one (a);
|
||||
SQL
|
||||
|
||||
dolt commit -am "Added tables and data"
|
||||
|
||||
dolt table export one one.sql
|
||||
dolt table export one two.sql
|
||||
|
||||
skip "Disabling foreign key checks don't work for schema changes"
|
||||
|
||||
dolt sql -b -q "set foreign_key_checks = 0; drop table one"
|
||||
dolt sql -b -q "set_foreign_key_checks = 0; drop table two"
|
||||
|
||||
dolt sql < one.sql
|
||||
dolt sql < two.sql
|
||||
|
||||
run dolt status
|
||||
[[ "$output" =~ "working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "export-tables: export a table with a string with commas to csv" {
|
||||
run dolt sql -q "insert into test_string values ('tim', 'is', 'super', 'duper', 'rad', 'a,b,c,d,e')"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
Reference in New Issue
Block a user