Add Prisma seed script with deterministic test data for local development #93

Merged
Copilot merged 4 commits from copilot/add-local-seed-data into main 2025-10-29 23:27:57 -05:00
Copilot commented 2025-10-29 21:45:41 -05:00 (Migrated from github.com)

Local testing required manual API calls to populate users, content, bindings, and verifications. Front-end developers needed on-chain writes for each session.

Changes

Core Implementation

  • prisma/seed.ts: Generates 5 test creators (Hardhat default mnemonic), 5 content entries, 10 platform bindings (YouTube, TikTok, GitHub, Instagram, Discord, LinkedIn), 3 verifications
  • package.json: Added db:seed and db:reset scripts with Prisma seed config
  • tsconfig.json: Include prisma directory for TypeScript compilation

Documentation

  • prisma/SEED_DATA.md: Test account addresses, platform binding IDs, usage examples, security warnings
  • Updated README.md, docs/CONTRIBUTOR_ONBOARDING.md, .env.example with seed instructions

Testing

  • test/seed.test.ts: 15 tests validating script structure, configuration, and seeded data integrity

Infrastructure

  • docker-compose.yml: Exposed PostgreSQL port 5432 for local access

Usage

# Populate test data
npm run db:seed

# Clear and reseed
npm run db:reset

Test accounts use public mnemonic "test test test test test test test test test test test junk" (Hardhat defaults). All addresses are publicly known - never use in production.

Example Test Data

# Query seeded YouTube binding
curl http://localhost:3001/api/resolve?platform=youtube&platformId=dQw4w9WgXcQ

# Creator 1: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
# Creator 2: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
Original prompt

This section details on the original issue you should resolve

<issue_title>Provide local seed data and fixtures for development</issue_title>
<issue_description>## Summary

  • Local testing would be easier with scripted seed data (creator accounts, contents, bindings, verifications) instead of manual API calls.
  • Providing deterministic fixtures enables front-end devs to work without on-chain writes each time.

Acceptance Criteria

  • Add a Prisma seed script (or Hardhat task) that populates representative users, contents, bindings, and verifications.
  • Document how to run the seed as part of local setup and how to reset the database.
  • Ensure seeded data is safe (no real secrets) and optional for production deployments.
    </issue_description>

Comments on the Issue (you are @copilot in this section)


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Local testing required manual API calls to populate users, content, bindings, and verifications. Front-end developers needed on-chain writes for each session. ## Changes **Core Implementation** - `prisma/seed.ts`: Generates 5 test creators (Hardhat default mnemonic), 5 content entries, 10 platform bindings (YouTube, TikTok, GitHub, Instagram, Discord, LinkedIn), 3 verifications - `package.json`: Added `db:seed` and `db:reset` scripts with Prisma seed config - `tsconfig.json`: Include prisma directory for TypeScript compilation **Documentation** - `prisma/SEED_DATA.md`: Test account addresses, platform binding IDs, usage examples, security warnings - Updated `README.md`, `docs/CONTRIBUTOR_ONBOARDING.md`, `.env.example` with seed instructions **Testing** - `test/seed.test.ts`: 15 tests validating script structure, configuration, and seeded data integrity **Infrastructure** - `docker-compose.yml`: Exposed PostgreSQL port 5432 for local access ## Usage ```bash # Populate test data npm run db:seed # Clear and reseed npm run db:reset ``` Test accounts use public mnemonic `"test test test test test test test test test test test junk"` (Hardhat defaults). All addresses are publicly known - never use in production. ## Example Test Data ```bash # Query seeded YouTube binding curl http://localhost:3001/api/resolve?platform=youtube&platformId=dQw4w9WgXcQ # Creator 1: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # Creator 2: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 ``` <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Provide local seed data and fixtures for development</issue_title> > <issue_description>## Summary > - Local testing would be easier with scripted seed data (creator accounts, contents, bindings, verifications) instead of manual API calls. > - Providing deterministic fixtures enables front-end devs to work without on-chain writes each time. > > ## Acceptance Criteria > - [ ] Add a Prisma seed script (or Hardhat task) that populates representative users, contents, bindings, and verifications. > - [ ] Document how to run the seed as part of local setup and how to reset the database. > - [ ] Ensure seeded data is safe (no real secrets) and optional for production deployments. > </issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes subculture-collective/internet-id#7 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/subculture-collective/internet-id/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
onnwee (Migrated from github.com) reviewed 2025-10-29 21:45:41 -05:00
PatrickFanella (Migrated from github.com) reviewed 2025-10-29 21:45:41 -05:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2025-10-29 23:03:05 -05:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull Request Overview

This PR adds database seeding functionality to populate the local development database with deterministic test data. The seed script creates test users, content entries, platform bindings, and verification records to streamline local development and testing workflows.

Key changes:

  • Created a comprehensive seed script (prisma/seed.ts) that generates 5 test users, 5 content entries, 10 platform bindings, and 3 verification records
  • Added test suite (test/seed.test.ts) to verify seed script structure and validate seeded data
  • Updated documentation to guide developers on using the seed functionality

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tsconfig.json Added "prisma" to included directories for TypeScript compilation
test/seed.test.ts New test file verifying seed script structure, configuration, and seeded data
prisma/seed.ts New seed script generating deterministic test data using test mnemonics
prisma/SEED_DATA.md Comprehensive documentation for seed data structure and usage
package.json Added prisma.seed configuration and db:seed/db:reset npm scripts
docs/CONTRIBUTOR_ONBOARDING.md Updated onboarding guide to document seed functionality
docker-compose.yml Changed db service from expose to ports to allow external database access
README.md Added documentation for seeding and resetting database
.env.example Added documentation section for database seed data

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

## Pull Request Overview This PR adds database seeding functionality to populate the local development database with deterministic test data. The seed script creates test users, content entries, platform bindings, and verification records to streamline local development and testing workflows. Key changes: - Created a comprehensive seed script (`prisma/seed.ts`) that generates 5 test users, 5 content entries, 10 platform bindings, and 3 verification records - Added test suite (`test/seed.test.ts`) to verify seed script structure and validate seeded data - Updated documentation to guide developers on using the seed functionality ### Reviewed Changes Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments. <details> <summary>Show a summary per file</summary> | File | Description | | ---- | ----------- | | tsconfig.json | Added "prisma" to included directories for TypeScript compilation | | test/seed.test.ts | New test file verifying seed script structure, configuration, and seeded data | | prisma/seed.ts | New seed script generating deterministic test data using test mnemonics | | prisma/SEED_DATA.md | Comprehensive documentation for seed data structure and usage | | package.json | Added prisma.seed configuration and db:seed/db:reset npm scripts | | docs/CONTRIBUTOR_ONBOARDING.md | Updated onboarding guide to document seed functionality | | docker-compose.yml | Changed db service from expose to ports to allow external database access | | README.md | Added documentation for seeding and resetting database | | .env.example | Added documentation section for database seed data | </details> --- 💡 <a href="/subculture-collective/internet-id/new/main/.github?filename=*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
@@ -93,2 +91,4 @@
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-29 23:03:04 -05:00

Exposing the database port (5432) to the host makes the database accessible from outside the Docker network, which could be a security risk in production environments. Consider documenting this change as development-only or using environment-specific Docker Compose files (e.g., docker-compose.override.yml for development).


Exposing the database port (5432) to the host makes the database accessible from outside the Docker network, which could be a security risk in production environments. Consider documenting this change as development-only or using environment-specific Docker Compose files (e.g., docker-compose.override.yml for development). ```suggestion ```
@@ -0,0 +95,4 @@
it("should have deterministic user addresses", async () => {
// Check for the first test wallet address (from the standard test mnemonic)
const expectedAddress = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-29 23:03:04 -05:00

The expected address uses lowercase letters in the test (line 98), but the seed script stores addresses in lowercase (line 64 of seed.ts uses .toLowerCase()). The hardcoded address here has mixed case, which will cause the test to fail. Change to: const expectedAddress = \"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266\"; (all lowercase after 0x).

The expected address uses lowercase letters in the test (line 98), but the seed script stores addresses in lowercase (line 64 of seed.ts uses `.toLowerCase()`). The hardcoded address here has mixed case, which will cause the test to fail. Change to: `const expectedAddress = \"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266\";` (all lowercase after 0x).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: subculture-collective/internet-id#93