Checking the migration status with golang-migrate
This post's featured URL for sharing metadata is https://www.jvt.me/img/profile.jpg.
If you're using golang-migrate
to perform your database migrations, you may wonder how to check what the current state of your migrations is.
I recently found myself doing the same, but finding an absence of anything explicitly documenting this, so thought I'd write it as a form of blogumentation.
When running the version
subcommand:
# for migrate v4.15.2
migrate -database "$DATABASE_URL" -path db/migrations version
We then receive the timestamp of the current migration state.
For instance, if we have the two migrations:
1481574547_create_users_table.up.sql
1481840000_alter_users_table.up.sql
The version
subcommand reporting a 1481574547
would indicate that we have not yet applied 1481840000_alter_users_table
.