Documentation
¶
Index ¶
- func ConnectFromEnv() (*sql.DB, dialect.Dialect, error)
- func Fresh(db *sql.DB, d dialect.Dialect) error
- func Register(name string, m any)
- func RegisterFunc(name string, up func(builder *schema.Builder) error)
- func Rollback(db *sql.DB, d dialect.Dialect, steps int) error
- func RunPending(db *sql.DB, d dialect.Dialect) error
- func Status(db *sql.DB, d dialect.Dialect) error
- type FuncMigration
- type Migration
- type Migrator
- func (m *Migrator) Fresh() error
- func (m *Migrator) Migrate() error
- func (m *Migrator) MigrateOne(name string) error
- func (m *Migrator) Refresh() error
- func (m *Migrator) Rollback() error
- func (m *Migrator) RollbackMigration(name string) error
- func (m *Migrator) RollbackSteps(steps int) error
- func (m *Migrator) Setup() error
- func (m *Migrator) Status() error
- type Registry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectFromEnv ¶
ConnectFromEnv reads standard environment variables (DB_CONNECTION, DB_DATABASE, etc.) and returns a ready *sql.DB connection along with the matching Dialect.
It does **not** automatically load .env files — callers (especially the CLI generated runner) should call godotenv.Load() first if they want .env support.
func Fresh ¶
Fresh drops the migrations table (if it exists) and re-runs all migrations from scratch.
func Register ¶
Register registers a migration with the default (global) registry. Generated migration files call this in their init() function. It accepts either a Migration interface or a bare function with signature func(*schema.Builder) error.
func RegisterFunc ¶
RegisterFunc registers a bare function as a Migration (Down is a no-op).
func RunPending ¶
RunPending runs all pending migrations using the provided DB and Dialect.
Types ¶
type FuncMigration ¶
type FuncMigration struct {
UpFunc func(builder *schema.Builder) error
DownFunc func(builder *schema.Builder) error
}
FuncMigration wraps a single Up function as a Migration with a no-op Down.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator runs migrations against the database.
func DefaultMigrator ¶
DefaultMigrator returns a new Migrator wired to the default registry. This is the recommended way to run migrations when using the high-level API.
func NewMigrator ¶
NewMigrator creates a new Migrator instance.
func (*Migrator) Fresh ¶
Fresh drops the migrations table and re-runs all migrations from scratch. This is equivalent to a clean database state.
func (*Migrator) MigrateOne ¶
MigrateOne runs a single specific migration (by name) if it is pending.
func (*Migrator) RollbackMigration ¶
RollbackMigration rolls back one specific migration by name.
func (*Migrator) RollbackSteps ¶
RollbackSteps rolls back the last N migrations (regardless of batch). This matches Laravel's `migrate:rollback --step=N` behavior.