From 46eaba42252e5a38d4651ddc135b96f01a4d2f40 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Fri, 3 Nov 2023 16:55:04 +0900 Subject: [PATCH] Enhance `npm run schema` of `payment-backend`. To users of `@samchon/payment-backend` module, I've changed its `npm run schema` command also to re-generate all the DB tables, too. --- packages/fake-iamport-server/package.json | 2 +- packages/fake-toss-payments-server/package.json | 2 +- packages/iamport-server-api/package.json | 2 +- packages/iamport-server-api/swagger.json | 2 +- packages/payment-api/package.json | 6 +++--- packages/payment-api/swagger.json | 2 +- packages/payment-backend/package.json | 10 +++++----- packages/payment-backend/src/PaymentSetupWizard.ts | 6 +++--- packages/payment-backend/src/executable/schema.ts | 4 ++++ packages/payment-backend/test/index.ts | 4 +--- packages/toss-payments-server-api/package.json | 2 +- packages/toss-payments-server-api/swagger.json | 2 +- 12 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/fake-iamport-server/package.json b/packages/fake-iamport-server/package.json index 03a1198..41e15dd 100644 --- a/packages/fake-iamport-server/package.json +++ b/packages/fake-iamport-server/package.json @@ -1,6 +1,6 @@ { "name": "fake-iamport-server", - "version": "5.0.3", + "version": "5.0.4", "description": "Fake iamport server for testing", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/fake-toss-payments-server/package.json b/packages/fake-toss-payments-server/package.json index 9e6a1d2..212bf57 100644 --- a/packages/fake-toss-payments-server/package.json +++ b/packages/fake-toss-payments-server/package.json @@ -1,6 +1,6 @@ { "name": "fake-toss-payments-server", - "version": "5.0.3", + "version": "5.0.4", "description": "Fake toss-payments server for testing", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/iamport-server-api/package.json b/packages/iamport-server-api/package.json index 48393d1..95890a0 100644 --- a/packages/iamport-server-api/package.json +++ b/packages/iamport-server-api/package.json @@ -1,6 +1,6 @@ { "name": "iamport-server-api", - "version": "5.0.3", + "version": "5.0.4", "description": "API for Iamport Server", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/iamport-server-api/swagger.json b/packages/iamport-server-api/swagger.json index 8fcdfa4..879bec7 100644 --- a/packages/iamport-server-api/swagger.json +++ b/packages/iamport-server-api/swagger.json @@ -13,7 +13,7 @@ "info": { "title": "Iamport API", "description": "Built by [fake-iamport-server](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server) with [nestia](https://github.com/samchon/nestia)", - "version": "5.0.3", + "version": "5.0.4", "license": { "name": "MIT" } diff --git a/packages/payment-api/package.json b/packages/payment-api/package.json index c76f796..d36721b 100644 --- a/packages/payment-api/package.json +++ b/packages/payment-api/package.json @@ -1,6 +1,6 @@ { "name": "@samchon/payment-api", - "version": "5.0.3", + "version": "5.0.4", "description": "API for Payment Backend", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -35,8 +35,8 @@ }, "dependencies": { "@nestia/fetcher": "^2.3.4", - "iamport-server-api": "^5.0.3", - "toss-payments-server-api": "^5.0.3", + "iamport-server-api": "^5.0.4", + "toss-payments-server-api": "^5.0.4", "typia": "^5.2.4" } } \ No newline at end of file diff --git a/packages/payment-api/swagger.json b/packages/payment-api/swagger.json index 9bed00b..b27fe99 100644 --- a/packages/payment-api/swagger.json +++ b/packages/payment-api/swagger.json @@ -7,7 +7,7 @@ } ], "info": { - "version": "5.0.3", + "version": "5.0.4", "title": "@samchon/payment-backend", "description": "Payment Backend Server", "license": { diff --git a/packages/payment-backend/package.json b/packages/payment-backend/package.json index c9cc3fc..d860f78 100644 --- a/packages/payment-backend/package.json +++ b/packages/payment-backend/package.json @@ -1,6 +1,6 @@ { "name": "@samchon/payment-backend", - "version": "5.0.3", + "version": "5.0.4", "description": "Payment Backend Server", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -65,14 +65,14 @@ "@typescript-eslint/parser": "^5.26.0", "cli": "^1.0.1", "copyfiles": "^2.4.1", - "iamport-server-api": "^5.0.3", + "iamport-server-api": "^5.0.4", "nestia": "^5.0.1", "pm2": "^4.5.6", "prettier": "^2.6.2", "prisma-markdown": "^1.0.5", "rimraf": "^3.0.2", "sloc": "^0.2.1", - "toss-payments-server-api": "^5.0.3", + "toss-payments-server-api": "^5.0.4", "ts-node": "^10.9.1", "ts-patch": "^3.0.2", "typescript": "^5.2.2", @@ -84,8 +84,8 @@ "bcryptjs": "^2.4.3", "dotenv": "^16.3.1", "dotenv-expand": "^10.0.0", - "fake-iamport-server": "^5.0.3", - "fake-toss-payments-server": "^5.0.3", + "fake-iamport-server": "^5.0.4", + "fake-toss-payments-server": "^5.0.4", "git-last-commit": "^1.0.0", "inquirer": "^8.2.5", "mutex-server": "^0.3.1", diff --git a/packages/payment-backend/src/PaymentSetupWizard.ts b/packages/payment-backend/src/PaymentSetupWizard.ts index 58ac5a6..ace9ad6 100644 --- a/packages/payment-backend/src/PaymentSetupWizard.ts +++ b/packages/payment-backend/src/PaymentSetupWizard.ts @@ -1,14 +1,14 @@ -import { PrismaClient } from "@prisma/client"; import cp from "child_process"; import { PaymentGlobal } from "./PaymentGlobal"; export namespace PaymentSetupWizard { - export async function schema(client: PrismaClient): Promise { + export async function schema(): Promise { if (PaymentGlobal.testing === false) throw new Error( "Erron on PaymentSetupWizard.schema(): unable to reset database in non-test mode.", ); + const execute = (type: string) => (argv: string) => cp.execSync( `npx prisma migrate ${type} --schema=src/schema.prisma ${argv}`, @@ -17,7 +17,7 @@ export namespace PaymentSetupWizard { execute("reset")("--force"); execute("dev")("--name init"); - await client.$executeRawUnsafe( + await PaymentGlobal.prisma.$executeRawUnsafe( `GRANT SELECT ON ALL TABLES IN SCHEMA ${PaymentGlobal.env.PAYMENT_POSTGRES_SCHEMA} TO ${PaymentGlobal.env.PAYMENT_POSTGRES_USERNAME_READONLY}`, ); } diff --git a/packages/payment-backend/src/executable/schema.ts b/packages/payment-backend/src/executable/schema.ts index 516b108..4d2cf76 100644 --- a/packages/payment-backend/src/executable/schema.ts +++ b/packages/payment-backend/src/executable/schema.ts @@ -1,6 +1,7 @@ import { PrismaClient } from "@prisma/client"; import { PaymentGlobal } from "../PaymentGlobal"; +import { PaymentSetupWizard } from "../PaymentSetupWizard"; async function execute( database: string, @@ -77,6 +78,9 @@ async function main(): Promise { GRANT SELECT ON ALL TABLES IN SCHEMA ${config.schema} TO ${config.readonlyUsername}; `, ); + + PaymentGlobal.testing = true; + await PaymentSetupWizard.schema(); } main().catch((exp) => { console.log(exp); diff --git a/packages/payment-backend/test/index.ts b/packages/payment-backend/test/index.ts index 07500fb..ff39588 100644 --- a/packages/payment-backend/test/index.ts +++ b/packages/payment-backend/test/index.ts @@ -71,9 +71,7 @@ async function main(): Promise { PaymentGlobal.testing = true; if (options.reset) { - await StopWatch.trace("Reset DB")(() => - PaymentSetupWizard.schema(PaymentGlobal.prisma), - ); + await StopWatch.trace("Reset DB")(PaymentSetupWizard.schema); await StopWatch.trace("Seed Data")(PaymentSetupWizard.seed); } diff --git a/packages/toss-payments-server-api/package.json b/packages/toss-payments-server-api/package.json index e7489d1..ba8fd0c 100644 --- a/packages/toss-payments-server-api/package.json +++ b/packages/toss-payments-server-api/package.json @@ -1,6 +1,6 @@ { "name": "toss-payments-server-api", - "version": "5.0.3", + "version": "5.0.4", "description": "API for Toss Payments Server", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/toss-payments-server-api/swagger.json b/packages/toss-payments-server-api/swagger.json index bbd4772..2774d3c 100644 --- a/packages/toss-payments-server-api/swagger.json +++ b/packages/toss-payments-server-api/swagger.json @@ -13,7 +13,7 @@ "info": { "title": "Toss Payments API", "description": "Built by [fake-toss-payments-server](https://github.com/samchon/payments/tree/master/packages/toss-payments-server-api) with [nestia](https://github.com/samchon/nestia)", - "version": "5.0.3", + "version": "5.0.4", "license": { "name": "MIT" }