feat(writer): 🎉 Update index naming conventions for consistency

* Use SQLName() for primary key constraint naming
* Enhance index name formatting with column suffix
This commit is contained in:
2026-01-31 17:23:18 +02:00
parent f532fc110c
commit c388e422d0
2 changed files with 3 additions and 2 deletions

View File

@@ -477,7 +477,7 @@ func (w *MigrationWriter) generateIndexScripts(model *models.Schema, current *mo
} }
if len(pkColumns) > 0 { if len(pkColumns) > 0 {
sort.Strings(pkColumns) sort.Strings(pkColumns)
constraintName := fmt.Sprintf("pk_%s_%s", strings.ToLower(model.Name), strings.ToLower(modelTable.Name)) constraintName := fmt.Sprintf("pk_%s_%s", model.SQLName(), modelTable.SQLName())
shouldCreate := true shouldCreate := true
if currentTable != nil { if currentTable != nil {

View File

@@ -594,7 +594,8 @@ func (w *Writer) writeIndexes(schema *models.Schema) error {
if index.Unique { if index.Unique {
indexType = "uidx" indexType = "uidx"
} }
indexName = fmt.Sprintf("%s_%s_%s", indexType, schema.SQLName(), table.SQLName()) columnSuffix := strings.Join(index.Columns, "_")
indexName = fmt.Sprintf("%s_%s_%s", indexType, table.SQLName(), strings.ToLower(columnSuffix))
} }
// Build column list with operator class support for GIN indexes // Build column list with operator class support for GIN indexes