migrations

package
v0.1.5-beta Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnSchema

type ColumnSchema struct {
	Name       string
	Type       string
	Nullable   bool
	Default    interface{}
	PrimaryKey bool
	Unique     bool
}

ColumnSchema representa uma coluna no banco

type Detector

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

Detector detecta mudanças nos models

func NewDetector

func NewDetector() *Detector

NewDetector cria um novo detector

func (*Detector) DetectChanges

func (d *Detector) DetectChanges() ([]SchemaChange, error)

DetectChanges escaneia os models e detecta mudanças

func (*Detector) GenerateMigrationFile

func (d *Detector) GenerateMigrationFile(changes []SchemaChange, name string) (string, error)

GenerateMigrationFile gera arquivo de migration

type IndexSchema

type IndexSchema struct {
	Name    string
	Columns []string
	Unique  bool
}

IndexSchema representa um índice no banco

type MigrationInfo

type MigrationInfo struct {
	Version     string
	Description string
	AppliedAt   *time.Time
}

MigrationInfo contém informações sobre uma migration

type MigrationStatus

type MigrationStatus struct {
	Applied []MigrationInfo
	Pending []MigrationInfo
}

MigrationStatus representa o status das migrations

type Runner

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

Runner executa migrations

func NewRunner

func NewRunner() *Runner

NewRunner cria um novo runner

func (*Runner) GetStatus

func (r *Runner) GetStatus() (*MigrationStatus, error)

GetStatus retorna o status das migrations

func (*Runner) MigrateDown

func (r *Runner) MigrateDown(steps int) (int, error)

MigrateDown reverte migrations

func (*Runner) MigrateDownTo

func (r *Runner) MigrateDownTo(version string) (int, error)

MigrateDownTo reverte até uma versão específica

func (*Runner) MigrateUp

func (r *Runner) MigrateUp(steps int) (int, error)

MigrateUp aplica migrations pendentes

type SQLGenerator

type SQLGenerator struct{}

SQLGenerator gera SQL para migrations

func NewSQLGenerator

func NewSQLGenerator() *SQLGenerator

NewSQLGenerator cria um novo gerador de SQL

func (*SQLGenerator) Generate

func (g *SQLGenerator) Generate(changes []SchemaChange, driver string) (up string, down string)

Generate gera SQL UP e DOWN para as mudanças

func (*SQLGenerator) GenerateFullTableDDL

func (g *SQLGenerator) GenerateFullTableDDL(metadata *parser.ModelMetadata, driver string) string

GenerateFullTableDDL gera DDL completo para uma tabela baseado no model

type SchemaChange

type SchemaChange struct {
	Type        string // CREATE_TABLE, ADD_COLUMN, DROP_COLUMN, ALTER_COLUMN, etc
	ModelName   string
	TableName   string
	Field       string
	Description string
	OldValue    interface{}
	NewValue    interface{}
}

SchemaChange representa uma mudança no schema

type TableSchema

type TableSchema struct {
	Name    string
	Columns []*ColumnSchema
	Indexes []*IndexSchema
}

TableSchema representa o schema de uma tabela no banco

Jump to

Keyboard shortcuts

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