Documentation
¶
Overview ¶
Package migrations provides edition-aware database migration loading.
Package migrations provides edition-aware database migration loading.
Index ¶
- Variables
- func CountByEdition(migrations []Migration) map[Edition]int
- func FilterMigrations(versions []string, edition Edition) []string
- func GetMigrationVersions(migrations []Migration) []string
- func GroupByEdition(migrations []Migration) map[Edition][]Migration
- func ReadMigrationContent(m Migration) ([]byte, error)
- func ShouldRunMigration(migrationVersion string, targetEdition Edition) bool
- type Edition
- type Migration
- type MigrationRecord
- type Runner
- func (r *Runner) Down(ctx context.Context) error
- func (r *Runner) EnsureMigrationTable(ctx context.Context) error
- func (r *Runner) GetAppliedMigrations(ctx context.Context) ([]MigrationRecord, error)
- func (r *Runner) GetPendingMigrations(ctx context.Context) ([]string, error)
- func (r *Runner) Status(ctx context.Context) error
- func (r *Runner) Up(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var MigrationClassification = map[string]Edition{ "000001": EditionCore, "000002": EditionCore, "000003": EditionCore, "000004": EditionCore, "000005": EditionCore, "000006": EditionCore, "000007": EditionCore, "000008": EditionCore, "000009": EditionCore, "000010": EditionCore, "000011": EditionCore, "000012": EditionCore, "000013": EditionCore, "000014": EditionCore, "000015": EditionCore, "000016": EditionCore, "000017": EditionCore, "000018": EditionCore, "000019": EditionCore, "000020": EditionCore, "000021": EditionCore, "000022": EditionCore, "000023": EditionCore, "000024": EditionCore, "000025": EditionCore, "000026": EditionCore, "000027": EditionCore, "000028": EditionCore, "000029": EditionCore, "000030": EditionCore, "000031": EditionCore, "000032": EditionCore, "000033": EditionCore, "000034": EditionCore, "000035": EditionCore, "000036": EditionCore, "000037": EditionCore, "000038": EditionCore, "000039": EditionCore, "000040": EditionCore, "000041": EditionCore, "000042": EditionCore, "000043": EditionCore, "000044": EditionCore, "000045": EditionCore, "000046": EditionCore, "000047": EditionCore, "000048": EditionCore, "000049": EditionCore, "000050": EditionEnterprise, "000051": EditionEnterprise, "000052": EditionEnterprise, "000053": EditionEnterprise, "000054": EditionEnterprise, "000055": EditionEnterprise, "000056": EditionEnterprise, "000057": EditionEnterprise, "000058": EditionEnterprise, "000059": EditionEnterprise, "000060": EditionEnterprise, "000061": EditionEnterprise, "000062": EditionEnterprise, "000063": EditionEnterprise, "000064": EditionEnterprise, "000065": EditionEnterprise, "000066": EditionEnterprise, "000067": EditionEnterprise, "000068": EditionEnterprise, "000069": EditionEnterprise, "000070": EditionEnterprise, "000071": EditionEnterprise, "000072": EditionEnterprise, "000073": EditionEnterprise, "000074": EditionEnterprise, "000075": EditionEnterprise, "000076": EditionEnterprise, "000077": EditionEnterprise, "000078": EditionEnterprise, "000079": EditionEnterprise, "000080": EditionSaaS, "000081": EditionSaaS, "000082": EditionSaaS, "000083": EditionSaaS, "000084": EditionSaaS, "000085": EditionSaaS, "000086": EditionSaaS, "000087": EditionSaaS, "000088": EditionSaaS, "000089": EditionSaaS, "000090": EditionSaaS, "000091": EditionSaaS, "000092": EditionSaaS, "000093": EditionSaaS, "000094": EditionSaaS, "000095": EditionSaaS, "000096": EditionSaaS, "000097": EditionSaaS, "000098": EditionSaaS, "000099": EditionSaaS, }
MigrationClassification maps migration numbers to their edition. This allows the existing flat migrations to be filtered by edition.
Convention: - Migrations 000001-000049: Core (OSS) - Migrations 000050-000079: Enterprise - Migrations 000080-000099: SaaS Platform - Migrations 000100+: Features (tagged individually)
Functions ¶
func CountByEdition ¶
CountByEdition counts migrations by edition.
func FilterMigrations ¶
FilterMigrations filters a list of migration versions by edition.
func GetMigrationVersions ¶
GetMigrationVersions returns all migration versions from a list.
func GroupByEdition ¶
GroupByEdition groups migrations by their edition.
func ReadMigrationContent ¶
ReadMigrationContent reads the content of a migration file.
func ShouldRunMigration ¶
ShouldRunMigration checks if a migration should run for the given edition.
Types ¶
type Edition ¶
type Edition string
Edition represents the product edition.
func GetMigrationEdition ¶
GetMigrationEdition returns the edition for a migration number. Returns EditionCore if not classified (default safe behavior).
func ParseEdition ¶
ParseEdition parses an edition string.
type Migration ¶
type Migration struct {
Version string
Name string
Edition Edition
Direction string // "up" or "down"
FilePath string
}
Migration represents a database migration file.
func LoadMigrationsFromDir ¶
LoadMigrationsFromDir loads migrations from a directory, filtered by edition. - EditionCore: only core migrations - EditionEnterprise: core + enterprise migrations - EditionSaaS: core + enterprise + saas migrations
type MigrationRecord ¶
MigrationRecord represents a migration in the schema_migrations table.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes database migrations with edition awareness.
func (*Runner) EnsureMigrationTable ¶
EnsureMigrationTable creates the schema_migrations table if it doesn't exist.
func (*Runner) GetAppliedMigrations ¶
func (r *Runner) GetAppliedMigrations(ctx context.Context) ([]MigrationRecord, error)
GetAppliedMigrations returns all applied migration versions.
func (*Runner) GetPendingMigrations ¶
GetPendingMigrations returns migrations that need to be applied.