Skip to content

Add seed data aligned with latest Prisma schema#34

Open
AlanMaria wants to merge 9 commits into
masterfrom
alan/feature/seed-data-clean
Open

Add seed data aligned with latest Prisma schema#34
AlanMaria wants to merge 9 commits into
masterfrom
alan/feature/seed-data-clean

Conversation

@AlanMaria
Copy link
Copy Markdown
Collaborator

This PR introduces seed data aligned with the current Prisma multi-file schema.

  • Implemented prisma/seed.ts based on prisma/models
  • No schema or migration changes included
  • Seed data validated using Prisma Studio

Ready for review.
git

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a comprehensive Prisma seed script intended to populate a fresh database with baseline reference data and sample operational data aligned to the current multi-file Prisma schema.

Changes:

  • Replaced the minimal seed with an expanded prisma/seed.ts that seeds core reference tables (countries, cultures, localized strings, roles, partners, locations, administrative levels).
  • Added seeding for domain data (tree types, projects, users + role assignments + project membership, scan batches, tree scans + audits, adopters + adoptions, reports).
  • Added password hashing for seeded users and additional console output during seeding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread prisma/seed.ts Outdated
Comment thread prisma/seed.ts Outdated
Comment thread prisma/seed.ts Outdated
Comment thread prisma/seed.ts Outdated
Comment thread prisma/seed.ts Outdated
Comment thread prisma/seed.ts Outdated
Copy link
Copy Markdown
Collaborator

@saitejaswini72 saitejaswini72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the ALLOW_SAMPLE_SEED=true npm run prisma:seed command twice locally. First run went through fine but the second run failed with a P2028 transaction timeout error. It hit 5493ms when the limit is 5000ms.

Image

@nikhil-3210
Copy link
Copy Markdown
Collaborator

I found the issue. The seed was doing too much work inside one large Prisma transaction and on rerun it could exceed Prisma’s default interactive transaction timeout, especially because password compare/hash work was happening during user updates.
I fixed it by:

  • moving password preparation outside the transaction
  • changing user writes to use precomputed passwordHash
  • splitting the seed into smaller transaction phases instead of one long transaction

Please pull the latest changes and test again with:
docker compose up -d postgres
npm run prisma:migrate:dev
ALLOW_SAMPLE_SEED=true npm run prisma:seed

If the schema is already applied and no migration step is needed locally, then just run:
ALLOW_SAMPLE_SEED=true npm run prisma:seed

@nikhil-3210 nikhil-3210 requested a review from saitejaswini72 May 2, 2026 12:11
Copy link
Copy Markdown
Collaborator

@saitejaswini72 saitejaswini72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally after the fix. Seed runs clean twice in a row and all checks pass. The hardcoded role IDs are still there but not a blocker for now. Good to merge.

Image

Copy link
Copy Markdown
Collaborator

@Jaykumar677 Jaykumar677 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go for now, as it is not a blocker. However, we will create a separate ticket for the hardcoded part.

Comment thread prisma/seed.ts Outdated
Comment thread prisma/seed.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants