Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rafaelespinoza/godfish
a db migration manager
https://github.com/rafaelespinoza/godfish
cassandra database-migrations mariadb mysql postgres schema-migrations sqlite3 sqlserver
Last synced: about 2 months ago
JSON representation
a db migration manager
- Host: GitHub
- URL: https://github.com/rafaelespinoza/godfish
- Owner: rafaelespinoza
- License: isc
- Created: 2020-01-22T05:31:25.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T00:54:05.000Z (5 months ago)
- Last Synced: 2024-07-31T20:49:41.334Z (5 months ago)
- Topics: cassandra, database-migrations, mariadb, mysql, postgres, schema-migrations, sqlite3, sqlserver
- Language: Go
- Homepage: https://pkg.go.dev/github.com/rafaelespinoza/godfish?tab=doc
- Size: 243 KB
- Stars: 7
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - godfish - Database migration manager, works with native query language. Support for cassandra, mysql, postgres, sqlite3. (Database / Database Schema Migration)
- awesome-go-extra - godfish - 01-22T05:31:25Z|2022-04-30T21:47:32Z| (Generators / Database Schema Migration)
README
# godfish
[![Go Reference](https://pkg.go.dev/badge/github.com/rafaelespinoza/godfish.svg)](https://pkg.go.dev/github.com/rafaelespinoza/godfish)
[![codecov](https://codecov.io/gh/rafaelespinoza/godfish/branch/main/graph/badge.svg?token=EoLelW4qiy)](https://codecov.io/gh/rafaelespinoza/godfish)
[![Go Report Card](https://goreportcard.com/badge/github.com/rafaelespinoza/godfish)](https://goreportcard.com/report/github.com/rafaelespinoza/godfish)[![cassandra](https://github.com/rafaelespinoza/godfish/actions/workflows/build-cassandra.yml/badge.svg)](https://github.com/rafaelespinoza/godfish/actions/workflows/build-cassandra.yml)
[![mysql](https://github.com/rafaelespinoza/godfish/actions/workflows/build-mysql.yml/badge.svg)](https://github.com/rafaelespinoza/godfish/actions/workflows/build-mysql.yml)
[![postgres](https://github.com/rafaelespinoza/godfish/actions/workflows/build-postgres.yml/badge.svg)](https://github.com/rafaelespinoza/godfish/actions/workflows/build-postgres.yml)
[![sqlite3](https://github.com/rafaelespinoza/godfish/actions/workflows/build-sqlite3.yml/badge.svg)](https://github.com/rafaelespinoza/godfish/actions/workflows/build-sqlite3.yml)
[![sqlserver](https://github.com/rafaelespinoza/godfish/actions/workflows/build-sqlserver.yml/badge.svg)](https://github.com/rafaelespinoza/godfish/actions/workflows/sqlserver.yml)`godfish` is a database migration manager, similar to the very good
[`dogfish`](https://github.com/dwb/dogfish), but written in golang.## goals
- use the native query language in the migration files, no other high-level DSLs
- interface with many DBs
- light on dependencies
- not terrible error messages## build
Make a CLI binary for the DB you want to use. This tool comes with some driver
implementations. Build one like so:```
make build-cassandra
make build-mysql
make build-postgres
make build-sqlite3
make build-sqlserver
```From there you could move it to `$GOPATH/bin`, move it to your project or
whatever else you need to do.## usage
```
godfish help
godfish -h
godfish -h
```Configuration options are read from command line flags first. If those are not
set, then it checks the configuration file.#### connecting to the db
Database connection parameters are always read from environment variables. Set:
```
DB_DSN=
```#### configure file paths
Manually set path to db migration files.
```sh
godfish -files db/migrations
```Make your life easier by creating a configuration file by invoking `godfish
init`. This creates a file at `.godfish.json`, where you can configure things.Change the path to the configuration file.
```sh
mv .godfish.json foo.json
godfish -conf foo.json
```#### everything else
```sh
cat .godfish.json
# { "path_to_files": "db/migrations" }godfish create-migration -name alpha
# outputs:
# db/migrations/forward-20200128070010-alpha.sql
# db/migrations/reverse-20200128070010-alpha.sqlgodfish create-migration -name bravo -reversible=false
# outputs:
# db/migrations/forward-20200128070106-bravo.sql#
# ... write the sql in those files ...
## apply migrations
godfish migrate
# apply migrations to up a specific version
godfish migrate -version 20060102150405# show status
godfish info# apply a reverse migration
godfish rollback# rollback and re-apply the last migration
godfish remigrate# show build metadata
godfish version
godfish version -json
```## other minutiae
Here are some notable differences between `dogfish` and `godfish`:
Filenames:
- dogfish: `migrate-${date}-${name}.sql`, or `rollback-${date}-${name}.sql`
- godfish: `forward-${date}-${name}.sql`, or `reverse-${date}-${name}.sql`Note, dogfish uses the words, "migrate" and "rollback" to describe the
migration's direction whereas godfish uses "forward" and "reverse". They are
the same in that they are two complementaries. This change has one trivial
benefit, the pieces of metadata encoded into the filename naturally align:```
cd /path/to/db/migrations && ls -1forward-20191112050547-init_foos.sql
forward-20191127051242-add_bars.sql
forward-20191205031405-update_more_stuff.sql
reverse-20191112050547-init_foos.sql
reverse-20191127051242-add_bars.sql
reverse-20191205031405-update_more_stuff.sql
```## contributing
These are welcome. To get you started, the code has some documentation, a godoc
page, at least one implementation of each interface and tests.Comments line lengths should be limited to 80 characters wide. Try not to make
source code lines too long. More lines is fine with the exception of
declarations of exported identifiers; they should be on one line, otherwise the
generated godoc looks weird. There are also tests, those should pass.The GitHub Actions run a security scanner on all of the source code using
[gosec](https://github.com/securego/gosec). There should be no rule violations
here. The Makefile provides a convenience target if you want to run `gosec` on
your development machine.## tests
Docker and docker-compose are used to create environments and run the tests
against a live database. Each database has a separate configuration. All of this
lives in `ci.Makefile` and the `.ci/` directory.Build environments and run tests
```sh
make -f ci.Makefile ci-cassandra3-up
make -f ci.Makefile ci-cassandra4-upmake -f ci.Makefile ci-sqlserver-up
make -f ci.Makefile ci-mariadb-up
make -f ci.Makefile ci-mysql57-up
make -f ci.Makefile ci-mysql8-upmake -f ci.Makefile ci-postgres14-up
make -f ci.Makefile ci-postgres15-upmake -f ci.Makefile ci-sqlite3-up
```Teardown
```sh
make -f ci.Makefile ci-cassandra3-down
make -f ci.Makefile ci-cassandra4-downmake -f ci.Makefile ci-sqlserver-down
make -f ci.Makefile ci-mariadb-down
make -f ci.Makefile ci-mysql57-down
make -f ci.Makefile ci-mysql8-downmake -f ci.Makefile ci-postgres14-down
make -f ci.Makefile ci-postgres15-downmake -f ci.Makefile ci-sqlite3-down
```