Search code examples
swiftmigrationmigratevapor

Vapor migrate command not found


I installed a swift vapor web-server and I have to run some migrations. Reading from the docs(https://docs.vapor.codes/fluent/migration/?h=migrate#migrate) it says that I just have to run vapor run migrate but all I get is an error that says .unknownCommand("migrate", available: ["boot", "serve", "routes"]). It seems the vapor toolbox doesn't have the migrate command. I installed the vapor toolbox following the docs(https://docs.vapor.codes/install/linux/#install-toolbox):

git clone https://github.com/vapor/toolbox.git
cd toolbox
git checkout <desired version>
make install

To be fair i had some problems with the make install comand. It said that swiftc wasn't a valid comand but I just changed swiftc to swift inside the Makefile and it did compile at the end. As a matter of fact the vapor --version command works. I use swift 5.5 and vapor 4. Does anybody now how to fix this or find some workaround like running the migration file by itself without the command?


Solution

  • I don't really use the vapor toolbox anymore. I put the second line in main.swift in the Sources/App/Run folder:

    // earlier lines omitted
    try configure(app)
    try app.autoMigrate().wait() // <-- this one needs to be in this position
    try app.run()
    

    It needs to be after everything has been configured but before you start the app running.