skip to content
Alvin Lucillo

Data migration, Docker, and Go

/ 1 min read

💻 Tech

If you’re using golang migrate, and you encountered the error below, it means you’re using an incorrect file name format.

error: first .: file does not exist

At first, it looks like the directory you specified in the -path or -source doesn’t exist. It may be the case, so you may want to check that first. But if you’re sure that the directory exists, then it’s probably the file name format. The correct format is {version}_{title}.up.{extension} OR {version}_{title}.down.{extension}. For example, 1_create_users_table.up.sql or 1_create_users_table.down.sql.

In the same topic, if your docker-compose service needs to wait for another service like a database, depends_on is not enough. You need to use wait-for-it. But if you encounter the error below, it means the first line is not a shebang. Probably, you modified the file and removed the first line.

/wait-for-it.sh: Syntax error: "(" unexpected (expecting ";;") 

One last bit since we’re talking about docker-compose. If you want to share your migration file via a volume, add a volume to your service like below.

volumes:
    - ./db/migrations:/migrations

You can then use the path /migrations in your wait-for-it script or set it as a WORKDIR like below.

WORKDIR /migrations