Skip to content

Commit 5203d53

Browse files
authored
Merge pull request #3126 from dolthub/angela/check_constraints
Added test for adding check constraint when modifying column
2 parents 859e4fc + cad6b22 commit 5203d53

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

enginetest/queries/alter_table_queries.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,20 @@ var ModifyColumnScripts = []ScriptTest{
22732273
},
22742274
},
22752275
},
2276+
{
2277+
// https://github.com/dolthub/dolt/issues/9591
2278+
Name: "Add check constraint when modifying column",
2279+
SetUpScript: []string{
2280+
"create table t(pk int primary key)",
2281+
"alter table t modify column pk int check(pk < 10)",
2282+
},
2283+
Assertions: []ScriptTestAssertion{
2284+
{
2285+
Query: "insert into t values (20)",
2286+
ExpectedErr: sql.ErrCheckConstraintViolated,
2287+
},
2288+
},
2289+
},
22762290
{
22772291
Name: "error cases",
22782292
SetUpScript: []string{},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250611225316-90a5898bfe26
9+
github.com/dolthub/vitess v0.0.0-20250729225143-5ab74d1f0182
1010
github.com/go-kit/kit v0.10.0
1111
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1212
github.com/gocraft/dbr/v2 v2.7.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9X
6060
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
6161
github.com/dolthub/vitess v0.0.0-20250611225316-90a5898bfe26 h1:9Npf0JYVCrwe9edTfYD/pjIncCePNDiu4j50xLcV334=
6262
github.com/dolthub/vitess v0.0.0-20250611225316-90a5898bfe26/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
63+
github.com/dolthub/vitess v0.0.0-20250729225143-5ab74d1f0182 h1:LrUmlwHlQLSu8OIL60APDGeUoPBoezeo8fTDRAe9EJg=
64+
github.com/dolthub/vitess v0.0.0-20250729225143-5ab74d1f0182/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
6365
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
6466
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
6567
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=

sql/analyzer/validate_create_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func ValidateModifyColumn(ctx *sql.Context, initialSch sql.Schema, schema sql.Sc
458458
// It cannot have been renamed in the same statement.
459459
oldColName := mc.Column()
460460
if !schema.Contains(oldColName, tableName) || !initialSch.Contains(oldColName, tableName) {
461-
return nil, sql.ErrTableColumnNotFound.New(table, oldColName)
461+
return nil, sql.ErrTableColumnNotFound.New(tableName, oldColName)
462462
}
463463

464464
newCol := mc.NewColumn()

0 commit comments

Comments
 (0)