kota's memex

https://github.com/golang-migrate/migrate

A very useful cli tool for creating and running sql migrations. There are a few advantages of using an external tool like this over an automatic migration system in your code, but basically it boils down to keeping complex migration logic separate from your application, having a simple way to check the "version" of a given database, and having an easy way to migrate forward OR BACKWARD.

creating migrations

migrate create -seq -ext=.sql -dir=./migrations create_movies_table

executing migrations

migrate -path=./migrations -database=sqlite://lists.db up

fixing a broken migration

If you're adding migration 3 and make a mistake your database will be considered "dirty" and the migrate tool will fail to run any migrations, printing an error message. You'll need to go ahead and manually "undo" any half-way finished migration and then force set the state to 2 before you can try running your migration again:

migrate -path=./migrations -database=sqlite://lists.db force 2