P
Prisma•7d ago
Smadger

Best way to use typedSQL when deploying to multiple places

I have a project which has just enabled typed SQL. However when I deploy my project multiple containers, multiple databases and multiple sites are deployed/updated. Currently I build everything before running my database migrations to reduce downtime. Is there a way to run prisma generate with typedsql without having to connect it to my database?
2 Replies
Prisma AI Help
Prisma AI Help•7d ago
You selected the bot's instantaneous insights. Let me compile your answer right away! Based on the knowledge sources provided, there is currently no way to run prisma generate with TypedSQL without connecting to a database. This requirement poses challenges for deployment scenarios like yours. Here are the key points and some potential workarounds: 1. TypedSQL requires an active database connection during generation: TypedSQL documentation states that an active database connection is required for this feature. 2. This requirement causes issues in CI/CD environments: As mentioned in this GitHub issue, users are experiencing difficulties in CI/CD pipelines and Docker builds where a database connection may not be readily available. 3. Potential workarounds: a. Generate types locally and include them in version control: You could generate the TypedSQL types on your local development environment and commit them to your repository. This approach is mentioned in this comment, though it's not ideal as it can lead to synchronization issues. b. Copy generated files during build: As suggested in this comment, you could copy the content of node_modules/.prisma/client/sql after generating the types locally to your build environment. 4. Future improvements: The Prisma team is aware of this limitation and is considering solutions to simplify the process, as discussed in this GitHub issue. One potential solution being considered is bundling a lightweight Postgres-compatible database like PGlite with the Prisma CLI for type generation. Given your specific scenario of deploying to multiple containers and databases, the current best approach might be to generate the TypedSQL types in a separate step before your main build and deployment process, possibly using a dedicated database instance for this purpose. However, this is not an ideal solution and may complicate your deployment workflow. It's worth noting that the Prisma team is actively working on improving this aspect of TypedSQL, so future versions may provide a more streamlined solution for your use case.
Nurul
Nurul•6d ago
Hi @Smadger 👋 Currently, it is a requirement for TypedSQL to have a connection to the database. We have a feature request here: #25124 to remove this requirement.
GitHub
Remove requirement for a running database when using TypedSQL · Iss...
Problem When using the new TypedSQL functionality of Prisma ORM, you need to have a running database. This is because the functionality relies on the database to parse the SQL and return type infor...

Did you find this page helpful?