blob: 5fb1beeabf239213add1803290e3436a4b43c74c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/**
* seedDocuments.ts
* - documents 테이블에 테스트 데이터 삽입
*/
import db from "@/db/db"
import { faker } from "@faker-js/faker"
import { documents } from "../schema/vendorDocu"
// 몇 개의 도큐먼트를 만들지
const NUM_DOCUMENTS = 200
// 가상으로 계약 ID가 96~125 범위
const CONTRACT_ID_MIN = 96
const CONTRACT_ID_MAX = 125
async function seedDocuments() {
try {
console.log("Seeding documents started...")
// documents 테이블에 NUM_DOCUMENTS 개 생성
const docsData = []
for (let i = 0; i < NUM_DOCUMENTS; i++) {
const randomContractId = faker.number.int({
min: CONTRACT_ID_MIN,
max: CONTRACT_ID_MAX,
})
docsData.push({
contractId: randomContractId,
docNumber: `DOC-${faker.number.int({ min: 1000, max: 9999 })}`,
title: faker.lorem.sentence(3),
status: faker.helpers.arrayElement(["ACTIVE", "REVIEW", "APPROVED"]),
issuedDate: faker.helpers.maybe(() => faker.date.past({ years: 1 }), {
probability: 0.7,
})
})
}
// documents 테이블 INSERT (returning 사용 안 함)
await db.insert(documents).values(docsData)
// // 삽입된 문서 수 확인
// const count = await db.select({ count: db.fn.count() }).from(documents)
// console.log(`Documents in database: ${count[0].count}`)
console.log("Seeding documents completed successfully.")
} catch (err) {
console.error("Seeding documents error:", err)
process.exit(1)
}
}
// 스크립트 직접 실행 시
seedDocuments()
.then(() => process.exit(0))
.catch(() => process.exit(1))
|