feat(models): 🎉 Add GUID field to various models
* Introduced GUID field to Database, Domain, DomainTable, Schema, Table, View, Sequence, Column, Index, Relationship, Constraint, Enum, and Script models. * Updated initialization functions to assign new GUIDs using uuid package. * Enhanced DCTX reader and writer to utilize GUIDs from models where available.
This commit is contained in:
@@ -133,7 +133,11 @@ func (w *Writer) mapTableFields(table *models.Table) models.DCTXTable {
|
||||
prefix = table.Name[:3]
|
||||
}
|
||||
|
||||
tableGuid := w.newGUID()
|
||||
// Use GUID from model if available, otherwise generate a new one
|
||||
tableGuid := table.GUID
|
||||
if tableGuid == "" {
|
||||
tableGuid = w.newGUID()
|
||||
}
|
||||
w.tableGuidMap[table.Name] = tableGuid
|
||||
|
||||
dctxTable := models.DCTXTable{
|
||||
@@ -171,7 +175,11 @@ func (w *Writer) mapTableKeys(table *models.Table) []models.DCTXKey {
|
||||
}
|
||||
|
||||
func (w *Writer) mapField(column *models.Column) models.DCTXField {
|
||||
guid := w.newGUID()
|
||||
// Use GUID from model if available, otherwise generate a new one
|
||||
guid := column.GUID
|
||||
if guid == "" {
|
||||
guid = w.newGUID()
|
||||
}
|
||||
fieldKey := fmt.Sprintf("%s.%s", column.Table, column.Name)
|
||||
w.fieldGuidMap[fieldKey] = guid
|
||||
|
||||
@@ -209,7 +217,11 @@ func (w *Writer) mapDataType(dataType string) string {
|
||||
}
|
||||
|
||||
func (w *Writer) mapKey(index *models.Index, table *models.Table) models.DCTXKey {
|
||||
guid := w.newGUID()
|
||||
// Use GUID from model if available, otherwise generate a new one
|
||||
guid := index.GUID
|
||||
if guid == "" {
|
||||
guid = w.newGUID()
|
||||
}
|
||||
keyKey := fmt.Sprintf("%s.%s", table.Name, index.Name)
|
||||
w.keyGuidMap[keyKey] = guid
|
||||
|
||||
@@ -344,7 +356,7 @@ func (w *Writer) mapRelation(rel *models.Relationship, schema *models.Schema) mo
|
||||
}
|
||||
|
||||
return models.DCTXRelation{
|
||||
Guid: w.newGUID(),
|
||||
Guid: rel.GUID, // Use GUID from relationship model
|
||||
PrimaryTable: w.tableGuidMap[rel.ToTable], // GUID of the 'to' table (e.g., users)
|
||||
ForeignTable: w.tableGuidMap[rel.FromTable], // GUID of the 'from' table (e.g., posts)
|
||||
PrimaryKey: primaryKeyGUID,
|
||||
|
||||
Reference in New Issue
Block a user