Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMigrationTableNameMissing is returned when the migrations table name is empty ErrMigrationTableNameMissing = errors.New("migrations table name cannot be empty") // ErrUnknownDriver is returned when the driver is unknown ErrUnknownDriver = errors.New("unknown driver") // ErrInvalidMigrationFile is returned when the migration file is invalid ErrInvalidMigrationFile = errors.New("invalid migration file") // ErrMigrationFolder is returned when the migration folder is invalid ErrMigrationFolder = errors.New("invalid migration folder") // ErrInvalidQuery is returned when the query is invalid ErrInvalidQuery = errors.New("invalid query") )
Functions ¶
This section is empty.
Types ¶
type DBDriver ¶
type DBDriver interface { // Dialect returns the database dialect Dialect() string // Close closes the connection to the database Close(ctx context.Context) error // CreateMigrationsTable creates the migrations table // migrationsTable is the name of the migrations table // If the table already exists, it does nothing // It returns an error if something goes wrong CreateMigrationsTable(ctx context.Context, migrationsTable string) error // SelectMigrations selects all migrations from the migrations table // migrationsTable is the name of the migrations table // It returns a sorted slice (by Version ascending) of migrations or an error SelectMigrations(ctx context.Context, migrationsTable string) ([]Migration, error) // ApplyMigrations applies migrations to the database // migrationsTable is the name of the migrations table // inTx is a flag that indicates if the migrations should be applied in a transaction // migrations is the slice of migrations to apply // It returns an error if something goes wrong ApplyMigrations(ctx context.Context, migrationsTable string, inTx bool, migrations []Migration) error }
DBDriver represents a database driver
type Migration ¶
type Migration struct { Version int Fname string AppliedAt *time.Time Statements []string Hash string }
Migration represents a single migration
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator is a struct that represents a migrator It is used to migrate a database
type Option ¶
Option represents a migrator option
func WithEmbedFS ¶
WithEmbedFS is an option to use the embed filesystem The fs is the embed filesystem It is nil by default
func WithInTransaction ¶
func WithInTransaction() Option
WithInTransaction is an option to apply all migrations in a transaction If an error occurs, the transaction is rolled back It is disabled by default
func WithMigrationTable ¶
WithMigrationTable is an option to set the migrations table name It is "schema_migrations" by default
func WithQueryValidator ¶
func WithQueryValidator(validator QueryValidator) Option
WithQueryValidator is an option to enable query validation It is disabled by default Its purpose is to validate queries before applying them
func WithSystemFS ¶
WithSystemFS is an option to use the system filesystem The root is the root folder of the migrations It is "migrations" by default