ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - rafaelespinoza/godfish: a db migration manager
a db migration manager. Contribute to rafaelespinoza/godfish development by creating an account on GitHub.
Visit Site

GitHub - rafaelespinoza/godfish: a db migration manager

GitHub - rafaelespinoza/godfish: a db migration manager

godfish

Go Reference codecov Go Report Card

cassandra mysql postgres sqlite3 sqlserver

godfish is a database migration manager, similar to the very good 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 <command> -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.

godfish -files db/migrations <command>

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.

mv .godfish.json foo.json
godfish -conf foo.json

everything else

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.sql

godfish 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 -1

forward-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. 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

make -f ci.Makefile ci-cassandra3-up
make -f ci.Makefile ci-cassandra4-up

make -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-up

make -f ci.Makefile ci-postgres14-up
make -f ci.Makefile ci-postgres15-up

make -f ci.Makefile ci-sqlite3-up

Teardown

make -f ci.Makefile ci-cassandra3-down
make -f ci.Makefile ci-cassandra4-down

make -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-down

make -f ci.Makefile ci-postgres14-down
make -f ci.Makefile ci-postgres15-down

make -f ci.Makefile ci-sqlite3-down

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory