Skip to content

Conversation

@seanspeaks
Copy link
Contributor

Resolves #494 - Prisma client is not generated for macOS users

Problem

When macOS users installed @friggframework/core from npm, they received pre-built Prisma clients with Linux binaries (rhel-openssl-3.0.x) but not macOS binaries. Running 'frigg start' would fail because the platform-specific query engine binary was missing.

This occurred because:

  1. The package is built in CI with Linux binaries for Lambda deployment
  2. The 'native' binaryTarget in schema.prisma resolves to the build platform
  3. macOS users get pre-generated clients without their platform binaries

Solution

Following TDD, DDD, and hexagonal architecture best practices in the codebase:

New Domain Services (packages/core/database/utils/):

  1. platform-detector.js: Detects current OS/arch and maps to Prisma binary targets

    • Handles macOS (darwin, darwin-arm64), Linux (musl, glibc), Windows
    • Provides platform descriptions for user-friendly error messages
    • Comprehensive test coverage (30 tests)
  2. binary-validator.js: Validates Prisma client has platform-specific binaries

    • Checks for query engine binaries matching current platform
    • Lists available binaries for debugging
    • Provides actionable suggestions when binaries are missing
    • Comprehensive test coverage (21 tests)

Enhanced Validation (packages/devtools/frigg-cli/):

  1. database-validator.js: Updated checkPrismaClientGenerated()

    • Now checks not just if client exists, but if platform binary exists
    • Detects when regeneration is needed
    • Provides detailed error info including available vs. required binaries
  2. start-command/index.js: Better error messages for platform mismatch

    • Detects when client exists but platform binary is missing
    • Shows which binaries are available vs. required
    • Guides users to run 'frigg db:setup' with clear explanation
  3. db-setup-command/index.js: Smart regeneration logic

    • Automatically detects when platform binaries are missing
    • Regenerates client only when needed
    • Shows informative messages about regeneration reason

Testing

  • All new code follows TDD patterns with Jest
  • 51 tests total (30 + 21) with 100% coverage of new code
  • Tests use mocking patterns consistent with codebase conventions

Impact

  • macOS users can now run 'frigg db:setup' to automatically generate correct binaries
  • 'frigg start' provides clear, actionable error messages
  • Works across all platforms (macOS, Linux, Windows, ARM64)
  • Backward compatible with existing workflows

Alternative Solutions Considered

  1. Postinstall hook: Would slow down npm installs for all users
  2. Ship all binaries: Would increase package size significantly (>60MB per platform)
  3. Current solution: Generate on-demand when needed ✅

This follows the project's patterns for domain-driven design, hexagonal architecture, and comprehensive test coverage.

…or macOS users

Resolves #494 - Prisma client is not generated for macOS users

## Problem
When macOS users installed @friggframework/core from npm, they received pre-built
Prisma clients with Linux binaries (rhel-openssl-3.0.x) but not macOS binaries.
Running 'frigg start' would fail because the platform-specific query engine binary
was missing.

This occurred because:
1. The package is built in CI with Linux binaries for Lambda deployment
2. The 'native' binaryTarget in schema.prisma resolves to the build platform
3. macOS users get pre-generated clients without their platform binaries

## Solution
Following TDD, DDD, and hexagonal architecture best practices in the codebase:

### New Domain Services (packages/core/database/utils/):
1. **platform-detector.js**: Detects current OS/arch and maps to Prisma binary targets
   - Handles macOS (darwin, darwin-arm64), Linux (musl, glibc), Windows
   - Provides platform descriptions for user-friendly error messages
   - Comprehensive test coverage (30 tests)

2. **binary-validator.js**: Validates Prisma client has platform-specific binaries
   - Checks for query engine binaries matching current platform
   - Lists available binaries for debugging
   - Provides actionable suggestions when binaries are missing
   - Comprehensive test coverage (21 tests)

### Enhanced Validation (packages/devtools/frigg-cli/):
1. **database-validator.js**: Updated checkPrismaClientGenerated()
   - Now checks not just if client exists, but if platform binary exists
   - Detects when regeneration is needed
   - Provides detailed error info including available vs. required binaries

2. **start-command/index.js**: Better error messages for platform mismatch
   - Detects when client exists but platform binary is missing
   - Shows which binaries are available vs. required
   - Guides users to run 'frigg db:setup' with clear explanation

3. **db-setup-command/index.js**: Smart regeneration logic
   - Automatically detects when platform binaries are missing
   - Regenerates client only when needed
   - Shows informative messages about regeneration reason

## Testing
- All new code follows TDD patterns with Jest
- 51 tests total (30 + 21) with 100% coverage of new code
- Tests use mocking patterns consistent with codebase conventions

## Impact
- macOS users can now run 'frigg db:setup' to automatically generate correct binaries
- 'frigg start' provides clear, actionable error messages
- Works across all platforms (macOS, Linux, Windows, ARM64)
- Backward compatible with existing workflows

## Alternative Solutions Considered
1. **Postinstall hook**: Would slow down npm installs for all users
2. **Ship all binaries**: Would increase package size significantly (>60MB per platform)
3. **Current solution**: Generate on-demand when needed ✅

This follows the project's patterns for domain-driven design, hexagonal architecture,
and comprehensive test coverage.
@seanspeaks seanspeaks requested a review from d-klotz November 5, 2025 15:06
@seanspeaks seanspeaks added the release Create a release when this pr is merged label Nov 5, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 5, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
15.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@d-klotz d-klotz added the prerelease This change is available in a prerelease. label Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prerelease This change is available in a prerelease. release Create a release when this pr is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants