schema

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDDL

func ApplyDDL(db *sql.DB, statements []string) error

ApplyDDL executes the DDL statements against the database.

func LoadLiveSchema

func LoadLiveSchema(database *sql.DB, dbName string, dialect db.Dialect) (map[string]*TableInfo, error)

LoadLiveSchema reads the current database schema using the dialect. Delegates to db.Dialect.LoadSchema and converts to the local TableInfo format.

func MigrateSite

func MigrateSite(database *sql.DB, dbName string, registry *doctype.Registry, dialect db.Dialect) error

MigrateSite computes the schema diff for a site and applies it.

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 ColumnAdd

type ColumnAdd struct {
	Name     string
	Type     string
	Nullable bool
	Default  string
}

ColumnAdd describes a column to be added to an existing table.

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

type ColumnRename struct {
	OldName string
	NewName string
}

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

func (d *Diff) GenerateDDL(registry *doctype.Registry, dialect db.Dialect) []string

GenerateDDL produces the SQL statements to apply the diff.

func (*Diff) IsEmpty

func (d *Diff) IsEmpty() bool

IsEmpty returns true if there are no changes to apply.

type IndexAdd

type IndexAdd struct {
	Table   string
	Columns []string
	Unique  bool
}

IndexAdd describes an index to be created.

type OrphanedColumn

type OrphanedColumn struct {
	Table  string
	Column string
}

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.

Jump to

Keyboard shortcuts

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