mig

package
v0.0.0-...-be3f9aa Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlowNumLimit = 4095 // FFF
	StepNumLimit = 255  // FF
)

limits

View Source
const DefaultDialect = "postgres"
View Source
const DefaultTrackingTable = "mig_applied_migrations"

Variables

This section is empty.

Functions

func MakeID

func MakeID(prefix string, flowNum, stepNum int) string

MakeID creates a migration ID from a given flow and step num flowNum and stepNum are converted to hex and appended to the prefix the intention is for each file to be numbered by its flowNum 001, 002 etc. but allow it to add related migrations in the future with stepNums this way create table and future alter table statements can be together in the same file

if you want your ID's to be valid uuid's then simply remove the last 6 chars from a baseID to create your prefix, such as "46855208-d306-4da2-bd18-30f7bc" as the flowNum and stepNum will always result in 6 chars, 3 for each number

Types

type Flow

type Flow []Step

type Runner

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

func NewRunner

func NewRunner(db *sql.DB) Runner

func (*Runner) Up

func (r *Runner) Up() error

func (Runner) WithDialect

func (r Runner) WithDialect(dialect string) Runner

WithDialect allows you to use something other than the default "postgres"

func (Runner) WithFlows

func (r Runner) WithFlows(flows ...*Flow) Runner

func (Runner) WithLogger

func (r Runner) WithLogger(l logger) Runner

func (Runner) WithSchema

func (r Runner) WithSchema(schemaName string) Runner

WithSchema sets the schemaName that the migration table is created in if that schema does not already exist it will try to create it for you

func (Runner) WithTrackingTable

func (r Runner) WithTrackingTable(tblName string) Runner

WithTrackingTable can be used to change the table name that migrations are recorded in if you qualify the table name with the schema it will also set the schema so tblName = "migrations" will set the table name leaving schemaName unchanged and tblName = "foo.migrations" will set both schema=foo, tbl=migrations

type Step

type Step struct {
	ID   string
	Up   string
	Down string
}

Jump to

Keyboard shortcuts

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