Search code examples
mysqldockergodatabase-migrationgolang-migrate

File not exist when run mysql database migrations on windows


I cloned an existing repository (repository created by a team in my office which deals with subscriptions in a certain app we are working on) which have some database migration files inside the path ..\internal\db\migrations , this is migration files path. First of all i run the command docker compose up .for an existing docker.yaml , then i run the command go build then go run . .

I made a debug and the app reaches the point when it is about to run the migration file then it displays an error:

Failed to initialize App. Error: first D:\subscription-store: file does not exist

although I checked the paths through debugging and they are correct and at the same time the migration files all are exists.

I am using visual studio code as an editor, Go version 1.15 ,docker and MySQL. I am running on enviroment windows 10.


Solution

  • After debugging and searching , it was found that the repository uses some paths to get the migration files from the local drive . the paths was written for Mac in the code base and i cloned the repository on a windows machine so it didn't work .

    The error specifically happened in the call of the function

    migrate.NewWithDatabaseInstance(
            fmt.Sprintf("file://%s", fullPath),
            "mysql",
            driver,
        )
    

    The generated path for the first parameter was

    file//d:\\subscription-store\\....\\db\\migrations
    

    And this is wrong for windows as the driver d: shouldn't be supported in the path . it is resolved as following

    "file:///"+"subscription-store\\....\\db\\migrations"
    

    When the above URL sent to the function rather than the old one , it worked successfully.