import { pgTable, text, timestamp, integer, varchar, boolean, jsonb } from 'drizzle-orm/pg-core'; import { relations } from 'drizzle-orm'; import { basicContract } from './basicContractDocumnet'; import { users } from './users'; import { vendors } from './vendors'; /** * GTC 기본 계약서 협의 코멘트 테이블 * SHI와 Vendor 간의 계약서 협의 내용을 저장 */ export const agreementComments = pgTable('agreement_comments', { id: integer("id").primaryKey().generatedAlwaysAsIdentity(), // 어떤 기본계약서에 대한 코멘트인지 basicContractId: integer('basic_contract_id') .references(() => basicContract.id) .notNull(), // 작성자 구분 (SHI or Vendor) authorType: text('author_type').notNull(), // 'SHI' | 'Vendor' // 작성자 정보 authorUserId: integer('author_user_id').references(() => users.id), authorVendorId: integer('author_vendor_id').references(() => vendors.id), authorName: varchar('author_name', { length: 255 }), // 선택적 작성자 이름 // 코멘트 내용 comment: text('comment').notNull(), // 첨부파일 정보 (JSON 배열로 저장) attachments: jsonb('attachments').$type>().default([]), // 상태 관리 isDeleted: boolean('is_deleted').notNull().default(false), // 감사 정보 createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), deletedAt: timestamp('deleted_at'), }); // Relations 정의 export const agreementCommentsRelations = relations(agreementComments, ({ one }) => ({ basicContract: one(basicContract, { fields: [agreementComments.basicContractId], references: [basicContract.id], }), authorUser: one(users, { fields: [agreementComments.authorUserId], references: [users.id], }), authorVendor: one(vendors, { fields: [agreementComments.authorVendorId], references: [vendors.id], }), })); export type AgreementComment = typeof agreementComments.$inferSelect; export type NewAgreementComment = typeof agreementComments.$inferInsert;