{"modulePath":"github.com/GoCodeAlone/workflow-plugin-data-engineering","version":"v0.3.3","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package migrate\n\nPackage migrate provides declarative schema diffing and scripted migration running.\n\n## Functions\n\n```go\nfunc MigrateSchemas() map[string]any\n```\nmoduleSchemas returns JSON Schema definitions for UI forms.\n\n```go\nfunc NewMigrateApplyStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewMigrateApplyStep creates a step.migrate\\_apply instance.\n\n```go\nfunc NewMigrateContractStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewMigrateContractStep creates a step.migrate\\_contract instance.\n\n```go\nfunc NewMigrateExpandStatusStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewMigrateExpandStatusStep creates a step.migrate\\_expand\\_status instance.\n\n```go\nfunc NewMigrateExpandStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewMigrateExpandStep creates a step.migrate\\_expand instance.\n\n```go\nfunc NewMigratePlanStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewMigratePlanStep creates a step.migrate\\_plan instance.\n\n```go\nfunc NewMigrateRollbackStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewMigrateRollbackStep creates a step.migrate\\_rollback instance.\n\n```go\nfunc NewMigrateRunStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewMigrateRunStep creates a step.migrate\\_run instance.\n\n```go\nfunc NewMigrateStatusStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewMigrateStatusStep creates a step.migrate\\_status instance.\n\n```go\nfunc NewSchemaEvolvePipelineStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewSchemaEvolvePipelineStep creates a step.schema\\_evolve\\_pipeline instance.\n\n```go\nfunc NewSchemaEvolveVerifyStep(name string, _ map[string]any) (sdk.StepInstance, error)\n```\nNewSchemaEvolveVerifyStep creates a step.schema\\_evolve\\_verify instance.\n\n```go\nfunc NewSchemaModule(name string, config map[string]any) (sdk.ModuleInstance, error)\n```\nNewSchemaModule creates a new migrate.schema module instance.\n\n```go\nfunc RegisterModule(name string, m *SchemaModule) error\n```\nRegisterModule adds a named SchemaModule to the global registry.\n\n```go\nfunc SetCDCLookup(fn func(string) (CDCRestarter, error))\n```\nSetCDCLookup registers the function used to resolve a CDC connector by module name.\n\n```go\nfunc SetDBLookup(fn func(string) (SQLExecutor, error))\n```\nSetDBLookup registers the function used to resolve a source DB executor by module name.\n\n```go\nfunc SetLakehouseLookup(fn func(string) (LakehouseEvolver, error))\n```\nSetLakehouseLookup registers the function used to resolve a lakehouse catalog module.\n\n```go\nfunc SetSchemaRegistryLookup(fn func(string) (SchemaRegistryProvider, error))\n```\nSetSchemaRegistryLookup registers the function used to resolve a schema registry module.\n\n```go\nfunc UnregisterModule(name string)\n```\nUnregisterModule removes a SchemaModule from the registry.\n\n## Types\n\n```go\ntype AppliedMigration struct {\n\tVersion   int\n\tAppliedAt time.Time\n\tChecksum  string\n}\n```\nAppliedMigration is a migration that has already been run.\n\n```go\ntype CDCRestarter interface {\n\tStop(ctx context.Context) error\n\tStart(ctx context.Context) error\n}\n```\nCDCRestarter can stop and restart a CDC connector to pick up schema changes.\n\n```go\ntype ColumnDef struct {\n\tName       string `json:\"name\"               yaml:\"name\"`\n\tType       string `json:\"type\"               yaml:\"type\"`\n\tNullable   bool   `json:\"nullable,omitempty\" yaml:\"nullable,omitempty\"`\n\tPrimaryKey bool   `json:\"primaryKey,omitempty\" yaml:\"primaryKey,omitempty\"`\n\tUnique     bool   `json:\"unique,omitempty\"   yaml:\"unique,omitempty\"`\n\tDefault    string `json:\"default,omitempty\"  yaml:\"default,omitempty\"`\n}\n```\nColumnDef describes a single column within a table.\n\n```go\ntype ConnectorAction struct {\n\tAction string `json:\"action\"` // \"restart\", \"reconfigure\"\n\tName   string `json:\"name\"`\n}\n```\nConnectorAction describes an action to take on a CDC connector.\n\n```go\ntype EvolutionStep struct {\n\tTarget      string         `json:\"target\"` // source_db, cdc_connector, schema_registry, lakehouse\n\tAction      string         `json:\"action\"` // alter_table, restart_connector, register_schema, evolve_table\n\tSQL         string         `json:\"sql,omitempty\"`\n\tConfig      map[string]any `json:\"config,omitempty\"`\n\tRollback    string         `json:\"rollback\"`\n\tDescription string         `json:\"description\"`\n}\n```\nEvolutionStep is a single ordered step in a schema evolution plan.\n\n```go\ntype ExpandContractChange struct {\n\tType      string `json:\"type\"` // add_column, rename_column, change_type, drop_column\n\tOldColumn string `json:\"oldColumn\"`\n\tNewColumn string `json:\"newColumn\"`\n\tNewType   string `json:\"newType\"`\n\tTransform string `json:\"transform\"` // SQL expr (references NEW.\u003ccol\u003e); defaults set per type\n}\n```\nExpandContractChange describes one change in an expand-contract migration.\n\n```go\ntype ExpandContractPlan struct {\n\tTable        string\n\tChanges      []ExpandContractChange\n\tExpandSQL    []string // DDL + triggers to apply during expand phase\n\tContractSQL  []string // DDL to apply during contract phase\n\tVerifySQL    string   // SQL to verify all rows have been migrated\n\tTriggerNames []string // generated trigger names (for status checking)\n\tNewColumns   []string // new column names added during expand\n}\n```\nExpandContractPlan holds all SQL generated for the expand and contract phases.\n\n```go\nfunc BuildExpandContractPlan(table string, changes []ExpandContractChange) (*ExpandContractPlan, error)\n```\nBuildExpandContractPlan generates SQL statements for the expand and contract phases.\n\nExpand phase creates new columns and BEFORE INSERT OR UPDATE triggers that keep old and new columns in sync, enabling dual-version read/write.\n\nContract phase removes old structures once all consumers have migrated.\n\n```go\ntype IndexDef struct {\n\tName    string   `json:\"name,omitempty\"   yaml:\"name,omitempty\"`\n\tColumns []string `json:\"columns\"          yaml:\"columns\"`\n\tUnique  bool     `json:\"unique,omitempty\" yaml:\"unique,omitempty\"`\n}\n```\nIndexDef describes an index on a table.\n\n```go\ntype LakehouseEvolver interface {\n\tEvolveTable(ctx context.Context, namespace []string, table string, change map[string]any) error\n}\n```\nLakehouseEvolver evolves an Iceberg table schema.\n\n```go\ntype MigrateApplyStep struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrateApplyStep executes a previously computed migration plan.\n\n```go\nfunc (s *MigrateApplyStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype MigrateContractStep struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrateContractStep executes the contract phase: removes old columns and triggers once all consumers have migrated to the new schema.\n\n```go\nfunc (s *MigrateContractStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype MigrateExpandStatusStep struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrateExpandStatusStep checks whether an expand phase is active and safe to contract.\n\n```go\nfunc (s *MigrateExpandStatusStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype MigrateExpandStep struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrateExpandStep executes the expand phase of an expand-contract migration. It adds new columns and installs sync triggers for dual-write operation.\n\n```go\nfunc (s *MigrateExpandStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype MigratePlanStep struct {\n\t// contains filtered or unexported fields\n}\n```\nMigratePlanStep diffs the desired schema against the live database.\n\n```go\nfunc (s *MigratePlanStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype MigrateRollbackStep struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrateRollbackStep rolls back N migration scripts.\n\n```go\nfunc (s *MigrateRollbackStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype MigrateRunStep struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrateRunStep runs a specific numbered migration script.\n\n```go\nfunc (s *MigrateRunStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype MigrateStatusStep struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrateStatusStep reports the current migration state.\n\n```go\nfunc (s *MigrateStatusStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype MigrationPlan struct {\n\tChanges []SchemaChange\n\tSafe    bool // true if all changes are non-breaking\n}\n```\nMigrationPlan is the result of diffing two schema definitions.\n\n```go\nfunc DiffSchema(desired, live SchemaDefinition) (MigrationPlan, error)\n```\nDiffSchema computes the migration plan to move from live to desired schema. live may be an empty SchemaDefinition (zero value) if the table does not yet exist.\n\n```go\ntype MigrationRunner struct {\n\t// contains filtered or unexported fields\n}\n```\nMigrationRunner executes ordered migration scripts with advisory locking.\n\n```go\nfunc NewMigrationRunner(executor SQLExecutor, lockTable string) (*MigrationRunner, error)\n```\nNewMigrationRunner creates a runner backed by executor storing state in lockTable. Returns an error if lockTable is not a valid SQL identifier.\n\n```go\nfunc (r *MigrationRunner) Apply(ctx context.Context, scripts []MigrationScript) error\n```\nApply runs all pending migrations from scripts in version order. It acquires a Postgres advisory lock for the duration.\n\n```go\nfunc (r *MigrationRunner) EnsureLockTable(ctx context.Context) error\n```\nEnsureLockTable creates the migration state table if it does not exist.\n\n```go\nfunc (r *MigrationRunner) Rollback(ctx context.Context, scripts []MigrationScript, steps int) error\n```\nRollback rolls back the N most recent applied migrations using their down scripts.\n\n```go\nfunc (r *MigrationRunner) Status(ctx context.Context, scripts []MigrationScript) (*MigrationState, error)\n```\nStatus returns the current version and which scripts are still pending.\n\n```go\ntype MigrationScript struct {\n\tVersion     int\n\tDescription string\n\tUpSQL       string\n\tDownSQL     string\n}\n```\nMigrationScript is a versioned up/down SQL pair parsed from disk.\n\n```go\nfunc LoadScripts(dir string) ([]MigrationScript, error)\n```\nLoadScripts parses NNN\\_description.up.sql + NNN\\_description.down.sql pairs from dir. Pairs are sorted by version ascending. A missing .down.sql file is not an error.\n\n```go\ntype MigrationState struct {\n\tVersion int\n\tApplied []AppliedMigration\n\tPending []MigrationScript\n}\n```\nMigrationState describes the current migration state of the database.\n\n```go\ntype SQLExecutor interface {\n\tExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)\n\tQueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)\n}\n```\nSQLExecutor executes SQL statements against a database connection.\n\n```go\ntype SchemaAction struct {\n\tAction        string `json:\"action\"` // \"register\", \"check_compat\"\n\tSubject       string `json:\"subject\"`\n\tSchema        string `json:\"schema\"`\n\tCompatibility string `json:\"compatibility\"`\n}\n```\nSchemaAction describes an action to take in the schema registry.\n\n```go\ntype SchemaChange struct {\n\tType        string // add_column, add_table, add_index, widen_type, drop_column, narrow_type, drop_index\n\tDescription string\n\tSQL         string\n\tBreaking    bool\n}\n```\nSchemaChange represents a single DDL change.\n\n```go\ntype SchemaDefinition struct {\n\tTable   string      `json:\"table\"             yaml:\"table\"`\n\tColumns []ColumnDef `json:\"columns\"           yaml:\"columns\"`\n\tIndexes []IndexDef  `json:\"indexes,omitempty\" yaml:\"indexes,omitempty\"`\n}\n```\nSchemaDefinition describes the desired state of a database table.\n\n```go\nfunc IntrospectSchema(ctx context.Context, exec SQLExecutor, tableName string) (*SchemaDefinition, error)\n```\nIntrospectSchema queries the live database for the current schema of tableName. Uses information\\_schema.columns and pg\\_indexes to build a SchemaDefinition. Returns nil (not an error) if the table does not exist.\n\n```go\nfunc ParseSchemaDir(dir string) ([]SchemaDefinition, error)\n```\nParseSchemaDir parses all .yaml files in a directory as schema definitions.\n\n```go\nfunc ParseSchemaFile(path string) (SchemaDefinition, error)\n```\nParseSchemaFile parses a YAML schema definition file.\n\n```go\ntype SchemaEvolutionPlan struct {\n\tSourceDB       SchemaChange // DDL to apply in the source database\n\tCDCConnector   ConnectorAction\n\tSchemaRegistry SchemaAction\n\tLakehouse      TableUpdate\n\tSafe           bool\n\tSteps          []EvolutionStep\n}\n```\nSchemaEvolutionPlan coordinates a schema change across the full CDC pipeline.\n\n```go\nfunc BuildEvolutionPlan(table, namespace string, change SchemaChange, subject, schema string, icebergFields []string) *SchemaEvolutionPlan\n```\nBuildEvolutionPlan constructs a SchemaEvolutionPlan from a change description. It does not execute anything — callers execute via executeEvolutionPlan.\n\n```go\ntype SchemaEvolvePipelineStep struct {\n\t// contains filtered or unexported fields\n}\n```\nSchemaEvolvePipelineStep orchestrates a schema change across the full CDC pipeline: schema registry → lakehouse → source DB → CDC connector restart.\n\n```go\nfunc (s *SchemaEvolvePipelineStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype SchemaEvolveVerifyStep struct {\n\t// contains filtered or unexported fields\n}\n```\nSchemaEvolveVerifyStep verifies that all pipeline layers have consistent schemas after an evolution. Compares source DB introspection against schema registry.\n\n```go\nfunc (s *SchemaEvolveVerifyStep) Execute(ctx context.Context, _ map[string]any, _ map[string]map[string]any, _, _, config map[string]any) (*sdk.StepResult, error)\n```\n\n```go\ntype SchemaModule struct {\n\t// contains filtered or unexported fields\n}\n```\nSchemaModule implements sdk.ModuleInstance for the migrate.schema module type.\n\n```go\nfunc LookupModule(name string) (*SchemaModule, error)\n```\nLookupModule retrieves a SchemaModule by name.\n\n```go\nfunc (m *SchemaModule) Init() error\n```\nInit validates the module configuration.\n\n```go\nfunc (m *SchemaModule) LockTable() string\n```\nLockTable returns the name of the migration state table.\n\n```go\nfunc (m *SchemaModule) OnBreakingChange() string\n```\nOnBreakingChange returns the configured breaking-change policy.\n\n```go\nfunc (m *SchemaModule) Schemas() []SchemaDefinition\n```\nSchemas returns the parsed declarative schema definitions.\n\n```go\nfunc (m *SchemaModule) Scripts() []MigrationScript\n```\nScripts returns the loaded migration scripts.\n\n```go\nfunc (m *SchemaModule) Start(_ context.Context) error\n```\nStart parses schema files and/or migration scripts based on the configured strategy, then registers this module in the global registry.\n\n```go\nfunc (m *SchemaModule) Stop(_ context.Context) error\n```\nStop deregisters the module.\n\n```go\ntype SchemaModuleConfig struct {\n\tStrategy         string       `json:\"strategy\"         yaml:\"strategy\"`         // declarative, scripted, or both\n\tTarget           string       `json:\"target\"           yaml:\"target\"`           // database module reference\n\tSchemas          []SchemaPath `json:\"schemas\"          yaml:\"schemas\"`          // YAML schema file paths\n\tMigrationsDir    string       `json:\"migrationsDir\"    yaml:\"migrationsDir\"`    // directory of NNN_*.sql files\n\tLockTable        string       `json:\"lockTable\"        yaml:\"lockTable\"`        // defaults to schema_migrations\n\tOnBreakingChange string       `json:\"onBreakingChange\" yaml:\"onBreakingChange\"` // block, warn, blue_green\n}\n```\nSchemaModuleConfig holds configuration for the migrate.schema module.\n\n```go\ntype SchemaPath struct {\n\tPath string `json:\"path\" yaml:\"path\"`\n}\n```\nSchemaPath is a reference to a YAML schema file.\n\n```go\ntype SchemaRegistryProvider interface {\n\tRegisterSubject(ctx context.Context, subject, schema string) (int, error)\n\tCheckCompatibility(ctx context.Context, subject, schema string) (bool, error)\n\tGetSchemaFields(ctx context.Context, subject string) ([]string, int, error)\n}\n```\nSchemaRegistryProvider registers schemas and checks compatibility. Also used by the verify step to read schema fields.\n\n```go\ntype TableUpdate struct {\n\tAction    string           `json:\"action\"` // \"add_column\", \"widen_type\"\n\tTable     string           `json:\"table\"`\n\tNamespace []string         `json:\"namespace\"`\n\tChanges   []map[string]any `json:\"changes\"`\n}\n```\nTableUpdate describes a change to apply to an Iceberg table.\n\n","path":"github.com/GoCodeAlone/workflow-plugin-data-engineering/internal/migrate","name":"migrate","synopsis":"Package migrate provides declarative schema diffing and scripted migration running.","isRedistributable":true}
