migration

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

type Migration struct {
	ID        uint   `gorm:"primaryKey"`
	Migration string `gorm:"uniqueIndex;not null"`
	Batch     int    `gorm:"not null"`
	CreatedAt time.Time
}

Migration represents a single migration

type MigrationInterface

type MigrationInterface interface {
	Up() error
	Down() error
	Signature() string
}

MigrationInterface defines the interface for migrations

type MigrationStatus

type MigrationStatus struct {
	Migration string
	Batch     int
	Status    string
}

MigrationStatus represents the status of a migration

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator handles database migrations

func NewMigrator

func NewMigrator(db *gorm.DB, tableName string) *Migrator

NewMigrator creates a new migrator instance

func (*Migrator) CreateMigrationsTable

func (m *Migrator) CreateMigrationsTable() error

CreateMigrationsTable creates the migrations table

func (*Migrator) GenerateMigrationFile

func (m *Migrator) GenerateMigrationFile(name string) error

GenerateMigrationFile generates a new migration file

func (*Migrator) RegisterMigration

func (m *Migrator) RegisterMigration(migration MigrationInterface)

RegisterMigration registers a migration

func (*Migrator) Rollback

func (m *Migrator) Rollback(steps int) error

Rollback rolls back the last batch of migrations

func (*Migrator) Run

func (m *Migrator) Run() error

Run runs all pending migrations

func (*Migrator) Status

func (m *Migrator) Status() ([]MigrationStatus, error)

Status returns the status of all migrations

Jump to

Keyboard shortcuts

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