migrate

package
v0.6.39 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(db *bun.DB, sql string, isTx bool, splitter string) (err error)

func GenerateDown

func GenerateDown(upSql string) (string, error)

func GenerateDownLine

func GenerateDownLine(up string) (string, error)

func GenerateDownLineWithContext added in v0.6.14

func GenerateDownLineWithContext(up string, c *Context) (down string, err error)

func GenerateDownWithContext added in v0.6.14

func GenerateDownWithContext(upSql string, c *Context) (down string, err error)

func Name

func Name(s string) (name string, comment string, isUp bool, isTx bool, ok bool)

func ReadSql

func ReadSql(f fs.FS, path string) (sql string, err error)

Types

type Column added in v0.6.14

type Column struct {
	Name        string
	Type        string
	Constraints string
}

type Context added in v0.6.14

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

func NewContext added in v0.6.14

func NewContext() *Context

func (*Context) Process added in v0.6.14

func (o *Context) Process(l []string) error

type DownGenerator

type DownGenerator struct {
	Process func(string) bool
	Command string
	Error   error
	// contains filtered or unexported fields
}

func NewDownGenerator

func NewDownGenerator(c *Context) *DownGenerator

type Migration

type Migration struct {
	bun.BaseModel

	Id         int64     `bun:",pk,autoincrement"`
	Name       string    `bun:",notnull"`
	Comment    string    `bun:",notnull"`
	IsTx       bool      `bun:",notnull"`
	UpHash     string    `bun:",notnull"`
	DownHash   string    `bun:",notnull"`
	UpSql      string    `bun:"-"`
	DownSql    string    `bun:",notnull"`
	GroupId    int64     `bun:",notnull"`
	MigratedAt time.Time `bun:",notnull"`

	Up   func() error `bun:"-"`
	Down func() error `bun:"-"`
	// contains filtered or unexported fields
}

func (*Migration) AutoGenerateDown

func (o *Migration) AutoGenerateDown(c *Context) error

func (*Migration) DownHashIsValid

func (o *Migration) DownHashIsValid() bool

func (Migration) Error

func (o Migration) Error() error

func (*Migration) GenerateDown

func (o *Migration) GenerateDown(c *Context) (err error)

func (*Migration) IsApplied

func (o *Migration) IsApplied() bool

func (*Migration) Lost

func (o *Migration) Lost() bool

func (*Migration) PreviewDown

func (o *Migration) PreviewDown(c *Context) (string, error)

func (*Migration) RepairDown added in v0.6.14

func (o *Migration) RepairDown(c *Context) (ok bool, err error)

func (*Migration) SetApplied

func (o *Migration) SetApplied(groupId int64)

func (*Migration) SetFuncs

func (o *Migration) SetFuncs(db *bun.DB, splitter string)

func (*Migration) SetUnapplied

func (o *Migration) SetUnapplied()

func (Migration) String

func (o Migration) String() string

func (*Migration) UpHashIsValid

func (o *Migration) UpHashIsValid() bool

type Migrations

type Migrations []*Migration

func (Migrations) Applied

func (o Migrations) Applied() (applied Migrations)

func (*Migrations) AutoGenerateDown

func (o *Migrations) AutoGenerateDown() (err error)

func (Migrations) Count

func (o Migrations) Count() int

func (Migrations) Last

func (o Migrations) Last() *Migration

func (Migrations) LastGroup

func (o Migrations) LastGroup() (l Migrations)

func (Migrations) LastGroupId

func (o Migrations) LastGroupId() (lastGroupId int64)

func (*Migrations) Load

func (o *Migrations) Load(f fs.FS) error

func (Migrations) PreviewDown added in v0.6.14

func (o Migrations) PreviewDown() (name string, down string, err error)

func (*Migrations) RepairDown added in v0.6.14

func (o *Migrations) RepairDown(update func(*Migration) error) (names []string, err error)

func (Migrations) SetFuncs

func (o Migrations) SetFuncs(db *bun.DB, splitter string)

func (Migrations) SortAsc

func (o Migrations) SortAsc()

func (Migrations) SortDesc

func (o Migrations) SortDesc()

func (Migrations) Unapplied

func (o Migrations) Unapplied() (unapplied Migrations)

type Migrator

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

func NewMigrator

func NewMigrator(db *bun.DB) *Migrator

func (*Migrator) AppliedMigrations

func (o *Migrator) AppliedMigrations() (l Migrations)

func (*Migrator) AppliedMigrationsCount

func (o *Migrator) AppliedMigrationsCount() int

func (*Migrator) Forget

func (o *Migrator) Forget() (err error)

func (*Migrator) HasIncompleteMigrations added in v0.4.13

func (o *Migrator) HasIncompleteMigrations() bool

func (*Migrator) Init

func (o *Migrator) Init() (err error)

func (*Migrator) Load

func (o *Migrator) Load(fs fs.FS) (err error)

func (*Migrator) Migrate

func (o *Migrator) Migrate() (err error)

func (*Migrator) Migrations

func (o *Migrator) Migrations() Migrations

func (*Migrator) MigrationsCount

func (o *Migrator) MigrationsCount() int

func (*Migrator) RepairDown added in v0.6.14

func (o *Migrator) RepairDown() ([]string, error)

func (*Migrator) Reset

func (o *Migrator) Reset() (err error)

func (*Migrator) Rollback

func (o *Migrator) Rollback() error

func (*Migrator) RollbackLast

func (o *Migrator) RollbackLast() (err error)

func (*Migrator) RolledbackMigrations added in v0.4.13

func (o *Migrator) RolledbackMigrations() (l Migrations)

func (*Migrator) RolledbackMigrationsCount added in v0.4.13

func (o *Migrator) RolledbackMigrationsCount() int

func (*Migrator) Status

func (o *Migrator) Status() string

func (*Migrator) UnappliedMigrations

func (o *Migrator) UnappliedMigrations() (l Migrations)

func (*Migrator) UnappliedMigrationsCount

func (o *Migrator) UnappliedMigrationsCount() int

func (*Migrator) WithAutoDownSql

func (o *Migrator) WithAutoDownSql(v bool) *Migrator

func (*Migrator) WithMarkAppliedOnSuccess

func (o *Migrator) WithMarkAppliedOnSuccess(v bool) *Migrator

func (*Migrator) WithReadonly added in v0.6.14

func (o *Migrator) WithReadonly(ro bool) *Migrator

func (*Migrator) WithRollbackLost

func (o *Migrator) WithRollbackLost(v bool) *Migrator

func (*Migrator) WithSaveDownSql

func (o *Migrator) WithSaveDownSql(v bool) *Migrator

func (*Migrator) WithSplitter

func (o *Migrator) WithSplitter(v string) *Migrator

func (*Migrator) WithTableName

func (o *Migrator) WithTableName(v string) *Migrator

type Schema added in v0.6.14

type Schema struct {
	Tables []Table
}

func (*Schema) AddColumn added in v0.6.14

func (o *Schema) AddColumn(tableName, columnName, columnType, columnConstraints string) error

func (*Schema) AddTable added in v0.6.14

func (o *Schema) AddTable(name string) error

func (*Schema) AlterColumnType added in v0.6.14

func (o *Schema) AlterColumnType(tableName, columnName, columnType string) error

func (*Schema) Column added in v0.6.14

func (o *Schema) Column(tableName, columnName string) (r *Column, err error)

func (*Schema) ColumnType added in v0.6.14

func (o *Schema) ColumnType(tableName, columnName string) (columnType string, columnConstraints string, err error)

func (*Schema) DromColumn added in v0.6.14

func (o *Schema) DromColumn(tableName, columnName string) error

func (*Schema) DromTable added in v0.6.14

func (o *Schema) DromTable(name string) error

func (*Schema) Table added in v0.6.14

func (o *Schema) Table(name string) (r *Table, err error)

type Table added in v0.6.14

type Table struct {
	Name    string
	Columns []Column
}

func (*Table) Column added in v0.6.14

func (o *Table) Column(name string) (r *Column, err error)

Jump to

Keyboard shortcuts

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