Compile goose into executable: what about migrations?
The README (briefly) mentions that you can embed goose into the application.
Is there a way to embed the migrations into the executable as well? I'd like to keep the executable self-contained, so that it upgrades the database automatically upon start.
I'm mainly using SQL migrations, but I'll happily convert them to go migrations if needed.
Comments (5)
-
repo owner -
reporter As far as I know, bindata is indeed the way to do this. The API of goose seems to be based around files, so that won't work with packaged assets.
I'll just package the migrations alongside the app for now, probably not worth the pain to try to embed it.
-
repo owner Cool. I'd also be open to modifying that if it seems interesting.
-
reporter If I were more experienced with Go (just making the switch) I'd offer to help out / would be able to tell what exactly I need to make it work.
For now however, I'll refrain from doing that. I guess it'll be a matter of replacing the filenames / directory handling with a more general interface (plus a default implementation that uses files / directories), but I'd like to be slightly more familiar with the usual Go patterns before I can say something meaningful on the subject.
Nonetheless, goose is an excellent module, enjoying it a lot. Thanks!
-
Until then a hack is to dump the migrations bindata to a tmpdir on disk to be read in by goose. I'm doing that on server startup to check for migrations though you could make it optional.
Or re-implement goose.RunMigrations (goose.CollectMigrations being the important part).
- Log in to comment
I haven't done this, but it sounds like it would be a more general question about how to package resources in a Go binary. Probably there are some libraries that do this - a quick search turned up https://github.com/jteeuwen/go-bindata which might be helpful?