Skip to content

Commit

Permalink
Enhance npm run schema of payment-backend.
Browse files Browse the repository at this point in the history
To users of `@samchon/payment-backend` module, I've changed its `npm run schema` command also to re-generate all the DB tables, too.
  • Loading branch information
samchon committed Nov 3, 2023
1 parent 7af7b3d commit 46eaba4
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/fake-iamport-server/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/fake-toss-payments-server/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/iamport-server-api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/iamport-server-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/payment-api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/payment-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
],
"info": {
"version": "5.0.3",
"version": "5.0.4",
"title": "@samchon/payment-backend",
"description": "Payment Backend Server",
"license": {
Expand Down
10 changes: 5 additions & 5 deletions packages/payment-backend/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/payment-backend/src/PaymentSetupWizard.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
export async function schema(): Promise<void> {
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}`,
Expand All @@ -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}`,
);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/payment-backend/src/executable/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PrismaClient } from "@prisma/client";

import { PaymentGlobal } from "../PaymentGlobal";
import { PaymentSetupWizard } from "../PaymentSetupWizard";

async function execute(
database: string,
Expand Down Expand Up @@ -77,6 +78,9 @@ async function main(): Promise<void> {
GRANT SELECT ON ALL TABLES IN SCHEMA ${config.schema} TO ${config.readonlyUsername};
`,
);

PaymentGlobal.testing = true;
await PaymentSetupWizard.schema();
}
main().catch((exp) => {
console.log(exp);
Expand Down
4 changes: 1 addition & 3 deletions packages/payment-backend/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ async function main(): Promise<void> {
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);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/toss-payments-server-api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/toss-payments-server-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 46eaba4

Please sign in to comment.