Documentation
¶
Overview ¶
Package migrator provides schema snapshot, diff, and SQL migration helpers for the Rain CLI.
Index ¶
- func ApplySQLMigrations(ctx context.Context, db *sql.DB, dialectName, tableName string, ...) (migrate.ApplyResult, error)
- func MarshalSnapshot(snapshot Snapshot) ([]byte, error)
- func SplitSQLStatements(sqlText string) ([]string, error)
- type ColumnSnapshot
- type ConstraintSnapshot
- type DiskMigration
- type ForeignKeySnapshot
- type IndexSnapshot
- type Plan
- type Registry
- type Snapshot
- type TableSnapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySQLMigrations ¶
func ApplySQLMigrations(ctx context.Context, db *sql.DB, dialectName, tableName string, migrationsOnDisk []DiskMigration) (migrate.ApplyResult, error)
ApplySQLMigrations applies ordered SQL migrations using the existing migration table tracking.
func MarshalSnapshot ¶
MarshalSnapshot produces stable, indented JSON for disk storage.
func SplitSQLStatements ¶
SplitSQLStatements splits one migration file into executable statements.
Types ¶
type ColumnSnapshot ¶
type ColumnSnapshot struct {
Name string `json:"name"`
Type schema.ColumnType `json:"type"`
Nullable bool `json:"nullable"`
DefaultSQL string `json:"default_sql,omitempty"`
HasDefault bool `json:"has_default"`
PrimaryKey bool `json:"primary_key"`
AutoIncrement bool `json:"auto_increment"`
Unique bool `json:"unique"`
DefinitionSQL string `json:"definition_sql"`
}
ColumnSnapshot stores one column definition and its additive DDL fragment.
type ConstraintSnapshot ¶
type ConstraintSnapshot struct {
Name string `json:"name"`
Type string `json:"type"`
SQL string `json:"sql"`
}
ConstraintSnapshot stores one table-level constraint.
type DiskMigration ¶
type DiskMigration struct {
ID string
Name string
DirPath string
SQLPath string
SnapshotPath string
SQL string
Snapshot Snapshot
}
DiskMigration represents one migration folder on disk.
func LoadDiskMigrations ¶
func LoadDiskMigrations(dir string) ([]DiskMigration, error)
LoadDiskMigrations reads ordered migration folders and validates required files.
func WriteMigrationFiles ¶
func WriteMigrationFiles(dir, name string, plan Plan, snapshot Snapshot, now time.Time) (DiskMigration, error)
WriteMigrationFiles writes one Drizzle-style migration folder containing migration.sql and snapshot.json.
type ForeignKeySnapshot ¶
ForeignKeySnapshot stores one single-column foreign key.
type IndexSnapshot ¶
IndexSnapshot stores one standalone index.
type Plan ¶
type Plan struct {
Statements []string
}
Plan summarizes one additive migration diff.
func DiffSnapshots ¶
DiffSnapshots creates an additive-only migration plan.
type Registry ¶
type Registry func() []schema.TableReference
Registry returns the managed tables that participate in migration generation.
type Snapshot ¶
type Snapshot struct {
Version int `json:"version"`
Dialect string `json:"dialect"`
Tables []TableSnapshot `json:"tables"`
}
Snapshot captures a deterministic schema view and the SQL fragments needed for additive diffs.
func BuildSnapshot ¶
func BuildSnapshot(dialectName string, tables []schema.TableReference) (Snapshot, error)
BuildSnapshot compiles managed tables into a deterministic snapshot.
func ReadLatestSnapshotFromMigrations ¶
ReadLatestSnapshotFromMigrations returns the newest migration snapshot or nil when no migrations exist.
func UnmarshalSnapshot ¶
UnmarshalSnapshot parses one JSON snapshot file.
type TableSnapshot ¶
type TableSnapshot struct {
Name string `json:"name"`
CreateTableSQL string `json:"create_table_sql"`
Columns []ColumnSnapshot `json:"columns"`
Constraints []ConstraintSnapshot `json:"constraints"`
ForeignKeys []ForeignKeySnapshot `json:"foreign_keys"`
Indexes []IndexSnapshot `json:"indexes"`
}
TableSnapshot stores a portable, deterministic representation of one table.