migrate

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate(ctx context.Context, db *sql.DB, dialect core.Dialect, models ...interface{}) error

AutoMigrate cria automaticamente tabelas a partir de structs. Útil para desenvolvimento rápido, mas não recomendado para produção.

Types

type Config

type Config struct {
	// TableName é o nome da tabela de controle (default: "schema_migrations")
	TableName string
}

Config contém configurações para o Migrator.

type Migration

type Migration struct {
	// Version é o número da versão da migration (ex: 1, 2, 3, etc.)
	Version int64
	// Name é o nome descritivo da migration (ex: "create_users_table")
	Name string
	// Up é executado quando aplicando a migration
	Up func(context.Context, *sql.DB, core.Dialect) error
	// Down é executado quando revertendo a migration
	Down func(context.Context, *sql.DB, core.Dialect) error
}

Migration representa uma migration com funções Up e Down.

func CreateTableMigration

func CreateTableMigration(version int64, name string, model interface{}) Migration

CreateTableMigration cria uma migration para criar uma tabela a partir de uma struct.

type MigrationStatus

type MigrationStatus struct {
	Version int64
	Name    string
	Applied bool
}

MigrationStatus representa o status de uma migration.

type Migrator

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

Migrator gerencia migrations de banco de dados.

func New

func New(db *sql.DB, dialect core.Dialect, logger core.Logger, config Config) *Migrator

New cria um novo Migrator.

func (*Migrator) Down

func (m *Migrator) Down(ctx context.Context) error

Down reverte a última migration aplicada.

func (*Migrator) Register

func (m *Migrator) Register(migration Migration)

Register registra uma nova migration.

func (*Migrator) RegisterMultiple

func (m *Migrator) RegisterMultiple(migrations []Migration)

RegisterMultiple registra múltiplas migrations.

func (*Migrator) Status

func (m *Migrator) Status(ctx context.Context) ([]MigrationStatus, error)

Status mostra o status de todas as migrations.

func (*Migrator) Up

func (m *Migrator) Up(ctx context.Context) error

Up aplica todas as migrations pendentes.

Jump to

Keyboard shortcuts

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