Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Migrations in Azure App Service #5084

Open
jamesderrick opened this issue Mar 23, 2022 · 4 comments
Open

Running Migrations in Azure App Service #5084

jamesderrick opened this issue Mar 23, 2022 · 4 comments

Comments

@jamesderrick
Copy link

Environment

Knex version: 1.0.4
Database + version: Azure SQL (SQL Server)
OS: Linux

Bug

I'm trying to use knex within an Azure App Service.
I can connect to the database and run queries without any issue. But I have an issue with migrations.
I originally had a migrate script set up to run when the container starts but that was erroring. So I'm now testing it manually by SSH-ing to the container and trying to run the following command npx knex migrate:latest --env production.
I get the error

Cannot find module '../package'
Require stack:
- /home/site/wwwroot/node_modules/.bin/knex

This is only a problem in Azure, the command works perfectly fine when run on my local version

@jamesderrick
Copy link
Author

I have circumvented this issue by installing knex globally on startup, but that's not the ideal approach. Would still like to understand the previous issue.

@jmccarthy92
Copy link

jmccarthy92 commented Jul 19, 2022

@jamesderrick Encountered this exact issue and used the same workaround, were you able to find another solution?

@jamesderrick
Copy link
Author

I put together a knex demo a couple of weeks ago and was actually able to make it work without an error
Using knex version 2.1
And then my start script in package.json is as follows...
"start": "npx knex migrate:latest& node index.js"

@shinmili
Copy link

I had the same issue, and it was caused by projectkudu/kudu#2946 in my case.

I set up an Azure Pipeline with AzureWebApp@1 task to deploy to Azure App Service. After successfully deployed, node_modules/.bin/knex was turned into a regular file, instead of a symlink. That messed up relative path module importing.

projectkudu/kudu#2946 (comment) can be the best workaround for now:

I just created a startup.sh script in the root of my projects which runs npm rebuild to recreate all the node_modules symlinks followed by my actual project's run command. I then go into the app service configuration in the Azure portal and change the custom startup command to startup.sh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants