Repository navigation
Expand file tree
/
Copy pathmodule.ts
More file actions
31 lines (30 loc) · 1.42 KB
/
Copy pathmodule.ts
File metadata and controls
31 lines (30 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { appRoot, resolve } from '@prisma/composer';
import { postgres } from '@prisma/composer-prisma-cloud/orm';
import { widgetContract } from './src/contract.ts';
import widgetsService from './src/service.ts';
/**
* The orm-demo app: one Prisma-ORM-typed Postgres and one compute service
* that round-trips through it. A closed root (empty boundary).
*
* The database provision id is "database" (not "db"): the prisma-cloud target
* passes it through as the Prisma resource name, and the Connection API rejects
* names shorter than 3 characters. The resource carries two doors (ADR-0022):
* `contract` (consumed — types + wires the resource, gives the deploy its
* target storageHash) and `config` (the ORM config PATH the deploy
* migration step loads to find migrations/ — never imported by the app build).
* Every deploy migrates the database to its `targetRef`: under `prisma dev`
* (environment `dev`) the contract this commit emits, and otherwise the ref
* named after the environment, `migrations/app/refs/<environment>.json`.
*/
export default appRoot('orm-demo', ({ environment, provision }) => {
const db = provision(
postgres({
name: 'database',
contract: widgetContract,
config: './prisma.config.ts',
targetRef: resolve([environment.name], ([name]) => (name === 'dev' ? '@contract' : name)),
}),
{ id: 'database' },
);
provision(widgetsService, { id: 'widgets', deps: { db } });
});