Skip to content

Commit 0ef2d20

Browse files
adam-majfarhanW3
andauthored
Include src and prisma schema in tsconfig.json (#135)
* Include src/**/*.ts in tsconfig.json * Add prisma:setup script * Remove copy files and fix dockerfile * Update to copy prisma schema * Update to prisma:setup:dev and prisma:setup:prod * Add custom schema to setup script * fixed docker build step. Added a find/replace for the prisma schema path on package.json in prod stage --------- Co-authored-by: farhanW3 <farhan@thirdweb.com>
1 parent 1d6308c commit 0ef2d20

File tree

8 files changed

+45
-132
lines changed

8 files changed

+45
-132
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ RUN apk --no-cache --virtual build-dependencies add g++ make py3-pip
4949
# Copy package.json and yarn.lock files
5050
COPY package*.json yarn*.lock ./
5151

52+
# Replace the schema path in the package.json file
53+
RUN sed -i 's_"schema": "./src/prisma/schema.prisma"_"schema": "./dist/src/prisma/schema.prisma"_g' package.json
54+
5255
# Copy the built dist folder from the base stage to the production stage
5356
COPY --from=base /app/dist ./dist
5457

core/database/sql-schemas/transactions.sql

Lines changed: 0 additions & 59 deletions
This file was deleted.

core/database/sql-schemas/trigger_notification.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.

core/database/sql-schemas/trigger_tx_table.sql

Lines changed: 0 additions & 9 deletions
This file was deleted.

core/database/sql-schemas/wallets.sql

Lines changed: 0 additions & 34 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
"scripts": {
1010
"docker": "docker compose --env-file ./.env up --remove-orphans",
1111
"docker:build": "docker compose build --no-cache",
12-
"dev": "yarn dev:infra && yarn prisma:init && yarn dev:server & sleep 10 && yarn dev:worker",
13-
"dev:server": "yarn prisma:init && nodemon --watch 'server/**/*.ts' --watch 'core/**/*.ts' --watch 'src/**/*.ts' --exec 'npx tsx ./server/index.ts' --files server/index.ts",
14-
"dev:worker": "yarn prisma:init && nodemon --watch 'worker/**/*.ts' --watch 'core/**/*.ts' --watch 'src/**/*.ts' --exec 'npx tsx ./worker/index.ts' --files worker/index.ts",
12+
"dev": "yarn dev:infra && yarn prisma:setup:dev && yarn dev:server & sleep 10 && yarn dev:worker",
13+
"dev:server": "nodemon --watch 'server/**/*.ts' --watch 'core/**/*.ts' --watch 'src/**/*.ts' --exec 'npx tsx ./server/index.ts' --files server/index.ts",
14+
"dev:worker": "nodemon --watch 'worker/**/*.ts' --watch 'core/**/*.ts' --watch 'src/**/*.ts' --exec 'npx tsx ./worker/index.ts' --files worker/index.ts",
1515
"dev:infra": "docker compose -f ./docker-compose-infra.yml up -d",
1616
"build": "yarn && rm -rf dist && tsc -p ./tsconfig.json --outDir dist",
17-
"prisma:reset": "prisma migrate reset --force && prisma generate",
18-
"prisma:init": "prisma migrate deploy && prisma generate",
19-
"start": "yarn prisma:init && yarn start:server & sleep 20 && yarn start:worker",
17+
"prisma:setup:dev": "npx tsx ./src/db/scripts/setup.ts",
18+
"prisma:setup:prod": "npx tsx ./dist/src/db/scripts/setup.js",
19+
"start": "yarn prisma:setup:prod && yarn start:server & sleep 20 && yarn start:worker",
2020
"start:server": "node --experimental-specifier-resolution=node ./dist/server/index.js",
2121
"start:worker": "node --experimental-specifier-resolution=node ./dist/worker/index.js",
2222
"start:docker": "docker compose build && docker compose --env-file ./.env up --remove-orphans",
2323
"docker-build-run": "docker compose build --no-cache && docker compose --env-file ./.env up --remove-orphans",
24-
"copy-files": "copyfiles ./core/database/sql-schemas/*.sql ./dist/",
24+
"copy-files": "copyfiles ./src/prisma/schema.prisma ./dist/ && copyfiles ./src/prisma/migrations/**/*.sql ./dist/",
2525
"lint": "eslint 'server/**/*.ts'",
2626
"lint:fix": "eslint --fix 'server/**/*.ts'",
2727
"test": "make test-evm",

src/db/scripts/setup.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { execSync } from "child_process";
2+
import { prisma } from "../client";
3+
4+
const main = async () => {
5+
const [{ exists: hasWalletsTable }]: [{ exists: boolean }] =
6+
await prisma.$queryRaw`
7+
SELECT EXISTS (
8+
SELECT 1
9+
FROM pg_tables
10+
WHERE schemaname = 'public'
11+
AND tablename = 'wallets'
12+
);
13+
`;
14+
15+
const schema =
16+
process.env.NODE_ENV === "production"
17+
? `./dist/src/prisma/schema.prisma`
18+
: `./src/prisma/schema.prisma`;
19+
20+
if (hasWalletsTable) {
21+
execSync(`yarn prisma migrate reset --force --schema ${schema}`, {
22+
stdio: "inherit",
23+
});
24+
} else {
25+
execSync(`yarn prisma migrate deploy --schema ${schema}`, {
26+
stdio: "inherit",
27+
});
28+
}
29+
30+
execSync(`yarn prisma generate --schema ${schema}`, { stdio: "inherit" });
31+
};
32+
33+
main();

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"worker/**/*.ts",
2525
"worker/**/*.d.ts",
2626
"worker/**/*.js",
27-
"core/env.ts"
27+
"core/env.ts",
28+
"src/**/*.ts"
2829
],
2930
"exclude": ["node_modules"]
3031
}

0 commit comments

Comments
 (0)