Skip to content

Commit a27bc43

Browse files
Marfuenclaude
andauthored
chore(db): publish flattened dist/schema.prisma for external consumers (#2677)
The native v7 multi-file schema refactor (c58045f) removed the legacy combine-schemas step that produced a single-file schema in dist/. That worked inside the monorepo (apps read prisma/schema/ directly), but broke external consumers like comp-private's enterprise-api/cx-dashboard/ framework-editor/trust apps, which all run cp ../../node_modules/@trycompai/db/dist/schema.prisma prisma/schema.prisma at build time. The 2.0.1 publish was the first to consume the post- refactor build, and shipped without dist/schema.prisma — breaking every consumer's db:getschema script and blocking SALE-49's comp-private PR. Add scripts/build-dist-schema.js: concatenates prisma/schema/*.prisma (schema.prisma generator+datasource first, models alphabetically after) into dist/schema.prisma during build. Output matches the v2.0.0 shape exactly so consumers don't need to change. Wire into the build script after tsc. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 32b210e commit a27bc43

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

packages/db/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"scripts": {
4646
"backfill:framework-versions": "bun src/scripts/backfill-framework-versions.ts",
47-
"build": "rm -rf dist && node scripts/generate-prisma-client-js.js && tsc",
47+
"build": "rm -rf dist && node scripts/generate-prisma-client-js.js && tsc && node scripts/build-dist-schema.js",
4848
"check-types": "tsc --noEmit",
4949
"db:generate": "node scripts/generate-prisma-client-js.js",
5050
"db:migrate": "prisma migrate dev",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Builds dist/schema.prisma from prisma/schema/*.prisma so consumers that
4+
* pull from the published @trycompai/db package (e.g. comp-private apps,
5+
* which run `cp .../@trycompai/db/dist/schema.prisma prisma/schema.prisma`)
6+
* receive a single, ready-to-use schema.
7+
*
8+
* Native multi-file Prisma v7 schemas live in `prisma/schema/`. Inside the
9+
* monorepo, consumers can read those files directly. Outside the monorepo
10+
* they cannot, so we ship a flattened copy in dist/.
11+
*/
12+
const fs = require('fs');
13+
const path = require('path');
14+
15+
const root = path.join(__dirname, '..');
16+
const schemaDir = path.join(root, 'prisma/schema');
17+
const distDir = path.join(root, 'dist');
18+
const outFile = path.join(distDir, 'schema.prisma');
19+
20+
if (!fs.existsSync(distDir)) fs.mkdirSync(distDir, { recursive: true });
21+
22+
// schema.prisma (generator + datasource) must come first; everything else
23+
// after, in deterministic order.
24+
const all = fs.readdirSync(schemaDir).filter((f) => f.endsWith('.prisma'));
25+
const ordered = [
26+
'schema.prisma',
27+
...all.filter((f) => f !== 'schema.prisma').sort(),
28+
];
29+
30+
const parts = ordered.map((file) => {
31+
const body = fs.readFileSync(path.join(schemaDir, file), 'utf8').trimEnd();
32+
if (file === 'schema.prisma') return body;
33+
return `// ===== ${file} =====\n${body}`;
34+
});
35+
36+
fs.writeFileSync(outFile, parts.join('\n\n') + '\n');
37+
console.log(`[build-dist-schema] wrote ${outFile} (${ordered.length} files)`);

0 commit comments

Comments
 (0)