Skip to content

Commit 3d7ec5e

Browse files
committed
feat: migration banned keywords, users
1 parent b8a3e01 commit 3d7ec5e

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

packages/velog-scripts/env/env.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const env = z.object({
1515
discordPrivatePostsChannelId: z.string(),
1616
redisHost: z.string(),
1717
restorePostsUsername: z.string().optional(),
18+
bannedKeywords: z.array(z.string()).min(1),
1819
})
1920

2021
export const ENV = env.parse({
@@ -24,4 +25,5 @@ export const ENV = env.parse({
2425
discordPrivatePostsChannelId: process.env.DISCORD_PRIVATE_POSTS_CHANNEL_ID,
2526
redisHost: process.env.REDIS_HOST,
2627
restorePostsUsername: process.env.RESTORE_POSTS_USERNAME,
28+
bannedKeywords: process.env.BANNED_KEYWORDS?.split(','),
2729
})

packages/velog-scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"private:posts": "pnpm env:copy -e development && ts-node ./scripts/privatePostsOfSpamAccount.mts",
1111
"check:gql": "pnpm prisma:copy && pnpm env:copy -e development && ts-node ./scripts/checkGql.mts",
1212
"restore:posts": "pnpm env:copy -e development && pnpm prisma:copy && ts-node ./scripts/restorePosts.mts",
13+
"add:bannedKeyword": "pnpm env:copy -e development && pnpm prisma:copy && ts-node ./scripts/addBannedKeywords.mts",
1314
"env:copy": "tsx ./scripts/copyEnv.ts",
1415
"prisma:copy": "tsx ./scripts/copyPrisma.ts",
1516
"build": "tsc",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'reflect-metadata'
2+
import { ENV } from '../env/env.mjs'
3+
import { DbService } from '../lib/db/DbService.mjs'
4+
import { container, injectable, singleton } from 'tsyringe'
5+
import { RedisService } from '../lib/redis/RedisService.mjs'
6+
7+
@singleton()
8+
@injectable()
9+
class Runner {
10+
constructor(private readonly db: DbService) {}
11+
public async run(bannedKeywords: string[]) {
12+
const data = bannedKeywords.map((value) => ({
13+
value,
14+
type: 'banned',
15+
}))
16+
17+
try {
18+
await this.db.dynamicConfigItem.createMany({
19+
data,
20+
})
21+
} catch (error) {
22+
console.log(error)
23+
}
24+
}
25+
}
26+
27+
;(async function () {
28+
const bannedKeywords = ENV.bannedKeywords
29+
if (!bannedKeywords) {
30+
throw new Error('No banned keywords')
31+
}
32+
33+
const runner = container.resolve(Runner)
34+
runner.run(bannedKeywords)
35+
})()

0 commit comments

Comments
 (0)