2

In the last part of my project I cannot seem to get the prisma database to deploy properly. The site successfully builds and I am able to view the site, but the momment I attempt to access the database it says that the following:

Invalid prisma.product.findUnique() invocation: The table main.Product does not exist in the current database.

I do have schema for it to migrate off:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}
...
model Product {
  id               String         @id@unique
  quantity         Int            @default(0)
  physical         Boolean        @default(false)
  onhold           Int            @default(0)
}

... 

During the build process on render.com it specifies the following:

Nov 3 02:40:16 PM import { PrismaClient } from '@prisma/client' Nov 3 02:40:16 PM const prisma = new PrismaClient() Nov 3 02:40:16 PM
Nov 3 02:40:19 PM Prisma schema loaded from server/database/schema.prisma Nov 3 02:40:19 PM Datasource "db": SQLite database "dev.db" at "file:./dev.db" Nov 3 02:40:19 PM
Nov 3 02:40:19 PM No migration found in prisma/migrations Nov 3 02:40:19 PM
Nov 3 02:40:19 PM
Nov 3 02:40:19 PM No pending migrations to apply.

I have set up the build command as such:

npm install; prisma generate --schema=./server/database/schema.prisma; prisma migrate deploy --schema=./server/database/schema.prisma; npm run build;

At the time there was no migration directory in the latest commit

When the project is built would it include what I have configured for the migration? Is the '--schema=...' pointing to the correct directory at the point where it is built?

What I have tried: Overall I have more questions than things I have tried due to a lack of knowledge on my part.

When I look at the nuxt build files for this project, it generates a completely different file structure than when its unbuilt, when tareting the SQL db to dev.db would it possibly be pointing incorrectly?

In addition, SQL lite is not good for production? If so what alternative would be good, as well as, how would one install that db onto the deployment server?

Nov 3 02:40:19 PM  Datasource "db": SQLite database "dev.db" at "file:./dev.db"

Does this line indicate that it has found the db to connect to? Overall, I am confused as to how it cannot find the Products table despite it being provided in my schema.

The overall question is what is causing the table to not be seen by the built nuxt app when querying?

kissu
  • 40,416
  • 14
  • 65
  • 133
  • For the next time, try to setup that deploy from the start, will be easier to debug incrementally rather than at the end. – kissu Nov 03 '22 at 14:37
  • I've decided to start a database service on render.com for postgresSQL and directed the schema to the internal DB URL - hopefully this works – Caleb Havea Nov 04 '22 at 01:39
  • overall a real silly mistake, a migration needed to be run before hand to link the schema to the database, this is fixed – Caleb Havea Nov 04 '22 at 14:36

1 Answers1

1

OP fixed the issue by running a migration ahead of the link to the schema.

kissu
  • 40,416
  • 14
  • 65
  • 133