RobertCraigie / prisma-client-py

Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
https://prisma-client-py.readthedocs.io
Apache License 2.0
1.88k stars 81 forks source link

Improved seeding support #718

Open jake-amicus opened 1 year ago

jake-amicus commented 1 year ago

Problem

The NodeJS Prisma package includes a mechanism for seeding databases with a prisma db seed command. This, however, requires configuring the command in the package.json of the project, which would normally be present in a NodeJS project.

{
  "prisma": {
    "seed": "prisma/seed.sh"
  }
}

Interestingly, if I add a file called package.json and simply include that JSON block above then the seed script is executed when I run prisma db seed. I think we just need a more pythonic way of defining what that seed script should be.

Suggested solution

I think just looking for a file called either seed.py or seed.sh would be an acceptable solution, since there is already a precedent for required file names, eg. partial_types.py.

Alternatives

We can manually run scripts to see data, but these scripts are not integrated with the Prisma reset/migrate workflows the way the prisma db seed command is.

Additional context

Node Prisma docs on database seeding

RobertCraigie commented 1 year ago

Yeah I agree this behaviour is not ideal. I already have an open issue regarding support for this in the main Prisma repository, https://github.com/prisma/prisma/issues/10359.

I'd consider adding custom support for this until it's supported natively by Prisma but unfortunately I don't think it's really feasible due to the structure of this feature and the numerous places it's used, especially in commands that perform other related tasks, e.g. prisma migrate dev.