Skip to content

Valuation Service - Infrastructure

Infrastructure setup

Databases

Uses Prisma with PostgreSQL.

Schema Location: services/valuation/prisma/schema.prisma

bash
docker compose -f 'docker-compose.yml' up -d --build 'databases'

to stop:

bash
docker compose -f 'docker-compose.yml' down 'databases'

Prisma Commands

bash
nx run valuation:prisma:generate # generate types
nx run valuation:prisma:reset # reset the database depending on the variable DATABASE_URL

Performing a Migration

  1. Modify the schema.prisma file of the service you're working with
  2. Trigger the nx command migrate:dev:create, which will automatically generate the migration file within the /migrations folder. Check the result as this command can be dangerous to merge/roll back
  3. Run the migration with the nx command migrate:dev
  4. Generate the schemas with the nx command prisma:generate.
  5. Obviously test your changes

You can then create your PR.

For deployment to the environments, you'll notice in the Dockerfile that a script entrypoint.sh is triggered. This script will automatically deploy your migration, meaning your migration will automatically be applied across the environments once the service starts.

Running the Service

Install Dependencies

bash
pnpm install

Environment variables

  1. Add a .env.dev at the service root
  2. Get the environment variables from 1password for the corresponding service

Commands

bash
# Development
nx run valuation:dev

# Build
nx run valuation:build

# Test
nx run valuation:test

# Lint
nx run valuation:lint

# Run in Docker
docker compose -f 'docker-compose.yml' up -d --build 'valuation'

# Check dependencies
nx show project valuation

# Show affected projects (based on git changes)
nx affected:graph

Shared Packages

The shared packages (dto, models, utils) are automatically linked and can be imported in both backend and frontend applications. Any changes to these packages will trigger rebuilds in dependent applications.

These packages mostly contain global functions (like logger, utils, ...) shared among services, providing common functionality and ensuring consistency across the monorepo.

Available Packages

  • dto - Data Transfer Objects
  • models - Shared data models
  • utils - Utility functions and helpers

Troubleshooting

pnpm run grouping:build fails

Scenario encountered:

  • valuation tests: nx run valuation:test
  • valuation grouping build: nx run valuation:grouping:build

Error message:

prebuild-install warn install No prebuilt binaries found (target=22.19.0 runtime=node arch=arm64 libc= platform=darwin)

Solution:

The @beparallel/grouping package uses prebuild-install which requires a GitHub token to download prebuilt binaries when they're not available for your platform. Export the GITHUB_TOKEN environment variable before running the build:

bash
export GITHUB_TOKEN=your_github_token_here
nx run valuation:grouping:build

Or for tests:

bash
export GITHUB_TOKEN=your_github_token_here
nx run valuation:test

Note: You can obtain a GitHub Personal Access Token in your .env file with the key GITHUB_TOKEN.