Skip to content

feat(cli): integrate Prisma generator into compile pipeline #19

Description

@dev-queiroz

Summary

Integrate Prisma generator into the official Forge compile pipeline.

Motivation

The Prisma generator exists but cannot be accessed through the official CLI. A generator that is not integrated into the compile workflow is incomplete and untested in production.

Current state:

forge compile
# Output: generated/openapi.json, generated/nest/, etc.
# Missing: Prisma schema

Target state:

forge compile
# Output: generated/openapi.json, generated/nest/, generated/prisma/schema.prisma

Technical Design

CLI Integration Points

The compiler pipeline must:

  1. Instantiate PrismaGenerator
  2. Pass DatabaseSchema IR to generator
  3. Write generated schema.prisma to output folder
  4. Report success/failure

Generated Structure

project/
├── src/
├── generated/
│   ├── openapi.json
│   ├── nest/
│   │   ├── controllers/
│   │   ├── dto/
│   │   └── services/
│   └── prisma/          ← NEW
│       └── schema.prisma
└── forge.config.json

Configuration

forge.config.json:

{
  "contracts": "./contracts/**/*.forge",
  "output": "./generated",
  "generators": {
    "typescript": true,
    "jsonSchema": true,
    "zod": true,
    "nestjs": true,
    "openapi": true,
    "prisma": true
  }
}

Acceptance Criteria

  • PrismaGenerator integrated into compile pipeline
  • forge compile command invokes Prisma generation
  • schema.prisma written to generated/prisma/
  • Output folder created automatically if missing
  • Generated schema is valid Prisma syntax
  • Error handling: meaningful messages if generation fails
  • Integration tests verify CLI invocation
  • All 29+ existing tests still pass
  • Zero regressions in other generators
  • TypeScript strict mode compliance

Example Usage

Command

$ forge compile
✓ Parsing contracts
✓ Building semantic model
✓ Generating TypeScript
✓ Generating JSON Schema
✓ Generating Zod validators
✓ Generating NestJS
✓ Generating OpenAPI spec
✓ Generating Prisma schema
✓ All generators completed in 240ms

Output

generated/
├── index.ts
├── openapi.json
├── nest/
│   ├── controllers/
│   ├── dto/
│   └── services/
└── prisma/
    └── schema.prisma

Files to Create/Modify

New Files:

  • tests/prisma-cli.test.mjs (NEW)

Modified Files:

  • packages/cli/src/commands/compile.ts (MODIFY - invoke Prisma generator)
  • packages/compiler/src/index.ts (MODIFY - if wrapper needed)
  • tests/cli.test.mjs (MODIFY - add Prisma output verification)

Test Strategy

Create integration test suite tests/prisma-cli.test.mjs:

CLI Tests

  • forge compile succeeds with Prisma generator
  • schema.prisma file is created
  • Output location correct: generated/prisma/schema.prisma
  • Schema content matches snapshot tests
  • Multiple contracts generate correctly

Validation Tests

  • Generated schema is Prisma-valid (format check)
  • No regressions in other generators
  • Build output directory hierarchy correct
  • File permissions readable

Error Handling

  • Missing DATABASE_URL in config (warning, not error)
  • Invalid contract type (error with context)
  • Unknown field type (error from generator)

Non-Goals

Out of scope (future phases):

  • prisma migrate integration
  • prisma db push integration
  • prisma studio launching
  • Automatic database provisioning
  • Provider selection UI

Future Extensions

Phase 2 (v0.3):

  • Provider configuration (postgres/mysql/sqlite selection)
  • Migration generation from schema diffs

Phase 3 (v0.4):

  • Prisma client code generation
  • Database seeding scripts
  • Relationship handling

Implementation Notes

  1. Generator pipeline order: execute after Semantic Model but before output summary
  2. Output path: respect config.output setting
  3. File permissions: schema.prisma should be readable/writable
  4. Error reporting: include line numbers from source contracts

Success Criteria

✅ Prisma fully integrated into official compile workflow
✅ No special commands needed (just forge compile)
✅ Schema generation transparent and automatic
✅ Unblocks database layer in generated applications

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions