File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import (
4242 "database/sql"
4343 "errors"
4444 "fmt"
45+ "regexp"
4546 "slices"
4647 "strconv"
4748 "strings"
@@ -193,8 +194,17 @@ func (m Migrator) CreateTable(values ...interface{}) error {
193194 }
194195
195196 for _ , chk := range stmt .Schema .ParseCheckConstraints () {
197+ constraintSQL := chk .Constraint
198+
199+ // Quote column names that appear in the constraint
200+ for _ , f := range stmt .Schema .Fields {
201+ if strings .Contains (constraintSQL , f .DBName ) {
202+ re := regexp .MustCompile (`\b` + regexp .QuoteMeta (f .DBName ) + `\b` )
203+ constraintSQL = re .ReplaceAllString (constraintSQL , QuoteIdentifier (f .DBName ))
204+ }
205+ }
196206 createTableSQL += "CONSTRAINT ? CHECK (?),"
197- values = append (values , clause.Column {Name : chk .Name }, clause.Expr {SQL : chk . Constraint })
207+ values = append (values , clause.Column {Name : chk .Name }, clause.Expr {SQL : constraintSQL })
198208 }
199209
200210 createTableSQL = strings .TrimSuffix (createTableSQL , "," )
Original file line number Diff line number Diff line change @@ -405,7 +405,6 @@ func TestUnicodeJSON(t *testing.T) {
405405}
406406
407407func TestJSONStrict (t * testing.T ) {
408- t .Skip ("Skipping due to issue #100" )
409408 type StrictJSONRecord struct {
410409 ID uint `gorm:"primaryKey;autoIncrement;column:record_id"`
411410 DocJson datatypes.JSON `gorm:"type:CLOB;column:doc;check:doc_is_json_strict,doc IS JSON (STRICT)"`
@@ -422,7 +421,6 @@ func TestJSONStrict(t *testing.T) {
422421}
423422
424423func TestJSONLAX (t * testing.T ) {
425- t .Skip ("Skipping due to issue #100" )
426424 type LaxJSONRecord struct {
427425 ID uint `gorm:"primaryKey;autoIncrement;column:record_id"`
428426 Doc datatypes.JSON `gorm:"type:CLOB;column:doc;check:doc_is_json_lax,doc IS JSON(LAX)"`
You can’t perform that action at this time.
0 commit comments