migrations

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package migrations provides edition-aware database migration loading.

Package migrations provides edition-aware database migration loading.

Index

Constants

This section is empty.

Variables

View Source
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

func CountByEdition(migrations []Migration) map[Edition]int

CountByEdition counts migrations by edition.

func FilterMigrations

func FilterMigrations(versions []string, edition Edition) []string

FilterMigrations filters a list of migration versions by edition.

func GetMigrationVersions

func GetMigrationVersions(migrations []Migration) []string

GetMigrationVersions returns all migration versions from a list.

func GroupByEdition

func GroupByEdition(migrations []Migration) map[Edition][]Migration

GroupByEdition groups migrations by their edition.

func ReadMigrationContent

func ReadMigrationContent(m Migration) ([]byte, error)

ReadMigrationContent reads the content of a migration file.

func ShouldRunMigration

func ShouldRunMigration(migrationVersion string, targetEdition Edition) bool

ShouldRunMigration checks if a migration should run for the given edition.

Types

type Edition

type Edition string

Edition represents the product edition.

const (
	EditionCore       Edition = "core"
	EditionEnterprise Edition = "enterprise"
	EditionSaaS       Edition = "saas"
)

func GetMigrationEdition

func GetMigrationEdition(version string) Edition

GetMigrationEdition returns the edition for a migration number. Returns EditionCore if not classified (default safe behavior).

func ParseEdition

func ParseEdition(s string) (Edition, error)

ParseEdition parses an edition string.

func (Edition) IsValid

func (e Edition) IsValid() bool

IsValid checks if the edition is valid.

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

func LoadMigrationsFromDir(dir string, edition Edition, direction string) ([]Migration, error)

LoadMigrationsFromDir loads migrations from a directory, filtered by edition. - EditionCore: only core migrations - EditionEnterprise: core + enterprise migrations - EditionSaaS: core + enterprise + saas migrations

func (Migration) String

func (m Migration) String() string

String returns the migration identifier.

type MigrationRecord

type MigrationRecord struct {
	Version   string
	AppliedAt time.Time
	Edition   string
}

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 NewRunner

func NewRunner(db *sql.DB, migrationsDir string, edition Edition) *Runner

NewRunner creates a new migration runner.

func (*Runner) Down

func (r *Runner) Down(ctx context.Context) error

Down rolls back the last migration.

func (*Runner) EnsureMigrationTable

func (r *Runner) EnsureMigrationTable(ctx context.Context) error

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

func (r *Runner) GetPendingMigrations(ctx context.Context) ([]string, error)

GetPendingMigrations returns migrations that need to be applied.

func (*Runner) Status

func (r *Runner) Status(ctx context.Context) error

Status prints the migration status.

func (*Runner) Up

func (r *Runner) Up(ctx context.Context) error

Up runs all pending migrations.

Jump to

Keyboard shortcuts

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