models

package
v0.0.0-...-114cbd0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBConnection

type DBConnection interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Close(ctx context.Context) error
	Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
}

DBConnection wrapper interface for interactions with db

func BuildConnector

func BuildConnector(ctx context.Context, str string) (conn DBConnection, err error)

type ExecutionContext

type ExecutionContext struct {
	Sql       string
	IsUp      bool
	Timestamp int64
	Name      string
}

type ImplModels

type ImplModels struct {
	Db DBConnection
}

ImplModels implementation of models interface with underlying database

func (*ImplModels) CreateMetaTable

func (models *ImplModels) CreateMetaTable() error

CreateMetaTable creates table named __pg_mig_meta that will be used for storing migration info

func (*ImplModels) Execute

func (models *ImplModels) Execute(executionContext ExecutionContext) error

Execute runs a migration within a transaction and updates meta table

func (*ImplModels) GetMigrationsList

func (models *ImplModels) GetMigrationsList() ([]int64, error)

GetMigrationsList - fetches timestamps of migrations that has been executed in current DB

func (*ImplModels) SquashMigrations

func (models *ImplModels) SquashMigrations(from time.Time, to time.Time, name int64) error

SquashMigrations deletes all migration instances in meta table between given timestamps (both inclusive). and writes a new squash migration with timestamp set to `to` variable value

type Models

type Models interface {
	CreateMetaTable() error
	GetMigrationsList() ([]int64, error)
	Execute(ExecutionContext) error
	SquashMigrations(time.Time, time.Time, int64) error
}

Models interface for interaction with database

Jump to

Keyboard shortcuts

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