Open techsavvyash opened 1 year ago
Sharing notes inline.
- Can we be sure that the schema and models are populated before the user starts to seed?
Yes.
- Do we allow for dynamic definition of
schema.prisma
based on the JSON/CSV file?
No
With these assumptions we can have a template file for seed.ts which we can then generate based on some parameters in the JSON/CSV file.
Let's nudge users to generate the JSON based on the prisma.<model>.create
either with or without relation based on the schema that they created. You can verify the type of the object to make sure it is correct but call prisma.<model>.create
to seed.
Let's document this and add this to the cli to ensure folks have a cli command to ingest easily and no one is creating custom things.
What are the problems/open questions at hand?
schema.prisma
based on the JSON/CSV file?Approaches we can follow
1. cQube Style
We can follow a cQube style approach with
grammar
anddata
files and use those to ingest the data into the db. (Seems like an overkill to me)2. Code Generations for
seed.ts
We can assume that the tables have been defined in the
schema.prisma
, migrations applied and theprisma client
generated. With these assumptions we can have atemplate
file forseed.ts
which we can then generate based on some parameters in the JSON/CSV file. This process can be wired up to some command likestencil generate seed-script --file='/path/to/json/file' --type=JSON/CSV
Things to take care of while following this approach would be:
schema.prisma
are same, since we will be doing plain code generation which will cause errors incase table names are wrong. -- A solution to this is to parse the JSON file against theschema.prisma
file.schema.prisma
3. Let the user write the seed script
Prisma has defined support for seeding based on writing seed scripts after defining the
schema.prisma
file, documentation around which can be found here. We can ask the devs to use this directly to seed the db.