diff

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllModels

func GetAllModels() []any

GetAllModels returns all registered models

func GetModel

func GetModel(name string) (any, bool)

GetModel returns a model instance by name

func RegisterModel

func RegisterModel(name string, model any)

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

type ColumnRename struct {
	OldName string
	NewName string
}

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

func NewSchemaMigrator(db *gorm.DB) Migrator

type ModelRegistry

type ModelRegistry struct {
	// contains filtered or unexported fields
}

ModelRegistry stores all registered model types

type Schema

type Schema struct {
	Tables map[string]*schema.Schema
}

Schema represents a database schema

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

func (c *SchemaComparer) GetModelSchemas(models ...any) (map[string]*schema.Schema, error)

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

func (*TableDiff) IsEmpty

func (d *TableDiff) IsEmpty() bool

IsEmpty checks if a TableDiff is empty

type TableRename

type TableRename struct {
	OldName string
	NewName string
}

TableRename represents a table rename operation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL