summaryrefslogtreecommitdiff
path: root/db/seeds/seedDcoments.ts
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
committerjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
commit1a2241c40e10193c5ff7008a7b7b36cc1d855d96 (patch)
tree8a5587f10ca55b162d7e3254cb088b323a34c41b /db/seeds/seedDcoments.ts
initial commit
Diffstat (limited to 'db/seeds/seedDcoments.ts')
-rw-r--r--db/seeds/seedDcoments.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/db/seeds/seedDcoments.ts b/db/seeds/seedDcoments.ts
new file mode 100644
index 00000000..5fb1beea
--- /dev/null
+++ b/db/seeds/seedDcoments.ts
@@ -0,0 +1,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)) \ No newline at end of file