Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15763f60cc |
@@ -1251,6 +1251,9 @@ func isIntegerType(colType string) bool {
|
|||||||
func isTextType(colType string) bool {
|
func isTextType(colType string) bool {
|
||||||
textTypes := []string{"text", "varchar", "character varying", "char", "character", "string"}
|
textTypes := []string{"text", "varchar", "character varying", "char", "character", "string"}
|
||||||
lowerType := strings.ToLower(colType)
|
lowerType := strings.ToLower(colType)
|
||||||
|
if strings.HasSuffix(lowerType, "[]") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
for _, t := range textTypes {
|
for _, t := range textTypes {
|
||||||
if strings.HasPrefix(lowerType, t) {
|
if strings.HasPrefix(lowerType, t) {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -87,6 +87,43 @@ func TestWriteDatabase(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWriteDatabase_GinIndexOnTextArrayDoesNotUseTrigramOperatorClass(t *testing.T) {
|
||||||
|
db := models.InitDatabase("testdb")
|
||||||
|
schema := models.InitSchema("public")
|
||||||
|
|
||||||
|
table := models.InitTable("plans", "public")
|
||||||
|
|
||||||
|
tagsCol := models.InitColumn("tags", "plans", "public")
|
||||||
|
tagsCol.Type = "text[]"
|
||||||
|
table.Columns["tags"] = tagsCol
|
||||||
|
|
||||||
|
index := &models.Index{
|
||||||
|
Name: "idx_plans_tags",
|
||||||
|
Type: "gin",
|
||||||
|
Columns: []string{"tags"},
|
||||||
|
}
|
||||||
|
table.Indexes[index.Name] = index
|
||||||
|
|
||||||
|
schema.Tables = append(schema.Tables, table)
|
||||||
|
db.Schemas = append(db.Schemas, schema)
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
writer := NewWriter(&writers.WriterOptions{})
|
||||||
|
writer.writer = &buf
|
||||||
|
|
||||||
|
if err := writer.WriteDatabase(db); err != nil {
|
||||||
|
t.Fatalf("WriteDatabase failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
output := buf.String()
|
||||||
|
if !strings.Contains(output, `USING gin (tags)`) {
|
||||||
|
t.Fatalf("expected GIN index on array column without explicit trigram opclass, got:\n%s", output)
|
||||||
|
}
|
||||||
|
if strings.Contains(output, "gin_trgm_ops") {
|
||||||
|
t.Fatalf("did not expect gin_trgm_ops for text[] column, got:\n%s", output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestWriteForeignKeys(t *testing.T) {
|
func TestWriteForeignKeys(t *testing.T) {
|
||||||
// Create a test database with two related tables
|
// Create a test database with two related tables
|
||||||
db := models.InitDatabase("testdb")
|
db := models.InitDatabase("testdb")
|
||||||
|
|||||||
Reference in New Issue
Block a user