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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// db/schema/table-presets.ts
import { pgTable, text, timestamp, boolean, integer, uuid } from "drizzle-orm/pg-core"
import { json } from "drizzle-orm/pg-core"
import { z } from "zod"
// TableSettings 타입 정의
export interface TableSettings<TData = any> {
// 페이지네이션
page: number
perPage: number
// 정렬
sort: Array<{
id: string
desc: boolean
}>
// 필터
filters: Array<{
id: string
value: any
operator?: string
type?: string
}>
joinOperator: "and" | "or"
basicFilters: Array<{
id: string
value: any
operator?: string
type?: string
}>
basicJoinOperator: "and" | "or"
search: string
// 날짜 범위 (선택적)
from?: string
to?: string
// 테이블 상태
columnVisibility: Record<string, boolean>
columnOrder: string[]
pinnedColumns: {
left: string[]
right: string[]
}
// 기타 확장 가능한 설정들
groupBy?: string[]
expandedRows?: string[]
}
export const tablePresets = pgTable("table_presets", {
id: uuid("id").primaryKey().defaultRandom(),
userId: text("user_id").notNull(),
tableId: text("table_id").notNull(), // 'rfq-list', 'purchase-orders' 등
name: text("name").notNull(),
settings: json("settings").$type<TableSettings>().notNull(),
isDefault: boolean("is_default").default(false).notNull(),
isActive: boolean("is_active").default(false).notNull(),
isShared: boolean("is_shared").default(false).notNull(),
createdBy: text("created_by"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
})
// 공유 프리셋 테이블
export const presetShares = pgTable("preset_shares", {
id: uuid("id").primaryKey().defaultRandom(),
presetId: uuid("preset_id").references(() => tablePresets.id, { onDelete: "cascade" }).notNull(),
sharedWithUserId: text("shared_with_user_id").notNull(),
permission: text("permission").default("read").notNull(), // 'read', 'write'
createdAt: timestamp("created_at").defaultNow().notNull(),
})
// TypeScript 타입 추출
export type TablePreset = typeof tablePresets.$inferSelect
export type NewTablePreset = typeof tablePresets.$inferInsert
|