summaryrefslogtreecommitdiff
path: root/db/schema
diff options
context:
space:
mode:
Diffstat (limited to 'db/schema')
-rw-r--r--db/schema/contract.ts421
-rw-r--r--db/schema/vendorData.ts321
2 files changed, 387 insertions, 355 deletions
diff --git a/db/schema/contract.ts b/db/schema/contract.ts
index c14921bb..1d628442 100644
--- a/db/schema/contract.ts
+++ b/db/schema/contract.ts
@@ -169,144 +169,215 @@ export const contractSigners = pgTable("contract_signers", {
export const contractsDetailView = pgView("contracts_detail_view").as((qb) => {
return qb
- .select({
- // Contract primary information
- id: contracts.id,
- contractNo: contracts.contractNo,
- contractName: contracts.contractName,
- status: contracts.status,
- startDate: contracts.startDate,
- endDate: contracts.endDate,
-
- // Project information
- projectId: contracts.projectId,
- projectCode: projects.code,
- projectName: projects.name,
-
- // Vendor information
- vendorId: contracts.vendorId,
- vendorName: vendors.vendorName,
-
- // Payment and delivery details
- paymentTerms: contracts.paymentTerms,
- deliveryTerms: contracts.deliveryTerms,
- deliveryDate: contracts.deliveryDate,
- deliveryLocation: contracts.deliveryLocation,
-
- // Financial information
- currency: contracts.currency,
- totalAmount: contracts.totalAmount,
- discount: contracts.discount,
- tax: contracts.tax,
- shippingFee: contracts.shippingFee,
- netTotal: contracts.netTotal,
-
- // Additional settings
- partialShippingAllowed: contracts.partialShippingAllowed,
- partialPaymentAllowed: contracts.partialPaymentAllowed,
- remarks: contracts.remarks,
- version: contracts.version,
-
- // Timestamps
- createdAt: contracts.createdAt,
- updatedAt: contracts.updatedAt,
-
- // Electronic signature status - ADDED .as('has_signature') here
- hasSignature: sql<boolean>`EXISTS (
- SELECT 1
- FROM ${contractEnvelopes}
- WHERE ${contractEnvelopes.contractId} = ${contracts.id}
- )`.as('has_signature'),
- // --- 전자서명 이력 (Envelope) + 서명자(Signer)를 JSON 으로 중첩한 배열 ---
- envelopes: sql<string>`COALESCE((
- SELECT json_agg(
- json_build_object(
- 'id', ce.id,
- 'envelopeId', ce.envelope_id,
- 'documentId', ce.document_id,
- 'envelopeStatus', ce.envelope_status,
- 'fileName', ce.file_name,
- 'filePath', ce.file_path,
- 'createdAt', ce.created_at,
- 'updatedAt', ce.updated_at,
- 'signers', (
- SELECT json_agg(
- json_build_object(
- 'id', cs.id,
- 'vendorContactId', cs.vendor_contact_id,
- 'signerType', cs.signer_type,
- 'signerEmail', cs.signer_email,
- 'signerName', cs.signer_name,
- 'signerPosition', cs.signer_position,
- 'signerStatus', cs.signer_status,
- 'signedAt', cs.signed_at
+ .select({
+ // Contract primary information
+ id: contracts.id,
+ contractNo: contracts.contractNo,
+ contractName: contracts.contractName,
+ status: contracts.status,
+ startDate: contracts.startDate,
+ endDate: contracts.endDate,
+
+ // Project information
+ projectId: contracts.projectId,
+ projectCode: projects.code,
+ projectName: projects.name,
+
+ // Vendor information
+ vendorId: contracts.vendorId,
+ vendorName: vendors.vendorName,
+
+ // Payment and delivery details
+ paymentTerms: contracts.paymentTerms,
+ deliveryTerms: contracts.deliveryTerms,
+ deliveryDate: contracts.deliveryDate,
+ deliveryLocation: contracts.deliveryLocation,
+
+ // Financial information
+ currency: contracts.currency,
+ totalAmount: contracts.totalAmount,
+ discount: contracts.discount,
+ tax: contracts.tax,
+ shippingFee: contracts.shippingFee,
+ netTotal: contracts.netTotal,
+
+ // Additional settings
+ partialShippingAllowed: contracts.partialShippingAllowed,
+ partialPaymentAllowed: contracts.partialPaymentAllowed,
+ remarks: contracts.remarks,
+ version: contracts.version,
+
+ // Timestamps
+ createdAt: contracts.createdAt,
+ updatedAt: contracts.updatedAt,
+
+ // Electronic signature status
+ hasSignature: sql<boolean>`EXISTS (
+ SELECT 1
+ FROM ${contractEnvelopes}
+ WHERE ${contractEnvelopes.contractId} = ${contracts.id}
+ )`.as("has_signature"),
+ // hasItme: sql<boolean>`EXISTS (
+ // SELECT 1
+ // FROM ${contractItems}
+ // WHERE ${contractItems.contractId} = ${contracts.id}
+ // )`.as("has_signature"),
+
+ // =========================
+ // 1) contract_items -> JSON
+ // =========================
+ // 'items' (or "contractItems")라는 필드를 JSON 배열로 가져오기
+ items: sql<string>`COALESCE((
+ SELECT json_agg(
+ json_build_object(
+ 'id', ci.id,
+ 'itemId', ci.item_id,
+ 'description', ci.description,
+ 'quantity', ci.quantity,
+ 'unitPrice', ci.unit_price,
+ 'taxRate', ci.tax_rate,
+ 'taxAmount', ci.tax_amount,
+ 'totalLineAmount', ci.total_line_amount,
+ 'remark', ci.remark,
+ 'createdAt', ci.created_at,
+ 'updatedAt', ci.updated_at
+ )
+ )
+ FROM ${contractItems} AS ci
+ WHERE ci.contract_id = ${contracts.id}
+ ), '[]')`.as("items"),
+
+ // =========================
+ // 2) contract_envelopes -> JSON
+ // =========================
+ envelopes: sql<string>`COALESCE((
+ SELECT json_agg(
+ json_build_object(
+ 'id', ce.id,
+ 'envelopeId', ce.envelope_id,
+ 'documentId', ce.document_id,
+ 'envelopeStatus', ce.envelope_status,
+ 'fileName', ce.file_name,
+ 'filePath', ce.file_path,
+ 'createdAt', ce.created_at,
+ 'updatedAt', ce.updated_at,
+ 'signers', (
+ SELECT json_agg(
+ json_build_object(
+ 'id', cs.id,
+ 'vendorContactId', cs.vendor_contact_id,
+ 'signerType', cs.signer_type,
+ 'signerEmail', cs.signer_email,
+ 'signerName', cs.signer_name,
+ 'signerPosition', cs.signer_position,
+ 'signerStatus', cs.signer_status,
+ 'signedAt', cs.signed_at
+ )
)
+ FROM ${contractSigners} AS cs
+ WHERE cs.envelope_id = ce.id
)
- FROM ${contractSigners} AS cs
- WHERE cs.envelope_id = ce.id
)
)
- )
- FROM ${contractEnvelopes} AS ce
- WHERE ce.contract_id = ${contracts.id}
- ), '[]')`.as("envelopes")
- })
- .from(contracts)
- .leftJoin(projects, eq(contracts.projectId, projects.id))
- .leftJoin(vendors, eq(contracts.vendorId, vendors.id))
-});
-
-// Type inference for the view
-export type ContractDetail = typeof contractsDetailView.$inferSelect;
-
-
-
-
-// ============ poa (Purchase Order Amendment) ============
+ FROM ${contractEnvelopes} AS ce
+ WHERE ce.contract_id = ${contracts.id}
+ ), '[]')`.as("envelopes"),
+ })
+ .from(contracts)
+ .leftJoin(projects, eq(contracts.projectId, projects.id))
+ .leftJoin(vendors, eq(contracts.vendorId, vendors.id))
+ });
+
+ export interface ContractItemParsed {
+ id: number
+ itemId: number
+ description: string | null
+ quantity: number
+ unitPrice: number | null
+ taxRate: number | null
+ taxAmount: number | null
+ totalLineAmount: number | null
+ remark: string | null
+ createdAt: string
+ updatedAt: string
+ }
+
+ // 기존 Envelope + Signers
+ export interface Envelope {
+ id: number
+ envelopeId: string
+ documentId: string | null
+ envelopeStatus: string | null
+ fileName: string
+ filePath: string
+ createdAt: string
+ updatedAt: string
+ signers?: {
+ id: number
+ vendorContactId: number | null
+ signerType: string
+ signerEmail: string
+ signerName: string
+ signerPosition: string | null
+ signerStatus: string
+ signedAt: string | null
+ }[]
+ }
+
+ // Drizzle가 만들어준 raw type
+ export type ContractDetail = typeof contractsDetailView.$inferSelect;
+
+ // 우리가 UI에서 쓰고 싶은 파싱된 타입
+ export type ContractDetailParsed = Omit<ContractDetail, "envelopes" | "items"> & {
+ envelopes: Envelope[]
+ items: ContractItemParsed[]
+ }
+
+ // ============ poa (Purchase Order Amendment) ============
export const poa = pgTable("poa", {
- // 주 키
- id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
-
- // Form code는 원본과 동일하게 유지
- contractNo: varchar("contract_no", { length: 100 }).notNull(),
-
- // 원본 PO 참조
- originalContractNo: varchar("original_contract_no", { length: 100 })
- .notNull()
- .references(() => contracts.contractNo, { onDelete: "cascade" }),
-
- // 원본 계약 정보
- projectId: integer("project_id")
- .notNull()
- .references(() => projects.id, { onDelete: "cascade" }),
- vendorId: integer("vendor_id")
- .notNull()
- .references(() => vendors.id, { onDelete: "cascade" }),
- originalContractName: varchar("original_contract_name", { length: 255 }).notNull(),
- originalStatus: varchar("original_status", { length: 50 }).notNull(),
-
- // 변경된 납품 조건
- deliveryTerms: text("delivery_terms"), // 변경된 납품 조건
- deliveryDate: date("delivery_date"), // 변경된 납품 기한
- deliveryLocation: varchar("delivery_location", { length: 255 }), // 변경된 납품 장소
-
- // 변경된 가격/금액 관련
- currency: varchar("currency", { length: 10 }), // 변경된 통화
- totalAmount: numeric("total_amount", { precision: 12, scale: 2 }), // 변경된 총 금액
- discount: numeric("discount", { precision: 12, scale: 2 }), // 변경된 할인
- tax: numeric("tax", { precision: 12, scale: 2 }), // 변경된 세금
- shippingFee: numeric("shipping_fee", { precision: 12, scale: 2 }), // 변경된 배송비
- netTotal: numeric("net_total", { precision: 12, scale: 2 }), // 변경된 순 총액
-
- // 변경 사유
- changeReason: text("change_reason"),
-
- // 승인 상태
- approvalStatus: varchar("approval_status", { length: 50 }).default("PENDING"),
-
- // 생성/수정 시각
- createdAt: timestamp("created_at").defaultNow().notNull(),
- updatedAt: timestamp("updated_at").defaultNow().notNull(),
+ // 주 키
+ id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
+
+ // Form code는 원본과 동일하게 유지
+ contractNo: varchar("contract_no", { length: 100 }).notNull(),
+
+ // 원본 PO 참조
+ originalContractNo: varchar("original_contract_no", { length: 100 })
+ .notNull()
+ .references(() => contracts.contractNo, { onDelete: "cascade" }),
+
+ // 원본 계약 정보
+ projectId: integer("project_id")
+ .notNull()
+ .references(() => projects.id, { onDelete: "cascade" }),
+ vendorId: integer("vendor_id")
+ .notNull()
+ .references(() => vendors.id, { onDelete: "cascade" }),
+ originalContractName: varchar("original_contract_name", { length: 255 }).notNull(),
+ originalStatus: varchar("original_status", { length: 50 }).notNull(),
+
+ // 변경된 납품 조건
+ deliveryTerms: text("delivery_terms"), // 변경된 납품 조건
+ deliveryDate: date("delivery_date"), // 변경된 납품 기한
+ deliveryLocation: varchar("delivery_location", { length: 255 }), // 변경된 납품 장소
+
+ // 변경된 가격/금액 관련
+ currency: varchar("currency", { length: 10 }), // 변경된 통화
+ totalAmount: numeric("total_amount", { precision: 12, scale: 2 }), // 변경된 총 금액
+ discount: numeric("discount", { precision: 12, scale: 2 }), // 변경된 할인
+ tax: numeric("tax", { precision: 12, scale: 2 }), // 변경된 세금
+ shippingFee: numeric("shipping_fee", { precision: 12, scale: 2 }), // 변경된 배송비
+ netTotal: numeric("net_total", { precision: 12, scale: 2 }), // 변경된 순 총액
+
+ // 변경 사유
+ changeReason: text("change_reason"),
+
+ // 승인 상태
+ approvalStatus: varchar("approval_status", { length: 50 }).default("PENDING"),
+
+ // 생성/수정 시각
+ createdAt: timestamp("created_at").defaultNow().notNull(),
+ updatedAt: timestamp("updated_at").defaultNow().notNull(),
})
// 타입 추론
@@ -314,48 +385,48 @@ export type POA = typeof poa.$inferSelect
// ============ poa_detail_view ============
export const poaDetailView = pgView("poa_detail_view").as((qb) => {
- return qb
- .select({
- // POA primary information
- id: poa.id,
- contractNo: poa.contractNo,
- projectId: contracts.projectId,
- vendorId: contracts.vendorId,
- changeReason: poa.changeReason,
- approvalStatus: poa.approvalStatus,
-
- // Original PO information
- originalContractName: sql<string>`${contracts.contractName}`.as('original_contract_name'),
- originalStatus: sql<string>`${contracts.status}`.as('original_status'),
- originalStartDate: sql<Date>`${contracts.startDate}`.as('original_start_date'),
- originalEndDate: sql<Date>`${contracts.endDate}`.as('original_end_date'),
-
- // Changed delivery details
- deliveryTerms: poa.deliveryTerms,
- deliveryDate: poa.deliveryDate,
- deliveryLocation: poa.deliveryLocation,
-
- // Changed financial information
- currency: poa.currency,
- totalAmount: poa.totalAmount,
- discount: poa.discount,
- tax: poa.tax,
- shippingFee: poa.shippingFee,
- netTotal: poa.netTotal,
-
- // Timestamps
- createdAt: poa.createdAt,
- updatedAt: poa.updatedAt,
-
- // Electronic signature status
- hasSignature: sql<boolean>`EXISTS (
- SELECT 1
- FROM ${contractEnvelopes}
- WHERE ${contractEnvelopes.contractId} = ${poa.id}
- )`.as('has_signature'),
- })
- .from(poa)
- .leftJoin(contracts, eq(poa.contractNo, contracts.contractNo))
+ return qb
+ .select({
+ // POA primary information
+ id: poa.id,
+ contractNo: poa.contractNo,
+ projectId: contracts.projectId,
+ vendorId: contracts.vendorId,
+ changeReason: poa.changeReason,
+ approvalStatus: poa.approvalStatus,
+
+ // Original PO information
+ originalContractName: sql<string>`${contracts.contractName}`.as('original_contract_name'),
+ originalStatus: sql<string>`${contracts.status}`.as('original_status'),
+ originalStartDate: sql<Date>`${contracts.startDate}`.as('original_start_date'),
+ originalEndDate: sql<Date>`${contracts.endDate}`.as('original_end_date'),
+
+ // Changed delivery details
+ deliveryTerms: poa.deliveryTerms,
+ deliveryDate: poa.deliveryDate,
+ deliveryLocation: poa.deliveryLocation,
+
+ // Changed financial information
+ currency: poa.currency,
+ totalAmount: poa.totalAmount,
+ discount: poa.discount,
+ tax: poa.tax,
+ shippingFee: poa.shippingFee,
+ netTotal: poa.netTotal,
+
+ // Timestamps
+ createdAt: poa.createdAt,
+ updatedAt: poa.updatedAt,
+
+ // Electronic signature status
+ hasSignature: sql<boolean>`EXISTS (
+ SELECT 1
+ FROM ${contractEnvelopes}
+ WHERE ${contractEnvelopes.contractId} = ${poa.id}
+ )`.as('has_signature'),
+ })
+ .from(poa)
+ .leftJoin(contracts, eq(poa.contractNo, contracts.contractNo))
});
// Type inference for the view
diff --git a/db/schema/vendorData.ts b/db/schema/vendorData.ts
index 01a10b7e..92a92c8e 100644
--- a/db/schema/vendorData.ts
+++ b/db/schema/vendorData.ts
@@ -3,41 +3,32 @@ import {
text,
varchar,
timestamp,
- integer,
- numeric,
- date,
- unique,
- serial,
- jsonb,
- uniqueIndex,
- } from "drizzle-orm/pg-core";
- import { contractItems } from "./contract";
-
- export const forms = pgTable(
- "forms",
- {
- id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
- contractItemId: integer("contract_item_id")
+ integer, numeric, date, unique, serial, jsonb, uniqueIndex
+} from "drizzle-orm/pg-core"
+import { contractItems } from "./contract"
+
+export const forms = pgTable("forms", {
+ id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
+ contractItemId: integer("contract_item_id")
.notNull()
.references(() => contractItems.id, { onDelete: "cascade" }),
- formCode: varchar("form_code", { length: 100 }).notNull(),
- formName: varchar("form_name", { length: 255 }).notNull(),
- // tagType: varchar("tag_type", { length: 50 }).notNull(),
- // class: varchar("class", { length: 100 }).notNull(),
- createdAt: timestamp("created_at").defaultNow().notNull(),
- updatedAt: timestamp("updated_at").defaultNow().notNull(),
- },
- (table) => {
- return {
+ formCode: varchar("form_code", { length: 100 }).notNull(),
+ formName: varchar("form_name", { length: 255 }).notNull(),
+ // tagType: varchar("tag_type", { length: 50 }).notNull(),
+ // class: varchar("class", { length: 100 }).notNull(),
+ createdAt: timestamp("created_at").defaultNow().notNull(),
+ updatedAt: timestamp("updated_at").defaultNow().notNull(),
+}, (table) => {
+ return {
// contractItemId와 formCode의 조합을 유니크하게 설정
- contractItemFormCodeUnique: uniqueIndex(
- "contract_item_form_code_unique"
- ).on(table.contractItemId, table.formCode),
- };
+ contractItemFormCodeUnique: uniqueIndex("contract_item_form_code_unique").on(
+ table.contractItemId,
+ table.formCode
+ ),
}
- );
-
- export const rfqAttachments = pgTable("form_templates", {
+})
+
+export const rfqAttachments = pgTable("form_templates", {
id: serial("id").primaryKey(),
formId: integer("form_id").references(() => forms.id),
fileName: varchar("file_name", { length: 255 }).notNull(),
@@ -45,204 +36,175 @@ import {
createdAt: timestamp("created_at").defaultNow().notNull(),
udpatedAt: timestamp("updated_at").defaultNow().notNull(),
- });
- export const formMetas = pgTable("form_metas", {
+});
+
+
+export const formMetas = pgTable("form_metas", {
id: serial("id").primaryKey(),
formCode: varchar("form_code", { length: 50 }).notNull(),
formName: varchar("form_name", { length: 255 }).notNull(),
columns: jsonb("columns").notNull(),
- createdAt: timestamp("created_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- updatedAt: timestamp("updated_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- });
-
- export const formEntries = pgTable("form_entries", {
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
+})
+
+export const formEntries = pgTable("form_entries", {
id: serial("id").primaryKey(),
formCode: varchar("form_code", { length: 50 }).notNull(),
data: jsonb("data").notNull(),
contractItemId: integer("contract_item_id")
- .notNull()
- .references(() => contractItems.id, { onDelete: "cascade" }),
- createdAt: timestamp("created_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- updatedAt: timestamp("updated_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- });
-
- // ============ tags (각 계약 아이템에 대한 Tag) ============
- // "어느 계약의 어느 아이템에 대한 태그"임을 나타내려면 contract_items를 참조
- export const tags = pgTable("tags", {
+ .notNull()
+ .references(() => contractItems.id, { onDelete: "cascade" }),
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
+})
+
+
+// ============ tags (각 계약 아이템에 대한 Tag) ============
+// "어느 계약의 어느 아이템에 대한 태그"임을 나타내려면 contract_items를 참조
+export const tags = pgTable("tags", {
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
-
+
// 이 Tag가 속한 "계약 내 아이템" (즉 contract_items.id)
contractItemId: integer("contract_item_id")
- .notNull()
- .references(() => contractItems.id, { onDelete: "cascade" }),
-
- formId: integer("form_id").references(() => forms.id, {
- onDelete: "set null",
- }),
-
+ .notNull()
+ .references(() => contractItems.id, { onDelete: "cascade" }),
+
+ formId: integer("form_id")
+ .references(() => forms.id, { onDelete: "set null" }),
+
tagNo: varchar("tag_no", { length: 100 }).notNull(),
tagType: varchar("tag_type", { length: 50 }).notNull(),
class: varchar("class", { length: 100 }).notNull(),
description: text("description"),
-
+
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
- });
-
- export type Tag = typeof tags.$inferSelect;
- export type Form = typeof forms.$inferSelect;
- export type NewTag = typeof tags.$inferInsert;
-
- export const tagTypes = pgTable("tag_types", {
+})
+
+export type Tag = typeof tags.$inferSelect
+export type Form = typeof forms.$inferSelect
+export type NewTag = typeof tags.$inferInsert
+
+export const tagTypes = pgTable("tag_types", {
code: varchar("code", { length: 50 }).primaryKey(),
description: text("description").notNull(),
-
- createdAt: timestamp("created_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- updatedAt: timestamp("updated_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- });
-
- export const tagSubfields = pgTable(
- "tag_subfields",
- {
- id: serial("id").primaryKey(),
-
- // 외래키: tagTypeCode -> tagTypes.code
- tagTypeCode: varchar("tag_type_code", { length: 50 })
+
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
+})
+
+export const tagSubfields = pgTable("tag_subfields", {
+ id: serial("id").primaryKey(),
+
+ // 외래키: tagTypeCode -> tagTypes.code
+ tagTypeCode: varchar("tag_type_code", { length: 50 })
.notNull()
.references(() => tagTypes.code, { onDelete: "cascade" }),
-
- /**
- * 나머지 필드
- */
- // tagTypeDescription: -> 이제 불필요. tagTypes.description로 join
- attributesId: varchar("attributes_id", { length: 50 }).notNull(),
- attributesDescription: text("attributes_description").notNull(),
-
- expression: text("expression"),
- delimiter: varchar("delimiter", { length: 10 }),
-
- sortOrder: integer("sort_order").default(0).notNull(),
-
- createdAt: timestamp("created_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- updatedAt: timestamp("updated_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- },
- (table) => {
- return {
+
+ /**
+ * 나머지 필드
+ */
+ // tagTypeDescription: -> 이제 불필요. tagTypes.description로 join
+ attributesId: varchar("attributes_id", { length: 50 }).notNull(),
+ attributesDescription: text("attributes_description").notNull(),
+
+ expression: text("expression"),
+ delimiter: varchar("delimiter", { length: 10 }),
+
+ sortOrder: integer("sort_order").default(0).notNull(),
+
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
+}, (table) => {
+ return {
uniqTagTypeAttribute: unique("uniq_tag_type_attribute").on(
- table.tagTypeCode,
- table.attributesId
+ table.tagTypeCode,
+ table.attributesId
),
- };
- }
- );
-
- export const tagSubfieldOptions = pgTable("tag_subfield_options", {
+ };
+});
+
+export const tagSubfieldOptions = pgTable("tag_subfield_options", {
id: serial("id").primaryKey(),
-
+
// 어떤 subfield에 속하는 옵션인지
attributesId: varchar("attributes_id", { length: 50 })
- .notNull()
- .references(() => tagSubfields.attributesId, { onDelete: "cascade" }),
-
+ .notNull()
+ .references(() => tagSubfields.attributesId, { onDelete: "cascade" }),
+
/**
* 실제 코드 (예: "PM", "AA", "VB", "VAR", "01", "02" ...)
*/
code: varchar("code", { length: 50 }).notNull(),
-
+
/**
* 사용자에게 보여줄 레이블 (예: "Pump", "Pneumatic Motor", "Ball Valve", ...)
*/
label: text("label").notNull(),
-
+
/**
* 생성/수정 시각 (선택)
*/
- createdAt: timestamp("created_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- updatedAt: timestamp("updated_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- });
-
- export const tagClasses = pgTable("tag_classes", {
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
+})
+
+export const tagClasses = pgTable("tag_classes", {
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
-
+
// 기존 code/label
code: varchar("code", { length: 100 }).notNull(),
label: text("label").notNull(),
-
+
// 새 필드: tagTypeCode -> references tagTypes.code
tagTypeCode: varchar("tag_type_code", { length: 50 })
- .notNull()
- .references(() => tagTypes.code, { onDelete: "cascade" }),
-
+ .notNull()
+ .references(() => tagTypes.code, { onDelete: "cascade" }),
+
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
- });
-
- export const tagTypeClassFormMappings = pgTable(
- "tag_type_class_form_mappings",
- {
- id: serial("id").primaryKey(),
-
- tagTypeLabel: varchar("tag_type_label", { length: 255 }).notNull(),
- classLabel: varchar("class_label", { length: 255 }).notNull(),
-
- formCode: varchar("form_code", { length: 50 }).notNull(),
- formName: varchar("form_name", { length: 255 }).notNull(),
-
- createdAt: timestamp("created_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- updatedAt: timestamp("updated_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- }
- );
-
- export type TagTypeClassFormMappings =
- typeof tagTypeClassFormMappings.$inferSelect;
- export type TagSubfields = typeof tagSubfields.$inferSelect;
- export type TagSubfieldOption = typeof tagSubfieldOptions.$inferSelect;
- export type TagClasses = typeof tagClasses.$inferSelect;
-
- export const viewTagSubfields = pgTable("view_tag_subfields", {
+})
+
+export const tagTypeClassFormMappings = pgTable("tag_type_class_form_mappings", {
+ id: serial("id").primaryKey(),
+
+ tagTypeLabel: varchar("tag_type_label", { length: 255 }).notNull(),
+ classLabel: varchar("class_label", { length: 255 }).notNull(),
+
+ formCode: varchar("form_code", { length: 50 }).notNull(),
+ formName: varchar("form_name", { length: 255 }).notNull(),
+
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
+})
+
+export type TagTypeClassFormMappings = typeof tagTypeClassFormMappings.$inferSelect
+export type TagSubfields = typeof tagSubfields.$inferSelect
+export type TagSubfieldOption = typeof tagSubfieldOptions.$inferSelect
+export type TagClasses = typeof tagClasses.$inferSelect
+
+
+export const viewTagSubfields = pgTable("view_tag_subfields", {
id: integer("id").primaryKey(),
-
+
tagTypeCode: varchar("tag_type_code", { length: 50 }).notNull(),
tagTypeDescription: text("tag_type_description"),
attributesId: varchar("attributes_id", { length: 50 }).notNull(),
attributesDescription: text("attributes_description").notNull(),
-
+
expression: text("expression"),
delimiter: varchar("delimiter", { length: 10 }),
sortOrder: integer("sort_order").default(0).notNull(),
-
+
createdAt: timestamp("created_at", { withTimezone: true }),
updatedAt: timestamp("updated_at", { withTimezone: true }),
- });
-
- export type ViewTagSubfields = typeof viewTagSubfields.$inferSelect;
-
- export const vendorDataReportTemps = pgTable("vendor_data_report_temps", {
+})
+
+export type ViewTagSubfields = typeof viewTagSubfields.$inferSelect
+
+export const vendorDataReportTemps = pgTable("vendor_data_report_temps", {
id: serial("id").primaryKey(),
contractItemId: integer("contract_item_id")
.notNull()
@@ -253,12 +215,11 @@ import {
fileName: varchar("file_name", { length: 255 }).notNull(),
filePath: varchar("file_path", { length: 1024 }).notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
- updatedAt: timestamp("updated_at", { withTimezone: true })
- .defaultNow()
- .notNull(),
+ .defaultNow()
+ .notNull(),
+ updatedAt: timestamp("updated_at", { withTimezone: true })
+ .defaultNow()
+ .notNull(),
});
- export type VendorDataReportTemps = typeof vendorDataReportTemps.$inferSelect;
-
+ export type VendorDataReportTemps = typeof vendorDataReportTemps.$inferSelect; \ No newline at end of file