moisei-dev/go-dbmigrate

GitHub: moisei-dev/go-dbmigrate

一个基于 Go 的数据库迁移工具,提供跨平台 CLI 与库接口,解决数据库版本管理与安全迁移问题。

Stars: 0 | Forks: 0

# migrate [![Build Status](https://travis-ci.org/mattes/migrate.svg?branch=master)](https://travis-ci.org/mattes/migrate) [![GoDoc](https://godoc.org/github.com/mattes/migrate?status.svg)](https://godoc.org/github.com/mattes/migrate) 一个用 Go 编写的迁移助手。在现有的 Golang 代码中使用它, 或者通过 CLI 运行命令。 ``` GoCode import github.com/mattes/migrate/migrate CLI go get -u github.com/mattes/migrate ``` __Features__ * 轻松实现 [Driver 接口](http://godoc.org/github.com/mattes/migrate/driver#Driver)。 * 在 ``^C`` 时优雅地退出正在进行的迁移。 * 无需神奇的搜索路径例程,也无需硬编码的配置文件。 * CLI 基于 ``migrate package`` 构建。 ## 可用的驱动 * [PostgreSQL](https://github.com/mattes/migrate/tree/master/driver/postgres) * [Cassandra](https://github.com/mattes/migrate/tree/master/driver/cassandra) * [SQLite](https://github.com/mattes/migrate/tree/master/driver/sqlite3) * [MySQL](https://github.com/mattes/migrate/tree/master/driver/mysql) ([experimental](https://github.com/mattes/migrate/issues/1#issuecomment-58728186)) * Bash(计划中) 需要其他驱动?只需实现 [Driver 接口](http://godoc.org/github.com/mattes/migrate/driver#Driver) 并提交 PR。 ## 终端使用方式 ``` # install go get github.com/mattes/migrate # create new migration file in path migrate -url driver://url -path ./migrations create migration_file_xyz # apply all available migrations migrate -url driver://url -path ./migrations up # roll back all migrations migrate -url driver://url -path ./migrations down # roll back the most recently applied migration, then run it again. migrate -url driver://url -path ./migrations redo # run down and then up command migrate -url driver://url -path ./migrations reset # show the current migration version migrate -url driver://url -path ./migrations version # apply the next n migrations migrate -url driver://url -path ./migrations migrate +1 migrate -url driver://url -path ./migrations migrate +2 migrate -url driver://url -path ./migrations migrate +n # roll back the previous n migrations migrate -url driver://url -path ./migrations migrate -1 migrate -url driver://url -path ./migrations migrate -2 migrate -url driver://url -path ./migrations migrate -n # go to specific migration migrate -url driver://url -path ./migrations goto 1 migrate -url driver://url -path ./migrations goto 10 migrate -url driver://url -path ./migrations goto v ``` ## Go 中使用 请查看 GoDoc: http://godoc.org/github.com/mattes/migrate/migrate ``` import "github.com/mattes/migrate/migrate" // Import any required drivers so that they are registered and available import _ "github.com/mattes/migrate/driver/mysql" // use synchronous versions of migration functions ... allErrors, ok := migrate.UpSync("driver://url", "./path") if !ok { fmt.Println("Oh no ...") // do sth with allErrors slice } // use the asynchronous version of migration functions ... pipe := migrate.NewPipe() go migrate.Up(pipe, "driver://url", "./path") // pipe is basically just a channel // write your own channel listener. see writePipe() in main.go as an example. ``` ## 迁移文件 迁移文件的格式如下: ``` 001_initial_plan_to_do_sth.up.sql # up migration instructions 001_initial_plan_to_do_sth.down.sql # down migration instructions 002_xxx.up.sql 002_xxx.down.sql ... ``` 为什么要两个文件?这样你仍然可以执行类似的操作 ``psql -f ./db/migrations/001_initial_plan_to_do_sth.up.sql``,并且 不需要任何自定义标记语言来划分“迁移上”和“迁移下”。请注意, 文件扩展名取决于驱动。 ## 替代方案 * https://bitbucket.org/liamstask/goose * https://github.com/tanel/dbmigrate * https://github.com/BurntSushi/migration * https://github.com/DavidHuie/gomigrate * https://github.com/rubenv/sql-migrate
标签:Cassandra, CVE-2026-32286, DNS解析, EVTX分析, Go, go-dbmigrate, jfrog, pgx, pgx/v5, PostgreSQL, Ruby工具, SQLite, SQL迁移, 事务迁移, 安全修复, 安全可观测性, 开源项目, 数据库工具, 数据库版本管理, 数据库迁移, 日志审计, 测试用例, 版本控制, 迁移工具, 迁移管理, 驱动接口