W
Wasp2w ago
Kbral

Heroku Server dont runned migration

I've created a heroku app, but when i've deployed it, didn't runned the migration
7 Replies
kapa.ai
kapa.ai2w ago
Hi @Kbral. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, it appears that Wasp doesn't automatically run database migrations when deploying to Heroku. Here's what you need to do: 1. First, make sure you have run wasp db migrate-dev locally to create the necessary migration files. 2. When deploying to Heroku, you need to manually run the database migrations as a separate step before releasing your app. This is because it's considered best practice to run migrations separately from the app deployment. 3. To run the migrations on Heroku, you can use the following command after pushing your container but before releasing it:
heroku run --app <app-name> npx prisma migrate deploy

heroku run --app <app-name> npx prisma migrate deploy

This command should be run between the heroku container:push and heroku container:release steps. 4. The full deployment process should look something like this:
heroku container:push --app <app-name> web
heroku run --app <app-name> npx prisma migrate deploy
heroku container:release --app <app-name> web

heroku container:push --app <app-name> web
heroku run --app <app-name> npx prisma migrate deploy
heroku container:release --app <app-name> web

By following these steps, you ensure that your database migrations are applied before the new version of your app is released. For more detailed information on deploying to Heroku with Wasp, you can refer to the Wasp documentation on manual Heroku deployment. Remember, it's important to run migrations separately to avoid potential issues with database state during deployment. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kbral, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Kbral
KbralOP2w ago
@kapa.ai i runned exactly id but id doesn't work...
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- I apologize for the confusion. Let's try to troubleshoot this issue further. Based on the knowledge sources provided, there are a few things we can check: 1. First, make sure you're in the correct project directory when running these commands. 2. It's possible that the migrations are not being applied correctly. Let's try to verify the state of your database migrations. You can connect to your Heroku PostgreSQL database using the Fly CLI (which Heroku uses) with this command:
fly postgres connect -a <your-db-name>

fly postgres connect -a <your-db-name>

3. Once connected, run the following SQL command to check if the migrations table exists and has any entries:
SELECT * FROM _prisma_migrations;

SELECT * FROM _prisma_migrations;

If this table doesn't exist or is empty, it indicates that the migrations haven't been applied successfully. 4. If the migrations table is empty or doesn't exist, there might be an issue with the Prisma client initialization. As mentioned in the GitHub issue about Prisma client initialization, you might need to manually generate the Prisma client. 5. You can try running the following command on Heroku:
heroku run --app <your-app-name> npx prisma generate --schema ./db/schema.prisma

heroku run --app <your-app-name> npx prisma generate --schema ./db/schema.prisma

Then, attempt to run the migrations again:
heroku run --app <your-app-name> npx prisma migrate deploy

heroku run --app <your-app-name> npx prisma migrate deploy

6. If you're still encountering issues, it would be helpful to check the Heroku logs for any specific error messages:
heroku logs --tail --app <your-app-name>

heroku logs --tail --app <your-app-name>

If none of these steps resolve the issue, it would be helpful to have more specific information about the error messages you're seeing. The Wasp team is usually very responsive to such issues, and you might want to consider opening an issue on their GitHub repository with detailed information about your setup and the exact error messages you're encountering. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kbral, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Kbral
KbralOP2w ago
@kapa.ai i've ruen ir and return id:
Running npx prisma generate --schema ./db/schema.prisma on ⬢ wasp-todo... up, run.2773 (Basic)

> [email protected] start-production
> npm run db-migrate-prod && NODE_ENV=production npm run start npx prisma generate ./db/schema.prisma


> [email protected] db-migrate-prod
> prisma migrate deploy --schema=../db/schema.prisma

Prisma schema loaded from ../db/schema.prisma
Datasource "db": PostgreSQL database "dbq2f6j120hb00", schema "public" at "c8m0261h0c7idk.cluster-czrs8kj4isg7.us-east-1.rds.amazonaws.com:5432"

No migration found in prisma/migrations


No pending migrations to apply.

> npm run validate-env && node --enable-source-maps -r dotenv/config bundle/server.js npx prisma generate ./db/schema.prisma
Running npx prisma generate --schema ./db/schema.prisma on ⬢ wasp-todo... up, run.2773 (Basic)

> [email protected] start-production
> npm run db-migrate-prod && NODE_ENV=production npm run start npx prisma generate ./db/schema.prisma


> [email protected] db-migrate-prod
> prisma migrate deploy --schema=../db/schema.prisma

Prisma schema loaded from ../db/schema.prisma
Datasource "db": PostgreSQL database "dbq2f6j120hb00", schema "public" at "c8m0261h0c7idk.cluster-czrs8kj4isg7.us-east-1.rds.amazonaws.com:5432"

No migration found in prisma/migrations


No pending migrations to apply.

> npm run validate-env && node --enable-source-maps -r dotenv/config bundle/server.js npx prisma generate ./db/schema.prisma
Then, do nothing, didn't solved
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the output you've provided, it seems that the migration process is not finding any migrations to apply. This could be because the migrations haven't been created locally or haven't been pushed to your Heroku app. Let's go through a few steps to troubleshoot this: 1. First, make sure you have created migrations locally. Run this command in your local development environment:
wasp db migrate-dev

wasp db migrate-dev

This should create migration files in your migrations folder. 2. After creating the migrations, make sure to commit these new migration files to your git repository and push them to Heroku. 3. Once you've pushed the new migrations, try running the migration command on Heroku again:
heroku run --app <your-app-name> npx prisma migrate deploy

heroku run --app <your-app-name> npx prisma migrate deploy

4. If you're still not seeing any migrations, there might be an issue with the location of your schema.prisma file. The output shows that Prisma is looking for the schema file at ../db/schema.prisma. Make sure this path is correct in your Heroku environment. 5. You can try to manually specify the schema path when running the migration:
heroku run --app <your-app-name> npx prisma migrate deploy --schema=./db/schema.prisma

heroku run --app <your-app-name> npx prisma migrate deploy --schema=./db/schema.prisma

6. If none of the above steps work, you might want to check if your schema.prisma file is being correctly deployed to Heroku. You can inspect the contents of your Heroku app's filesystem:
heroku run --app <your-app-name> ls -R

heroku run --app <your-app-name> ls -R

Look for the db directory and the schema.prisma file within it. If you're still encountering issues after trying these steps, it would be helpful to share more details about your project structure, particularly the location of your schema.prisma file and your migration files. Remember, as mentioned in the Discord support thread, it's crucial to run wasp db migrate-dev locally before deploying to ensure that your migrations are created and ready to be applied on your production database. If the problem persists, you might want to reach out to the Wasp community on their Discord channel for more specific assistance with your deployment setup. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kbral, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
matijash
matijash2w ago
Seems like you switched to Fly from Heroku, from your other thread?
Kbral
KbralOP2w ago
Yeh, it solved my problem

Did you find this page helpful?