Comments (1)
The problem
Here's what happens with wasp db migrate-dev
:
- The user changes the
prisma.schema
file. - The user runs
wasp db migrate-dev
. - Wasp generates the new Prisma client.
- Wasp builds the SDK, which also builds the user code that's copied into its
ext-src
folder. - The SDK build fails because the old user code in
ext-src
doesn't fit the new Prisma client. - Wasp exists before actually migrating the database.
Proposed solutions
@Martinsos identified two possible approaches:
- Tolerating the TypeScript errors and doing the migration anyway.
- Migrating the database before generating the client.
Tolerating TypeScript errors
I decided against this approach because:
- Changing how we treat TypeScript errors during the SDK build would change it for every command, not just
migrate-dev
, which might have unintended consequences. I could have added a flag that tolerates TS errors only formigrate-dev
, but it would have been too hacky IMO. - The SDK build only fails because it compiles user code. We should be compiling the user code before building the SDK (tracked here). Ignoring all SDK build errors just because they accidentally catch errors that should have been caught earlier seems incorrect and...
- ... Most importantly, this issue is semi-blocked by #1718. Any fixes we do now might become incorrect or ineffective once we change the compilation order, meaning we'd have to fix the same thing again pretty soon.
Migrating before generating the client
This is the correct thing to do since it's natural to generate the database client after taking care of the database.
But it's not as easy as it sounds.
By default, Prisma generates the client after each migration. We turned this off in #962 because, at the time, we needed two different clients (source).
Since we no longer need two clients, my first thought was to turn the automatic client generation back on and stop generating the client manually. Unfortunately, we still want to generate the client during wasp compile
, so that wasn't an option (see why: #444).
We could add a flag that tells wasp compile
not to generate the client when dealing with wasp db migrate-dev
, but this is a little hacky.
The proper solution (IMO)
It's best that each command only runs the compilation steps it needs.
Wasp goes through these steps before running each database command (as part of runDbCommand
), but not all commands need all steps:
- Install the dependencies -- All commands need it because it installs the Prisma CLI
- Generate code into
.wasp/out
- All commands need it..wasp/out/server
is their working directory1 - Generate the Prisma client if necessary - Only
seed
needs this step because it's the only one that executes user code on the database. - Build the SDK in
.wasp/out/sdk/wasp
- Onlyseed
needs this step because it's the only one that executes user code on the database. - Connect to the database - All commands need it.
The wasp db migrate-dev
doesn't even need to run the SDK build that's causing the problem. Unfortunately, steps 1-4 are part of the compilation process (wasp compile
) and can't be cherry-picked.
Therefore, to make this solution possible, we'd have to modularize the compile
function, which is a significant change.
from wasp.
Related Issues (20)
- Allow more complex CORS setups HOT 1
- wrong url after deployment HOT 2
- ERR_MODULE_NOT_FOUND on build (reproducible with fresh install) HOT 2
- Refactor database engine definitions HOT 2
- Unit test all of our framework code HOT 1
- Make Ext import extensions consitent HOT 8
- Implement proper import mappings in SDK generator
- Deployment issue, project works on dev, deployed behind apache there is an odd "Hello world" route HOT 1
- `wasp deps` command doesn't output the SDK deps HOT 1
- Expose PgBoss instance as part of public API
- Rename "client unit tests" to something more appropriate HOT 1
- Server URL gets reset on the client in new deployments on Fly HOT 1
- [By end of Sep] Update Wasp AI GPT models
- Make it clear what is the best option for deploying the Wasp app for free
- Implement TS SDK npm package libraries
- Update Tanstack Query to the latest version
- Update React router to the latest version
- Implement a POC execution system for the TS SDK
- Always use the user's `tsconfig.json` when processing their code
- Update Railway deployment docs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasp.