Skip to content

Commit a9e0a08

Browse files
committed
resolved the issues 100 by quoting the names in the constraint
1 parent 5f3cd5c commit a9e0a08

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

oracle/migrator.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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, ",")

tests/json_bulk_2_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ func TestUnicodeJSON(t *testing.T) {
405405
}
406406

407407
func 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

424423
func 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)"`

0 commit comments

Comments
 (0)