core

package
v0.0.0-...-cb75879 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Postgresql string = "postgres"
	Mysql             = "mysql"
	SqlServer         = "sqlserver"
	Oracle            = "oracle"
)

Variables

View Source
var SqlConnectionUrlRegex = regexp.MustCompile("^([a-z]+?):\\/\\/(.+?):(.+?)@([\\w:\\.]+?)\\/([\\w_]+?)([\\?].+?)?$")
View Source
var VersionRangeRegex = regexp.MustCompile("^([U|V][\\d_\\.]+?):([U|V][\\d_\\.]+?)$")
View Source
var VersionRegex = regexp.MustCompile("([V|U])([\\d_\\.]+?)__(.+?)(\\.\\w{2,6})")
View Source
var VersionShortRegex = regexp.MustCompile("^([U|V])([\\d_\\.]+?)$")

Functions

func CompareVersionStr

func CompareVersionStr(left string, right string) bool

CompareVersionStr If left is smaller than the right one, then true.

If both are the same, then true.

Example:

CompareVersionStr("1_0", "0_1") -> false
CompareVersionStr("1_0", "1_10") -> true
CompareVersionStr("1_0_5", "1_10") -> true

func CreateVersionTable

func CreateVersionTable(url string, verbose bool, schema string) error

func EqualsVersionFullAndShort

func EqualsVersionFullAndShort(leftVersionShort *VersionShort, rightVersionShort *Version) bool

func EqualsVersionShort

func EqualsVersionShort(leftVersionShort *VersionShort, rightVersionShort *VersionShort) bool

func ExecuteMigrationString

func ExecuteMigrationString(url string, sqlString string, verbose bool) error

func GenerateConsecutiveDowngradesMigrationString

func GenerateConsecutiveDowngradesMigrationString(flavor string, path string, schema string, currentVersion *VersionShort, times int) (string, error)

func GenerateMigrationString

func GenerateMigrationString(node *MigrationNode) string

func GenerateMigrationStringFromVersionShortRange

func GenerateMigrationStringFromVersionShortRange(init bool, flavor string, path string, schema string, currentVersion *VersionShort, leftVersion *VersionShort, rightVersion *VersionShort) (string, error)

func GenerateTransactionString

func GenerateTransactionString(flavor string, sql string) (string, error)

func GetCreateVersionTableQueryString

func GetCreateVersionTableQueryString(schema string) string

func GetDatabaseConnection

func GetDatabaseConnection(url string, verbose bool) (*sql.DB, string, error)

func GetUpdateVersionQueryString

func GetUpdateVersionQueryString(init bool, currentVersion *VersionShort, version *VersionShort, schema string) string

func GetVersionTableName

func GetVersionTableName(schema string) string

func ParseVersionShortRange

func ParseVersionShortRange(versionShortRange string) (*VersionShort, *VersionShort, error)

func PrintMigrationTree

func PrintMigrationTree(root *MigrationNode, currentVersion *VersionShort)

func TransverseMigrationTree

func TransverseMigrationTree(root *MigrationNode, fn TransverseFunction)

Types

type MigrationFailedFile

type MigrationFailedFile struct {
	FilePath string
	FileName string
	Error    error
}

type MigrationFile

type MigrationFile struct {
	FilePath string
	FileName string
	Version  *Version
	Content  string
}

type MigrationNode

type MigrationNode struct {
	File              *MigrationFile
	UndoMigrationNode *MigrationNode
	NextMigrationNode *MigrationNode
	PrevMigrationNode *MigrationNode
}

func BuildMigrationTree

func BuildMigrationTree(dir string) (*MigrationNode, *[]*MigrationFailedFile, error)

func BuildMigrationTreeFromPath

func BuildMigrationTreeFromPath(dir string) (*MigrationNode, *[]*MigrationFailedFile, error)

func FindMigrationNode

func FindMigrationNode(root *MigrationNode, version *VersionShort) *MigrationNode

type TransverseFunction

type TransverseFunction func(node *MigrationNode) error

type Version

type Version struct {
	Prefix      string // Prefix: can be `U` or `V`
	Version     string // Version: semantic version with _
	Description string // Description: description of the migration
	Suffix      string // Suffix: file extension
}

func FindPreviousVersion

func FindPreviousVersion(root *MigrationNode, targetVersion *VersionShort) *Version

func ParseVersion

func ParseVersion(version string) (*Version, error)

type VersionShort

type VersionShort struct {
	Prefix  string
	Version string
}

func GetCurrentDatabaseVersion

func GetCurrentDatabaseVersion(url string, verbose bool, schema string) (*VersionShort, string, error)

func GetVersionShortFromFull

func GetVersionShortFromFull(version *Version) *VersionShort

func ParseVersionShort

func ParseVersionShort(versionShort string) (*VersionShort, error)

Jump to

Keyboard shortcuts

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