bisonmigration

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

README

bisonmigration

A migration engine to deploy database changes in your golang + mongodb app.

Migration files register their UP and DOWN functions in the migration engine during the init phase.

Migrations file processed (UPs) are logged in a dedicated collection to keep track of what's already processed.

It is possible to process all pending migration files or specific ones. It is possible to rollback the last "batch" of migration files or specific files or until a specific one

Each migration file is uniquely identified and has a sequence number. It is possible to define how strict to be with sequence values:

  • process or not duplicate sequence number
  • process or not sequence smaller than previously processed values

This is particularly useful to tune the right amout of strictness to apply to the sequence of migrations. Big dev teams working on the same repo could generate the same sequence number or merge back an old feature branch with sequence number old.

It is up to team based on the worklflow to decide how to configure strictness.

Due to the nature of the process sequence checks are performed during the processing of the migration, not during their creation. For this reason a stricter environment could end up having more issues during CI/CD phase with migration issues. These issues should - in any case - be identified during test phase, not production.

Instead of integrating the migration tool in your main application it is suggested to create a dedicated command to run when needed. This will leave the main app cleaner and smaller.

Documentation

Index

Constants

View Source
const DbConnectionLabelDefault = "*DEFAULT*"
View Source
const MigrationAppDefaultCollection = "migrations"
View Source
const MigrationAppDefaultDatabase = "migrations"
View Source
const SequenceStrictnessNoDuplicates = "NODUPLICATES" //Sequence ids cannot be used more than once, they are unique (like all of us....)
View Source
const SequenceStrictnessNoLateComers = "NOLATECOMERS" //The system won't allow processing a sequence smaller then a sequence already processed

Variables

View Source
var Verbose bool = true

Functions

func CheckIfDbIsInitialised

func CheckIfDbIsInitialised() bool

func GetDbConnectionsMissing

func GetDbConnectionsMissing() []string

func GetMigrationAppCollectionExists

func GetMigrationAppCollectionExists() bool

func GetMigrationAppDatabaseExists

func GetMigrationAppDatabaseExists() bool

func GetMigrationFileTemplate

func GetMigrationFileTemplate() string

func GetMigrationsPendingCount

func GetMigrationsPendingCount() int

func GetMigrationsProcessedCount

func GetMigrationsProcessedCount() int

func GetMigrationsRegisteredCount

func GetMigrationsRegisteredCount() int

func InitialiseDatabase

func InitialiseDatabase()

func MigrationEngineInitialise

func MigrationEngineInitialise(databaseName string, collectionName string, dbClient *mongo.Client, sequenceStrictness []string)

func RegisterDbConnection

func RegisterDbConnection(label string, description string, dbClient *mongo.Client)

func RegisterMigration

func RegisterMigration(sequence int64, description string, dbConnLabel string, upFunction migrationFunctionSignatureType, downFunction migrationFunctionSignatureType)

func RollbackASpecificMigration

func RollbackASpecificMigration(migrationUniqueId string) error

func RollbackLastBatchMigrations

func RollbackLastBatchMigrations() error

func RollbackSingleLastMigration

func RollbackSingleLastMigration() error

func RollbackToSpecificMigration

func RollbackToSpecificMigration(migrationUniqueId string) error

func RunNextSingleMigration

func RunNextSingleMigration() error

func RunPendingMigrations

func RunPendingMigrations() error

func RunSpecificMigration

func RunSpecificMigration(migrationUniqueId string) error

func RunUpToSpecificMigration

func RunUpToSpecificMigration(migrationUniqueId string) error

Types

type DatabaseConnectionLabelType

type DatabaseConnectionLabelType struct {
	Label string

	Description string
	// contains filtered or unexported fields
}

func GetConnectionsLabels

func GetConnectionsLabels() []DatabaseConnectionLabelType

type MigrationsProcessedType

type MigrationsProcessedType []migrationDbRecordType

func GetMigrationsProcessed

func GetMigrationsProcessed() MigrationsProcessedType

type MigrationsRegisteredType

type MigrationsRegisteredType []migrationRegisteredType

func GetMigrationsPending

func GetMigrationsPending() MigrationsRegisteredType

func GetMigrationsRegistered

func GetMigrationsRegistered() MigrationsRegisteredType

Jump to

Keyboard shortcuts

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