yarn rw g sdl tableName is really nice to create new tables, but I was wondering what the best way to update the files generated by this command.
for example, if I want to add a new column to a table after I initially ran
yarn rw g sdl is there an update command like
yarn rw update sdl tableName? Or if I have to write those updates manually is there a recommended process? Like
edit schema.prisma →
edit .sdl.js file →
yarn rw db save →
yarn rw db up
In the scenario above, have you made modifications to the sdl file? If not, and would like a new generated file you can use the
yarn rw g sdl tableName --force
--force should do what I need, thank you!
Is this the recommended way to do this? I find myself running this command then discarding the service/.ts because it overwrote some custom logic there. Is there a way to only update the sdl file? or would people recommend just updating by hand?
Regenerating SDL from updated schema has been up for some discussion for awhile with ideas of making be a smart off and only adding in changes or forcing a full overwrite.
I wrote the “Regenerating the SDL” docs here Command Line Interface | RedwoodJS Docs to give some options to make sure you don’t lose tests or stories.
But, typically people do two things:
- Generate the SDL from schema once and then manually update sdl.ts for new/updated fields
- Keep the CRUD sdl intact and in generated for such that it can always ge generated code. Then make custom sdl.ts and custom services for your non-crud behavior.
So your Post sdl generate makes post, posts, and its mutations. All generated.
Then have myPosts service where there is a myPost query and method that filters posts by current user id.
I tend to do the latter.