Hi,
I have a postgresql db that already have tables populated with tons of data.
I could not use the “prisma pull” cli as prisma does not handle cross schema references (yet, #1175), so I crated the model to one of the tables manually in the schema.prisma file:
model Source {
id Int @id @default(autoincrement())
name String?
name_acronym String?
description String?
url String?
contract String?
date_start DateTime?
date_end DateTime?
original_id String?
original_create_date DateTime?
original_update_date DateTime?
active Int? @default(1)
create_by String?
create_date DateTime?
update_by String?
update_date DateTime?
@@map(name: "sources")
}
I created cell, page, and service using yarn rw scaffold source cli.
When I try to get to: localhost:8910\sources i get the following error:
Invalid prisma.source.findMany() invocation:
The table `gvg.Source` does not exist in the current database.
but then I get the error: Cannot read property 'findMany' of undefined
Any thoughts on how to fix it, as I have about 20 more tables with relationship between then in the db with around 80M records, that I would like to access?
I didn’t try that on the prod db. I have a copy that I use for dev. Thank you for the warning though.
@dthyresson, I cannot use introspecting as Prisma introspect does not support cross schema connection, references, and keys.
I had to manually create the model in schema.prisma
If I change the table name in the db to Source, the issue goes away. Unfortunately, I cannot change the table name permanently, as it is used in the production application.
Prisma model naming conventions (singular form, PascalCase) do not always match table names in the database. A common approach for naming tables in databases is to use plural form and snake_case notation - for example: comments. When you introspect a database with a table named comments, the result Prisma model will look like this:
model comments { // Fields}
However, you can still adhere to the naming convention without renaming the underlying comments table in the database by using the @@map attribute:
model Comment { // Fields @@map(name: "comments")}
Note: You can also @map a column name or enum value, and @@map an enum.
@map and @@map allow you to tune the shape of your Prisma Client API by decoupling model and field names from table and column names in the underlying database.
I think you would be able to use Prisma introspection to introspect the db, map the table names and fields, then run the yarn rw g sdl <Model> in the expected pascal case.
@dthyresson , already tried that. Prisma does not support introspecting cross schema reference (#1175).
What I do not understand is why I have to “update” the migrations in sqlite first and then transfer to app to connect to the prostgres option.
Hi @wiezmankimchi perhaps I am misunderstanding, but if you intend to use PostgreSQL you can start off using that – you don’t need to being with SQLite. That’s just a quick-start option for those who do not of PG installed locally or access to a hosted database.
I switch mine immediately when I start a new app and work in PG throughout.