I have spend several days now trying to figure out why my back-end is not working on the online version of my app. I created a Nuxt project that uses Prisma for a very small and simple database.
I had already build the "Nuxt part" of the app before actively using prisma (althought it was already implemented into the project).
After awhile I created a very basic API for prisma to work with and I got everyhting working locally then I tried to build it on heroku by adding this line: release: npx prisma migrate deploy to my Procfile.
I thought this was going to use the latest migration to recreate my local database but when navigate the online version I noticed everything that's dependent off the database isn't working because its probably not in the database.
I tried to make a migration manually and pushed the branch to see what Heroku would log and this is the result:
2021-12-30T13:46:41.573842+00:00 heroku[release.1710]: State changed from starting to up
2021-12-30T13:46:43.062707+00:00 app[release.1710]: Prisma schema loaded from prisma/schema.prisma
2021-12-30T13:46:43.083393+00:00 app[release.1710]: Datasource "db": SQLite database "dev.db" at "file:./dev.db"
2021-12-30T13:46:43.118865+00:00 app[release.1710]:
2021-12-30T13:46:43.118897+00:00 app[release.1710]: 12 migrations found in prisma/migrations
2021-12-30T13:46:43.118939+00:00 app[release.1710]: WARNING The following migrations have been modified since they were applied:
2021-12-30T13:46:43.118940+00:00 app[release.1710]: 20211216111431_init
2021-12-30T13:46:43.118941+00:00 app[release.1710]:
2021-12-30T13:46:43.120322+00:00 app[release.1710]:
2021-12-30T13:46:43.120440+00:00 app[release.1710]: No pending migrations to apply.
2021-12-30T13:46:43.348438+00:00 heroku[release.1710]: Process exited with status 0
2021-12-30T13:46:43.426838+00:00 heroku[release.1710]: State changed from up to complete
2021-12-30T13:46:45.281380+00:00 app[api]: Release v32 created by user [email protected]
2021-12-30T13:46:46.373458+00:00 heroku[web.1]: Restarting
2021-12-30T13:46:46.454020+00:00 heroku[web.1]: State changed from up to starting
2021-12-30T13:46:47.466600+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-12-30T13:46:47.671788+00:00 heroku[web.1]: Process exited with status 143
2021-12-30T13:46:57.249166+00:00 heroku[web.1]: Starting process with command `npm start`
2021-12-30T13:46:58.317560+00:00 app[web.1]:
2021-12-30T13:46:58.317577+00:00 app[web.1]: > [email protected] start /app
2021-12-30T13:46:58.317577+00:00 app[web.1]: > nuxt start
2021-12-30T13:46:58.317577+00:00 app[web.1]:
2021-12-30T13:46:59.566391+00:00 app[web.1]: ℹ Listening on: http://172.17.136.142:51422/
2021-12-30T13:46:59.601868+00:00 heroku[web.1]: State changed from starting to up
I believe it's because you're trying to deploy sqlite on Heroku, which is not recommended since Heroku will periodically clean the disk and erase your sqlite database (see SQLite on Heroku). Use their database-as-a-service instead, they have a free tier for postgresql. This would require you to also use postgresql locally since Prisma removed the ability to have multiple providers (sqlite locally and postgresql in production). It's best practice to use the same db in dev and production anyways.
Here are some steps to run postgresql locally in Nuxt 3 and deploy it to Heroku.
Locally
Create a postgres database with docker in a
docker-compose.yml-file in your project root dir.Create an environment variable file alongside in your project root dir,
.envFor convenience, add some npm scripts to your
package.jsonUpdate your prisma
schema.prismaand change provider to postgresNow you should be able to start local development with
npm run devand close the database container withnpm run stop.Production
Create a Heroku postgres db:
Resourcesclick onFind more add-ons.Heroku Postgresfree tier. (3. ?) I believe Heroku adds the config vars automatically. Go to settings andShow Config Vars, there should be aDATABASE_URLwith the credentials from the new Heroku Postgres db.Procfile, this tells Heroku which scripts to run on deploy. It should have the instruction forwebandreleaseto tell Heroku how to start the server and how to make migrations.Hope that helps!