Skip to content

Commit

Permalink
chore(#16): creating a script to migrate the platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
sametcodes committed Mar 6, 2023
1 parent 817a4ea commit ecdd221
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This project uses [Husky](https://typicode.github.io/husky/#/) to run the lintin
The metric methods require name and descriptions on the database records, and they are provided on as JSDoc comments on the methods. You can run the following command to migrate metric methods to the related database records.

```bash
npm run migrate:methods
npm run migrate:platform
```

## Versions and changelogs
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"build": "npm run prisma:generate && next build",
"build:staging": "env-cmd -f .env.staging npm run build && env-cmd -f .env.staging npm run start",
"start": "next start",
"prisma:generate": "prisma generate --schema=./services/prisma/schema.prisma",
"lint": "next lint --max-warnings=0",
"lint:fix": "next lint --fix",
"prettier": "prettier --check .",
"prettier:fix": "prettier --write .",
"prepare": "husky install",
"migrate:methods": "ts-node -r tsconfig-paths/register scripts/migrates/methods.ts"
"prisma:generate": "prisma generate --schema=./services/prisma/schema.prisma",
"migrate:platform": "ts-node -r tsconfig-paths/register scripts/migrates/platform.ts"
},
"dependencies": {
"@next-auth/prisma-adapter": "^1.0.5",
Expand All @@ -32,6 +32,7 @@
"@types/react-dom": "18.0.8",
"@types/simple-oauth2": "^5.0.2",
"chalk": "^4.1.0",
"env-cmd": "^10.1.0",
"eslint": "8.34.0",
"eslint-config-next": "13.2.0",
"husky": "^8.0.0",
Expand Down
13 changes: 10 additions & 3 deletions scripts/migrates/methods.ts → scripts/migrates/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ const migrate = async ({
docs: JSDocMinified[];
code: string;
}): Promise<void> => {
const platform = await prisma.platform.findUnique({ where: { code } });

if (!platform) return console.error(`Platform ${code} not found`);
let platform = await prisma.platform.findUnique({ where: { code } });

if (!platform) {
const name = Array.from(code)
.map((letter, i) => (i === 0 ? letter.toUpperCase() : letter))
.join("");
platform = await prisma.platform.create({
data: { code, name, methods: [] },
});
}

const methods = docs
.map((doc) => ({
Expand Down

0 comments on commit ecdd221

Please sign in to comment.