mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-06 18:59:02 -06:00
added bats test
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,3 +9,5 @@ venv
|
||||
benchmark/perf_tools/dolt-builds/dolt
|
||||
benchmark/perf_tools/dolt-builds/working
|
||||
benchmark/perf_tools/output
|
||||
|
||||
test.sh
|
||||
@@ -52,28 +52,29 @@ func AddPrimaryKeyToTable(ctx context.Context, table *doltdb.Table, tableName st
|
||||
return col
|
||||
})
|
||||
|
||||
// Get Row Data out of Table
|
||||
rowData, err := table.GetRowData(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Go through columns of new table
|
||||
err = newCollection.Iter(func(tag uint64, col schema.Column) (stop bool, err error) {
|
||||
// Skip if they are not going to be part if primary key
|
||||
// Skip if they are not part of primary key
|
||||
if !col.IsPartOfPK {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// Get Row Data out of Table
|
||||
rowData, err := table.GetRowData(ctx)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
// Go through every row
|
||||
err = rowData.Iter(ctx, func(key, value types.Value) (stop bool, err error) {
|
||||
r, err := row.FromNoms(sch, key.(types.Tuple), value.(types.Tuple))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
// Check if column value is null
|
||||
val, ok := r.GetColVal(tag)
|
||||
if !ok || val == nil || val == types.NullValue {
|
||||
return true, fmt.Errorf("cannot change column to NOT NULL when one or more values is NULL")
|
||||
return true, fmt.Errorf("primary key cannot have NULL values")
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
|
||||
@@ -10,6 +10,13 @@ teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test "primary-key-changes: add primary key using null values" {
|
||||
dolt sql -q "create table t(pk int, val int)"
|
||||
dolt sql -q "INSERT INTO t (val) VALUES (1)"
|
||||
run dolt sql -q "ALTER TABLE t ADD PRIMARY KEY (pk)"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "primary-key-changes: add single primary key" {
|
||||
dolt sql -q "create table t(pk int, val int)"
|
||||
run dolt sql -q "ALTER TABLE t ADD PRIMARY KEY (pk)"
|
||||
@@ -573,11 +580,5 @@ SQL
|
||||
dolt sql -q "create table t (pk int, c1 int)"
|
||||
dolt sql -q "insert into t values (NULL, NULL)"
|
||||
run dolt sql -q "alter table t add primary key(pk)"
|
||||
skip "This should fail on some sort of constraint error"
|
||||
[ $status -eq 1 ]
|
||||
|
||||
# This is the current failure mode
|
||||
run dolt sql -q "update t set c1=1"
|
||||
[ $status -eq 1 ]
|
||||
[[ "$output" =~ "received nil" ]] || false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user