Documentation
¶
Index ¶
- func GetAllModels() []any
- func GetModel(name string) (any, bool)
- func RegisterModel(name string, model any)
- type Column
- type ColumnRename
- type Migrator
- type ModelRegistry
- type Schema
- type SchemaComparer
- func (c *SchemaComparer) Compare(models ...interface{}) (*SchemaDiff, error)
- func (c *SchemaComparer) CompareSchemas(current, target map[string]*schema.Schema) (*SchemaDiff, error)
- func (c *SchemaComparer) CompareTable(current, target *schema.Schema) TableDiff
- func (c *SchemaComparer) GetCurrentSchema() (map[string]*schema.Schema, error)
- func (c *SchemaComparer) GetModelSchemas(models ...any) (map[string]*schema.Schema, error)
- type SchemaDiff
- type SchemaMigrator
- type Table
- type TableDiff
- type TableRename
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterModel ¶
RegisterModel registers a model type with the registry
Types ¶
type Column ¶
type Column struct {
Name string
Type string
IsPrimaryKey bool
IsUnique bool
IsNotNull bool
DefaultValue string
Size int
Precision int
Scale int
Comment string
AutoIncrement bool
UniqueIndex string
Index string
ForeignKey string
References string
OnDelete string
OnUpdate string
Check string
Constraint string
Embedded bool
EmbeddedPrefix string
Serializer string
Permission string
Ignore bool
AutoCreateTime bool
AutoUpdateTime bool
Tag string
TagSettings map[string]string
}
Column represents a database column
type ColumnRename ¶
ColumnRename represents a column rename operation
type Migrator ¶
type Migrator interface {
ColumnTypes(dst any) ([]gorm.ColumnType, error)
GetTables() ([]string, error)
GetIndexes(tableName string) ([]*schema.Index, error)
GetRelationships(tableName string) ([]*schema.Relationship, error)
}
func NewSchemaMigrator ¶
type ModelRegistry ¶
type ModelRegistry struct {
// contains filtered or unexported fields
}
ModelRegistry stores all registered model types
type SchemaComparer ¶
type SchemaComparer struct {
// contains filtered or unexported fields
}
SchemaComparer compares database schemas
func NewSchemaComparer ¶
func NewSchemaComparer(db *gorm.DB) *SchemaComparer
NewSchemaComparer creates a new schema comparer
func (*SchemaComparer) Compare ¶
func (c *SchemaComparer) Compare(models ...interface{}) (*SchemaDiff, error)
Compare compares the current database schema with the provided models
func (*SchemaComparer) CompareSchemas ¶
func (c *SchemaComparer) CompareSchemas(current, target map[string]*schema.Schema) (*SchemaDiff, error)
CompareSchemas compares two schemas and returns the differences
func (*SchemaComparer) CompareTable ¶
func (c *SchemaComparer) CompareTable(current, target *schema.Schema) TableDiff
CompareTable compares two table schemas and returns a TableDiff using GORM types
func (*SchemaComparer) GetCurrentSchema ¶
func (c *SchemaComparer) GetCurrentSchema() (map[string]*schema.Schema, error)
GetCurrentSchema gets the current database schema
func (*SchemaComparer) GetModelSchemas ¶
GetModelSchemas gets the schema from the provided models
type SchemaDiff ¶
type SchemaDiff struct {
TablesToCreate []TableDiff
TablesToDrop []string
TablesToModify []TableDiff
TablesToRename []TableRename
}
SchemaDiff represents the differences between two database schemas
type SchemaMigrator ¶
type SchemaMigrator struct {
// contains filtered or unexported fields
}
func (*SchemaMigrator) ColumnTypes ¶
func (m *SchemaMigrator) ColumnTypes(dst any) ([]gorm.ColumnType, error)
func (*SchemaMigrator) GetIndexes ¶
func (m *SchemaMigrator) GetIndexes(tableName string) ([]*schema.Index, error)
func (*SchemaMigrator) GetRelationships ¶
func (m *SchemaMigrator) GetRelationships(tableName string) ([]*schema.Relationship, error)
func (*SchemaMigrator) GetTables ¶
func (m *SchemaMigrator) GetTables() ([]string, error)
type Table ¶
type Table struct {
Name string
Schema *schema.Schema
Fields map[string]*schema.Field
Indexes []*schema.Index
}
Table represents a database table
type TableDiff ¶
type TableDiff struct {
Schema *schema.Schema
FieldsToAdd []*schema.Field
FieldsToDrop []*schema.Field
FieldsToModify []*schema.Field
FieldsToRename []ColumnRename
IndexesToAdd []*schema.Index
IndexesToDrop []*schema.Index
IndexesToModify []*schema.Index
ForeignKeysToAdd []*schema.Relationship
ForeignKeysToDrop []*schema.Relationship
}
TableDiff represents the differences in a table, using GORM types
type TableRename ¶
TableRename represents a table rename operation