//go:embed migrations/*.sql

Just recently I learned about embed.FS. It was an accident, that showed up at the right time. Especially when I had a use case to try it out. It's not a game changer per se, but I love finding out better ways to do things. Usually how I would do this is, in my docker build I include the migrations directory and the migrations binary looks for it and runs the migrations before it starts the server. This on it's own is pretty awesome, as it ensures the right migrations always run with right version of the server. If the migrations fail, the last successful image is used.

When I found out about embedded file systems, I can now include the migration files in my final binary. So I no longer need to include the migration files in the final build. It removes one config and now is a standalone program. It's about enjoying the little things in life, this counts as one of those things.

You can find an example here

Happy embedding :)