- changed status to resolved
Lack of Go Migration Examples
It is not immediately clear from README how to create migrations written in Go. Were there examples anywhere that could be included in this README?
Comments (5)
-
repo owner -
reporter Sorry, I didn't explain myself clearly.
What I meant to say is there no example on how to use sql.Tx to specify desired schema. For example, how would I specify a column of strings and a primary key using this type of migration?
Are these Go migrations meant to be an abstraction of SQL ones, a la ActiveRecord migration, or is it something else?
-
repo owner Ah, I see. Migrations are not specified at that level by goose - you can use the database/sql APIs directly if you want, or you can use whatever other tools you choose.
There are a variety of libraries out there that provide higher level SQL interfaces in Go, but I think you'll need to find one that works for you.
-
reporter Ah. The confusion here is the assumption (by me, maybe others too) that a migration written in Go instead of SQL has access to a DSL like other migration tools do, e.g. ActiveRecord (ruby) or Knex (js). My bad.
Thanks for your responses. Leaving this doc reference here: http://golang.org/pkg/database/sql/#Tx
-
repo owner Right - there are existing Go libraries that provide at least some of the functionality that appears to be supported by those projects, and as long as they support the database/sql interface, you should be able to plug them into your migrations.
For example, https://github.com/chuckpreslar/codex provides a nice API for generating SQL that you can then execute within a sql.Tx.
It might be nice to compile a list of the tools people like to use for this task, if it doesn't exist already elsewhere...
- Log in to comment
ReadMe: pointer to
goose create
as a reminder of how to create both Go and SQL migrations. fixes issue#24→ <<cset e885648f5ad6>>