Create tables for local development
Hi! I'm trying to use a local instance of a PostgreSQL database (via Docker) so that I can make queries without hitting my production database. I'll need to create the tables themselves inside the database before I can make these queries. Is there a way I can do that from what Prisma generates?
I have the Prisma schema and the associated models (e.g. User, Session, Account), but I would need to translate it to raw SQL statements and add them via a Docker initialization script. I know there are already raw SQL files for the migrations, but those are "step by step" rather than the final / most up to date results. I could do this by hand, but this means that any time I update the schema, I would have to manually edit the initialization script as well (which would be prone to error). Thanks!
3 Replies
Further looking into this, seems like
prisma migrate diff --script
might be something that would work?
prisma migrate diff --from-empty --to-url <URL> --script
seems like it's correct, but if someone could confirm that would be splendid!Hi @chicken dinner
migrate diff
looks like a good approach for this
https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/baseline-your-database-typescript-cockroachdbBaseline with Prisma ORM, TypeScript, and CockroachDB | Prisma Docu...
Baseline your database with Prisma ORM, TypeScript, and CockroachDB
Thanks Raphael! I'll try that out 🙂