Documentation
¶
Overview ¶
Package schema manages database schema migration. It compares the DocType registry against the live database schema and generates/applies DDL to make them match.
Index ¶
- func ApplyDDL(db *sql.DB, statements []string) error
- func LoadLiveSchema(database *sql.DB, dbName string, dialect db.Dialect) (map[string]*TableInfo, error)
- func MigrateSite(database *sql.DB, dbName string, registry *doctype.Registry, ...) error
- type ActivationPreview
- type ColumnAdd
- type ColumnInfo
- type ColumnRename
- type Diff
- type IndexAdd
- type OrphanedColumn
- type TableInfo
- type TieredChange
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActivationPreview ¶
type ActivationPreview struct {
DDL []string `json:"ddl"`
Changes []TieredChange `json:"changes"`
Blocked []TieredChange `json:"blocked"`
Warnings []TieredChange `json:"warnings"`
}
ActivationPreview contains the full impact analysis for activating a config change.
func AnalyzeImpact ¶
func AnalyzeImpact(database *sql.DB, oldDT, newDT *doctype.DocType, reg *doctype.Registry, dialect db.Dialect) *ActivationPreview
AnalyzeImpact compares a proposed doctype against the existing one (if any) and classifies each change into safety tiers. It also counts affected rows.
type ColumnInfo ¶
type ColumnInfo struct {
Name string
Type string
Nullable bool
Default sql.NullString
Indexed bool
}
ColumnInfo represents a column in the live database schema.
type ColumnRename ¶
ColumnRename describes a column to be renamed (from renamed_from).
type Diff ¶
type Diff struct {
NewTables []string // Tables to CREATE
NewColumns map[string][]ColumnAdd // Table → columns to ADD
NewIndexes map[string][]IndexAdd // Table → indexes to CREATE
RenameColumns map[string][]ColumnRename // Table → columns to RENAME
Orphaned []OrphanedColumn // Columns in DB but not in registry
}
Diff represents the difference between the registry and the live schema.
func ComputeDiff ¶
func ComputeDiff(registry *doctype.Registry, liveSchema map[string]*TableInfo, dialect db.Dialect) *Diff
ComputeDiff// ComputeDiff compares the registry DocTypes against the live database schema and produces a Diff of changes needed.
func (*Diff) GenerateDDL ¶
GenerateDDL produces the SQL statements to apply the diff.
type OrphanedColumn ¶
OrphanedColumn is a column that exists in the database but not in the registry.
type TableInfo ¶
type TableInfo struct {
Name string
Columns map[string]*ColumnInfo
}
TableInfo represents a table in the live database schema.
type TieredChange ¶
type TieredChange struct {
Tier string `json:"tier"` // "safe", "warning", "blocked"
DocType string `json:"doctype"`
Field string `json:"field,omitempty"`
Change string `json:"change"`
Rows int `json:"rows"`
DDL string `json:"ddl,omitempty"`
Message string `json:"message"`
}
TieredChange describes a single schema change with its safety classification.