goflyway

package module
v0.0.0-...-f0bb5e9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 18 Imported by: 0

README

goflyway

When adapting Flyway to new or legacy databases, it can be quite troublesome. It throws errors like "ERROR: Unsupported Database: xxx", when in reality they're just SQL scripts that could be executed sequentially. It seems excessive to modify Flyway itself just to make it work.

For running Flyway scripts in Golang, my approach is simple: convert the Flyway scripts into Goose scripts, then execute them using Goose.

Thanks to DeepSeek, I used it to generate all the code and tests, and then completed the project with some minor tweaks.

flyway 在适配新数据库或老数据库时很麻烦,它会报 ERROR: Unsupported Database: xxx, 其实只是一些 sql 脚本而已,你只要按顺序执行就可以了。 结果你为了用 flyway 还要修改它就太夸张了。

在 golang 中运行 flyway 脚本, 我的方法很简单,将 flyway 脚本转成 goose 脚本,然后再用 goose 运行它。

感谢 deepseek, 我用它生成了所有代码和测试, 然后稍作修改就完成了它!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SqlHandleHooks []func(string) (string, error)

Functions

func Convert

func Convert(inputPath, outputDir, baseYear string) (string, error)

func ConvertAndMigrate

func ConvertAndMigrate(cfg *Config) error

func ConvertFlywayToGoose

func ConvertFlywayToGoose(in io.Reader) (string, error)

ConvertFlywayToGoose 将 Flyway SQL 转换为 Goose SQL 格式

func CopyMigrateTable

func CopyMigrateTable(
	driver string,
	db *sql.DB,
	flywayTable string,
	gooseTable string,
	baseYear string,
) error

重命名函数:CopyMigrateTable

func IsTableAlreadyExists

func IsTableAlreadyExists(err error) bool

func IsTableNotExists

func IsTableNotExists(err error) bool

func RunMain

func RunMain()

func Split

func Split(in io.Reader) ([]string, error)

Split 分割 SQL 语句

func SplitByDelimiter

func SplitByDelimiter(r io.Reader, prefix string) ([]string, []bool)

Types

type Config

type Config struct {
	BaseYear     string
	InputPath    string
	OutputDir    string
	DBDriver     string
	DBConnString string
}

type Token

type Token struct {
	Type          TokenType
	Value         string
	DelimiterWord string // 当前使用的分隔符
}

Token 表示解析出的词法单元

type TokenType

type TokenType int

TokenType 表示解析出的 token 类型

const (
	TokenText TokenType = iota
	TokenSemicolon
	TokenBegin
	TokenEnd
	TokenDelimiterCommand
)

type Tokenizer

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

Tokenizer 封装 SQL 解析器

func NewTokenizer

func NewTokenizer(in io.Reader) *Tokenizer

func (*Tokenizer) NextToken

func (t *Tokenizer) NextToken() (Token, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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