Local setup
Create the database
If this is your first time setting up, you may need to create a default database for your system user. If you see the error
psql: error: FATAL: database "<username>" does not exist, run:Configure the connection URL
Copy
api/.env.template to api/.env and set DATABASE_URL to include your system username:Set up the database and seed data
From the The seeded data closely matches the jurisdictions used in the core environment with appropriate feature flags set.If you want randomly generated data instead (for more varied local development), run:
api directory, run the setup script. This generates the Prisma client, runs all pending migrations, and seeds the database with staging data:Seeded local credentials
After runningyarn setup, the following admin account is available in the local database:
| Field | Value |
|---|---|
[email protected] | |
| Password | abcdef |
Prisma commands
| Command | Description |
|---|---|
yarn setup | Generates Prisma client, runs all migrations, and seeds staging data |
yarn setup:dev | Same as yarn setup but seeds randomly generated data |
yarn generate:client | Regenerates the Prisma client after schema changes |
yarn prisma migrate dev --name <name> | Creates a new migration file based on changes to schema.prisma |
yarn db:migration:run | Runs all pending migrations against the connected database |
yarn db:seed:staging | Seeds the database with staging data without running migrations |
Modifying the schema
The Prisma schema file is located atapi/prisma/schema.prisma. It defines the structure of all database models, the relationships between them, database enums, and how Prisma connects to the database.
Install the Prisma VS Code extension for syntax highlighting and automatic formatting of
.prisma files.Add the field to the DTO
Update the relevant DTO file under
api/src/dtos/ to include the new field with its validators and transformer decorators.Regenerate the Prisma client
Run the following command to update the TypeScript types and the OpenAPI/Swagger spec:
Add the field to schema.prisma
Manually add the new field to the appropriate model in
api/prisma/schema.prisma, following the naming conventions described below.Naming conventions
All Prisma models and fields follow a consistent naming convention that bridges TypeScript conventions with PostgreSQL conventions:| Element | TypeScript style | Database style | Example |
|---|---|---|---|
| Model names | PascalCase | snake_case via @@map() | HelloWorld → hello_world |
| Enum names | PascalCase | snake_case via @@map() | ListingStatus → listing_status |
| Field names | camelCase | snake_case via @map() | helloWorld → hello_world |
schema.prisma:
Translation migration helper
To generate SQL for inserting or updating rows in thetranslations table, use the yarn translations:sql command:
jurisdiction_id IS NULL for each language. The script generates SQL for en, es, tl, vi, zh, ar, bn, ko, hy, fa and machine-translates missing non-English values using the Google Translate API.
Common options:
| Flag | Description |
|---|---|
--output <name-or-path> | Write SQL to a file instead of stdout. Use a name like 52_my_migration to write to prisma/migrations/52_my_migration/migration.sql |
--languages en,es,tl | Limit output to specific language codes |
--jurisdiction "Bloomington" | Target jurisdiction-specific rows by name instead of generic rows |
--no-machine-translate | Disable Google Translate for non-English strings |
When writing output to a migration file, ensure you increment the migration number prefix beyond the last existing migration in
prisma/migrations/.