ChakshuGautam / stencil

Microservices Boilerplate for SamagraX
https://stencil.samagra.io
MIT License
4 stars 5 forks source link

Seeding the DB #15

Open techsavvyash opened 1 year ago

techsavvyash commented 1 year ago

What are the problems/open questions at hand?

Approaches we can follow

1. cQube Style

We can follow a cQube style approach with grammar and data 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 the prisma client generated. 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. This process can be wired up to some command like stencil generate seed-script --file='/path/to/json/file' --type=JSON/CSV

Things to take care of while following this approach would be:

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.

ChakshuGautam commented 12 months 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.

ChakshuGautam commented 12 months ago

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.