More Roundtrip tests
This commit is contained in:
84
pkg/models/dctx.go
Normal file
84
pkg/models/dctx.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package models
|
||||
|
||||
import "encoding/xml"
|
||||
|
||||
// DCTXDictionary represents the root element of a DCTX file
|
||||
type DCTXDictionary struct {
|
||||
XMLName xml.Name `xml:"Dictionary"`
|
||||
Name string `xml:"Name,attr"`
|
||||
Version string `xml:"Version,attr"`
|
||||
Tables []DCTXTable `xml:"Table"`
|
||||
Relations []DCTXRelation `xml:"Relation,omitempty"`
|
||||
}
|
||||
|
||||
// DCTXTable represents a table definition in DCTX
|
||||
type DCTXTable struct {
|
||||
Guid string `xml:"Guid,attr"`
|
||||
Name string `xml:"Name,attr"`
|
||||
Prefix string `xml:"Prefix,attr"`
|
||||
Driver string `xml:"Driver,attr,omitempty"`
|
||||
Owner string `xml:"Owner,attr,omitempty"`
|
||||
Path string `xml:"Path,attr,omitempty"`
|
||||
Description string `xml:"Description,attr,omitempty"`
|
||||
Fields []DCTXField `xml:"Field"`
|
||||
Keys []DCTXKey `xml:"Key,omitempty"`
|
||||
Options []DCTXOption `xml:"Option,omitempty"`
|
||||
}
|
||||
|
||||
// DCTXField represents a field/column definition in DCTX
|
||||
type DCTXField struct {
|
||||
Guid string `xml:"Guid,attr"`
|
||||
Name string `xml:"Name,attr"`
|
||||
DataType string `xml:"DataType,attr"`
|
||||
Size int `xml:"Size,attr,omitempty"`
|
||||
NoPopulate bool `xml:"NoPopulate,attr,omitempty"`
|
||||
Thread bool `xml:"Thread,attr,omitempty"`
|
||||
Fields []DCTXField `xml:"Field,omitempty"` // For GROUP fields (nested structures)
|
||||
Options []DCTXOption `xml:"Option,omitempty"`
|
||||
}
|
||||
|
||||
// DCTXKey represents an index or key definition in DCTX
|
||||
type DCTXKey struct {
|
||||
Guid string `xml:"Guid,attr"`
|
||||
Name string `xml:"Name,attr"`
|
||||
KeyType string `xml:"KeyType,attr,omitempty"`
|
||||
Primary bool `xml:"Primary,attr,omitempty"`
|
||||
Unique bool `xml:"Unique,attr,omitempty"`
|
||||
Order int `xml:"Order,attr,omitempty"`
|
||||
Description string `xml:"Description,attr,omitempty"`
|
||||
Components []DCTXComponent `xml:"Component"`
|
||||
}
|
||||
|
||||
// DCTXComponent represents a component of a key (field reference)
|
||||
type DCTXComponent struct {
|
||||
Guid string `xml:"Guid,attr"`
|
||||
FieldId string `xml:"FieldId,attr,omitempty"`
|
||||
Order int `xml:"Order,attr"`
|
||||
Ascend bool `xml:"Ascend,attr,omitempty"`
|
||||
}
|
||||
|
||||
// DCTXOption represents a property option in DCTX
|
||||
type DCTXOption struct {
|
||||
Property string `xml:"Property,attr"`
|
||||
PropertyType string `xml:"PropertyType,attr,omitempty"`
|
||||
PropertyValue string `xml:"PropertyValue,attr"`
|
||||
}
|
||||
|
||||
// DCTXRelation represents a relationship/foreign key in DCTX
|
||||
type DCTXRelation struct {
|
||||
Guid string `xml:"Guid,attr"`
|
||||
PrimaryTable string `xml:"PrimaryTable,attr"`
|
||||
ForeignTable string `xml:"ForeignTable,attr"`
|
||||
PrimaryKey string `xml:"PrimaryKey,attr,omitempty"`
|
||||
ForeignKey string `xml:"ForeignKey,attr,omitempty"`
|
||||
Delete string `xml:"Delete,attr,omitempty"`
|
||||
Update string `xml:"Update,attr,omitempty"`
|
||||
ForeignMappings []DCTXFieldMapping `xml:"ForeignMapping,omitempty"`
|
||||
PrimaryMappings []DCTXFieldMapping `xml:"PrimaryMapping,omitempty"`
|
||||
}
|
||||
|
||||
// DCTXFieldMapping represents a field mapping in a relation
|
||||
type DCTXFieldMapping struct {
|
||||
Guid string `xml:"Guid,attr"`
|
||||
Field string `xml:"Field,attr"`
|
||||
}
|
||||
@@ -38,7 +38,8 @@ type Schema struct {
|
||||
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty" xml:"-"`
|
||||
Scripts []*Script `json:"scripts,omitempty" yaml:"scripts,omitempty" xml:"scripts,omitempty"`
|
||||
Sequence uint `json:"sequence,omitempty" yaml:"sequence,omitempty" xml:"sequence,omitempty"`
|
||||
RefDatabase *Database `json:"ref_database,omitempty" yaml:"ref_database,omitempty" xml:"ref_database,omitempty"`
|
||||
RefDatabase *Database `json:"-" yaml:"-" xml:"-"` // Excluded to prevent circular references
|
||||
Relations []*Relationship `json:"relations,omitempty" yaml:"relations,omitempty" xml:"-"`
|
||||
}
|
||||
|
||||
// SQLName returns the schema name in lowercase
|
||||
@@ -58,7 +59,7 @@ type Table struct {
|
||||
Tablespace string `json:"tablespace,omitempty" yaml:"tablespace,omitempty" xml:"tablespace,omitempty"`
|
||||
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty" xml:"-"`
|
||||
Sequence uint `json:"sequence,omitempty" yaml:"sequence,omitempty" xml:"sequence,omitempty"`
|
||||
RefSchema *Schema `json:"ref_schema,omitempty" yaml:"ref_schema,omitempty" xml:"ref_schema,omitempty"`
|
||||
RefSchema *Schema `json:"-" yaml:"-" xml:"-"` // Excluded to prevent circular references
|
||||
}
|
||||
|
||||
// SQLName returns the table name in lowercase
|
||||
@@ -96,7 +97,7 @@ type View struct {
|
||||
Comment string `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
|
||||
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty" xml:"-"`
|
||||
Sequence uint `json:"sequence,omitempty" yaml:"sequence,omitempty" xml:"sequence,omitempty"`
|
||||
RefSchema *Schema `json:"ref_schema,omitempty" yaml:"ref_schema,omitempty" xml:"ref_schema,omitempty"`
|
||||
RefSchema *Schema `json:"-" yaml:"-" xml:"-"` // Excluded to prevent circular references
|
||||
}
|
||||
|
||||
// SQLName returns the view name in lowercase
|
||||
@@ -119,7 +120,7 @@ type Sequence struct {
|
||||
OwnedByColumn string `json:"owned_by_column,omitempty" yaml:"owned_by_column,omitempty" xml:"owned_by_column,omitempty"`
|
||||
Comment string `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
|
||||
Sequence uint `json:"sequence,omitempty" yaml:"sequence,omitempty" xml:"sequence,omitempty"`
|
||||
RefSchema *Schema `json:"ref_schema,omitempty" yaml:"ref_schema,omitempty" xml:"ref_schema,omitempty"`
|
||||
RefSchema *Schema `json:"-" yaml:"-" xml:"-"` // Excluded to prevent circular references
|
||||
}
|
||||
|
||||
// SQLName returns the sequence name in lowercase
|
||||
@@ -184,8 +185,10 @@ type Relationship struct {
|
||||
Type RelationType `json:"type" yaml:"type" xml:"type"`
|
||||
FromTable string `json:"from_table" yaml:"from_table" xml:"from_table"`
|
||||
FromSchema string `json:"from_schema" yaml:"from_schema" xml:"from_schema"`
|
||||
FromColumns []string `json:"from_columns" yaml:"from_columns" xml:"from_columns"`
|
||||
ToTable string `json:"to_table" yaml:"to_table" xml:"to_table"`
|
||||
ToSchema string `json:"to_schema" yaml:"to_schema" xml:"to_schema"`
|
||||
ToColumns []string `json:"to_columns" yaml:"to_columns" xml:"to_columns"`
|
||||
ForeignKey string `json:"foreign_key" yaml:"foreign_key" xml:"foreign_key"`
|
||||
Properties map[string]string `json:"properties" yaml:"properties" xml:"-"`
|
||||
ThroughTable string `json:"through_table,omitempty" yaml:"through_table,omitempty" xml:"through_table,omitempty"` // For many-to-many
|
||||
@@ -292,14 +295,28 @@ func InitColumn(name, table, schema string) *Column {
|
||||
}
|
||||
|
||||
// InitIndex initializes a new Index with empty slices
|
||||
func InitIndex(name string) *Index {
|
||||
func InitIndex(name, table, schema string) *Index {
|
||||
return &Index{
|
||||
Name: name,
|
||||
Table: table,
|
||||
Schema: schema,
|
||||
Columns: make([]string, 0),
|
||||
Include: make([]string, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// InitRelation initializes a new Relationship with empty slices
|
||||
func InitRelation(name, schema string) *Relationship {
|
||||
return &Relationship{
|
||||
Name: name,
|
||||
FromSchema: schema,
|
||||
ToSchema: schema,
|
||||
Properties: make(map[string]string),
|
||||
FromColumns: make([]string, 0),
|
||||
ToColumns: make([]string, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// InitRelationship initializes a new Relationship with empty maps
|
||||
func InitRelationship(name string, relType RelationType) *Relationship {
|
||||
return &Relationship{
|
||||
|
||||
Reference in New Issue
Block a user