diff --git a/oracle/migrator.go b/oracle/migrator.go index 10d5aa4..ec9f0b3 100644 --- a/oracle/migrator.go +++ b/oracle/migrator.go @@ -42,6 +42,7 @@ import ( "database/sql" "errors" "fmt" + "regexp" "slices" "strconv" "strings" @@ -193,8 +194,17 @@ func (m Migrator) CreateTable(values ...interface{}) error { } for _, chk := range stmt.Schema.ParseCheckConstraints() { + constraintSQL := chk.Constraint + + // Quote column names that appear in the constraint + for _, f := range stmt.Schema.Fields { + if strings.Contains(constraintSQL, f.DBName) { + re := regexp.MustCompile(`\b` + regexp.QuoteMeta(f.DBName) + `\b`) + constraintSQL = re.ReplaceAllString(constraintSQL, QuoteIdentifier(f.DBName)) + } + } createTableSQL += "CONSTRAINT ? CHECK (?)," - values = append(values, clause.Column{Name: chk.Name}, clause.Expr{SQL: chk.Constraint}) + values = append(values, clause.Column{Name: chk.Name}, clause.Expr{SQL: constraintSQL}) } createTableSQL = strings.TrimSuffix(createTableSQL, ",") diff --git a/tests/json_bulk_2_test.go b/tests/json_bulk_2_test.go index aa423fc..1eff40b 100644 --- a/tests/json_bulk_2_test.go +++ b/tests/json_bulk_2_test.go @@ -405,7 +405,6 @@ func TestUnicodeJSON(t *testing.T) { } func TestJSONStrict(t *testing.T) { - t.Skip("Skipping due to issue #100") type StrictJSONRecord struct { ID uint `gorm:"primaryKey;autoIncrement;column:record_id"` 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) { } func TestJSONLAX(t *testing.T) { - t.Skip("Skipping due to issue #100") type LaxJSONRecord struct { ID uint `gorm:"primaryKey;autoIncrement;column:record_id"` Doc datatypes.JSON `gorm:"type:CLOB;column:doc;check:doc_is_json_lax,doc IS JSON(LAX)"`