Yarn rw g sdl is great but

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.prismaedit .sdl.js fileyarn rw db saveyarn rw db up

1 Like

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 --force flag: yarn rw g sdl tableName --force

3 Likes

Ahh that --force should do what I need, thank you!

2 Likes

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:

  1. Generate the SDL from schema once and then manually update sdl.ts for new/updated fields
  2. 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.

1 Like