| 1 | import {pgTable, serial, integer, text, numeric, boolean, date, primaryKey, check} from "drizzle-orm/pg-core";
|
|---|
| 2 | import {sql} from "drizzle-orm";
|
|---|
| 3 |
|
|---|
| 4 | export const componentsTable = pgTable("components", {
|
|---|
| 5 | id: serial("id").primaryKey(),
|
|---|
| 6 | name: text("name").notNull(),
|
|---|
| 7 | brand: text("brand").notNull(),
|
|---|
| 8 | price: numeric("price").notNull(),
|
|---|
| 9 | imgUrl: text("img_url"),
|
|---|
| 10 | type: text("type").notNull()
|
|---|
| 11 | },
|
|---|
| 12 | (t) => ({
|
|---|
| 13 | checkType: check("check_type", sql`${t.type} in
|
|---|
| 14 | ('cpu', 'gpu', 'memory', 'storage', 'power_supply', 'motherboard', 'case', 'cooler', 'memory_card', 'optical_drive', 'sound_card', 'cables', 'network_adapter', 'network_card')`)
|
|---|
| 15 | }),
|
|---|
| 16 | );
|
|---|
| 17 |
|
|---|
| 18 | // Base Components
|
|---|
| 19 | export const CPUTable = pgTable("cpu", {
|
|---|
| 20 | componentId: integer("component_id")
|
|---|
| 21 | .primaryKey()
|
|---|
| 22 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 23 | socket: text("socket").notNull(),
|
|---|
| 24 | cores: integer("cores").notNull(),
|
|---|
| 25 | threads: integer("threads").notNull(),
|
|---|
| 26 | baseClock: numeric("base_clock").notNull(),
|
|---|
| 27 | boostClock: numeric("boost_clock"),
|
|---|
| 28 | tdp: numeric("tdp").notNull()
|
|---|
| 29 | });
|
|---|
| 30 |
|
|---|
| 31 | export const GPUTable = pgTable("gpu", {
|
|---|
| 32 | componentId: integer("component_id")
|
|---|
| 33 | .primaryKey()
|
|---|
| 34 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 35 | vram: numeric("vram").notNull(),
|
|---|
| 36 | tdp: numeric("tdp").notNull(),
|
|---|
| 37 | baseClock: numeric("base_clock"),
|
|---|
| 38 | boostClock: numeric("boost_clock"),
|
|---|
| 39 | chipset: text("chipset").notNull(),
|
|---|
| 40 | length: numeric("length").notNull()
|
|---|
| 41 | });
|
|---|
| 42 |
|
|---|
| 43 | export const memoryTable = pgTable("memory", {
|
|---|
| 44 | componentId: integer("component_id")
|
|---|
| 45 | .primaryKey()
|
|---|
| 46 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 47 | type: text("type").notNull(),
|
|---|
| 48 | speed: numeric("speed").notNull(),
|
|---|
| 49 | capacity: numeric("capacity").notNull(),
|
|---|
| 50 | modules: integer("modules").notNull()
|
|---|
| 51 | });
|
|---|
| 52 |
|
|---|
| 53 | export const powerSupplyTable = pgTable("power_supply", {
|
|---|
| 54 | componentId: integer("component_id")
|
|---|
| 55 | .primaryKey()
|
|---|
| 56 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 57 | type: text("type").notNull(),
|
|---|
| 58 | wattage: numeric("wattage").notNull(),
|
|---|
| 59 | formFactor: text("form_factor").notNull()
|
|---|
| 60 | });
|
|---|
| 61 |
|
|---|
| 62 | export const pcCasesTable = pgTable("pc_case", {
|
|---|
| 63 | componentId: integer("component_id")
|
|---|
| 64 | .primaryKey()
|
|---|
| 65 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 66 | coolerMaxHeight: numeric("cooler_max_height").notNull(),
|
|---|
| 67 | gpuMaxLength: numeric("gpu_max_length").notNull()
|
|---|
| 68 | });
|
|---|
| 69 |
|
|---|
| 70 | // Case multi-values
|
|---|
| 71 | export const caseStorageFormFactorsTable = pgTable("case_storage_form_factors", {
|
|---|
| 72 | caseId: integer("case_id")
|
|---|
| 73 | .notNull()
|
|---|
| 74 | .references(() => pcCasesTable.componentId, {onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 75 | formFactor: text("form_factor").notNull(),
|
|---|
| 76 | numSlots: integer("num_slots").notNull()
|
|---|
| 77 | },
|
|---|
| 78 | (t) => ({
|
|---|
| 79 | pk: primaryKey({ columns: [t.caseId, t.formFactor] })
|
|---|
| 80 | }),
|
|---|
| 81 | );
|
|---|
| 82 |
|
|---|
| 83 | export const casePsFormFactorsTable = pgTable( "case_ps_form_factors", {
|
|---|
| 84 | caseId: integer("case_id")
|
|---|
| 85 | .notNull()
|
|---|
| 86 | .references(() => pcCasesTable.componentId, { onDelete: "cascade", onUpdate: "cascade"}),
|
|---|
| 87 | formFactor: text("form_factor").notNull()
|
|---|
| 88 | },
|
|---|
| 89 | (t) => ({
|
|---|
| 90 | pk: primaryKey({ columns: [t.caseId, t.formFactor] })
|
|---|
| 91 | }),
|
|---|
| 92 | );
|
|---|
| 93 |
|
|---|
| 94 | export const caseMoboFormFactorsTable = pgTable("case_mobo_form_factors", {
|
|---|
| 95 | caseId: integer("case_id")
|
|---|
| 96 | .notNull()
|
|---|
| 97 | .references(() => pcCasesTable.componentId, { onDelete: "cascade", onUpdate: "cascade"}),
|
|---|
| 98 | formFactor: text("form_factor").notNull()
|
|---|
| 99 | },
|
|---|
| 100 | (t) => ({
|
|---|
| 101 | pk: primaryKey({ columns: [t.caseId, t.formFactor] })
|
|---|
| 102 | }),
|
|---|
| 103 | );
|
|---|
| 104 |
|
|---|
| 105 | export const coolersTable = pgTable("cooler", {
|
|---|
| 106 | componentId: integer("component_id")
|
|---|
| 107 | .primaryKey()
|
|---|
| 108 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 109 | type: text("type").notNull(),
|
|---|
| 110 | height: numeric("height").notNull(),
|
|---|
| 111 | maxTdpSupported: numeric("max_tdp_supported").notNull()
|
|---|
| 112 | });
|
|---|
| 113 |
|
|---|
| 114 | // Cooler multi-values
|
|---|
| 115 | export const coolerCPUSocketsTable = pgTable("cooler_cpu_sockets", {
|
|---|
| 116 | coolerId: integer("cooler_id")
|
|---|
| 117 | .notNull()
|
|---|
| 118 | .references(() => coolersTable.componentId, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 119 | socket: text("socket").notNull()
|
|---|
| 120 | },
|
|---|
| 121 | (t) => ({
|
|---|
| 122 | pk: primaryKey({ columns: [t.coolerId, t.socket] })
|
|---|
| 123 | })
|
|---|
| 124 | );
|
|---|
| 125 |
|
|---|
| 126 | export const motherboardsTable = pgTable("motherboard", {
|
|---|
| 127 | componentId: integer("component_id")
|
|---|
| 128 | .primaryKey()
|
|---|
| 129 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 130 |
|
|---|
| 131 | socket: text("socket").notNull(),
|
|---|
| 132 | chipset: text("chipset").notNull(),
|
|---|
| 133 | formFactor: text("form_factor").notNull(),
|
|---|
| 134 | ramType: text("ram_type").notNull(),
|
|---|
| 135 | numRamSlots: integer("num_ram_slots").notNull(),
|
|---|
| 136 | maxRamCapacity: numeric("max_ram_capacity").notNull(),
|
|---|
| 137 | pciExpressSlots: numeric("pci_express_slots").notNull()
|
|---|
| 138 | });
|
|---|
| 139 |
|
|---|
| 140 | export const storageTable = pgTable("storage", {
|
|---|
| 141 | componentId: integer("component_id")
|
|---|
| 142 | .primaryKey()
|
|---|
| 143 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 144 | type: text("type").notNull(),
|
|---|
| 145 | capacity: numeric("capacity").notNull(),
|
|---|
| 146 | formFactor: text("form_factor").notNull()
|
|---|
| 147 | });
|
|---|
| 148 |
|
|---|
| 149 | // Other Components
|
|---|
| 150 | export const memoryCardsTable = pgTable("memory_card", {
|
|---|
| 151 | componentId: integer("component_id")
|
|---|
| 152 | .primaryKey()
|
|---|
| 153 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 154 | numSlots: integer("num_slots").notNull(),
|
|---|
| 155 | interface: text("interface").notNull()
|
|---|
| 156 | });
|
|---|
| 157 |
|
|---|
| 158 | export const opticalDrivesTable = pgTable("optical_drive", {
|
|---|
| 159 | componentId: integer("component_id")
|
|---|
| 160 | .primaryKey()
|
|---|
| 161 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 162 | formFactor: text("form_factor").notNull(),
|
|---|
| 163 | type: text("type").notNull(),
|
|---|
| 164 | interface: text("interface").notNull(),
|
|---|
| 165 | writeSpeed: numeric("write_speed").notNull(),
|
|---|
| 166 | readSpeed: numeric("read_speed").notNull()
|
|---|
| 167 | });
|
|---|
| 168 |
|
|---|
| 169 | export const soundCardsTable = pgTable("sound_card", {
|
|---|
| 170 | componentId: integer("component_id")
|
|---|
| 171 | .primaryKey()
|
|---|
| 172 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 173 | sampleRate: numeric("sample_rate").notNull(),
|
|---|
| 174 | bitDepth: numeric("bit_depth").notNull(),
|
|---|
| 175 | chipset: text("chipset").notNull(),
|
|---|
| 176 | interface: text("interface").notNull(),
|
|---|
| 177 | channel: text("channel").notNull()
|
|---|
| 178 | });
|
|---|
| 179 |
|
|---|
| 180 | export const cablesTable = pgTable("cables", {
|
|---|
| 181 | componentId: integer("component_id")
|
|---|
| 182 | .primaryKey()
|
|---|
| 183 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 184 | lengthCm: numeric("length_cm").notNull(),
|
|---|
| 185 | type: text("type").notNull()
|
|---|
| 186 | });
|
|---|
| 187 |
|
|---|
| 188 | export const networkAdaptersTable = pgTable("network_adapter", {
|
|---|
| 189 | componentId: integer("component_id")
|
|---|
| 190 | .primaryKey()
|
|---|
| 191 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 192 | wifiVersion: text("wifi_version").notNull(),
|
|---|
| 193 | interface: text("interface").notNull(),
|
|---|
| 194 | numAntennas: integer("num_antennas").notNull()
|
|---|
| 195 | });
|
|---|
| 196 |
|
|---|
| 197 | export const networkCardsTable = pgTable("network_card", {
|
|---|
| 198 | componentId: integer("component_id")
|
|---|
| 199 | .primaryKey()
|
|---|
| 200 | .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }),
|
|---|
| 201 | numPorts: integer("num_ports").notNull(),
|
|---|
| 202 | speed: numeric("speed").notNull(),
|
|---|
| 203 | interface: text("interface").notNull()
|
|---|
| 204 | });
|
|---|
| 205 |
|
|---|
| 206 | export type componentItem = typeof componentsTable.$inferSelect;
|
|---|
| 207 | export type componentInsert = typeof componentsTable.$inferInsert;
|
|---|
| 208 |
|
|---|
| 209 | export type cpuItem = typeof CPUTable.$inferSelect;
|
|---|
| 210 | export type cpuInsert = typeof CPUTable.$inferInsert;
|
|---|
| 211 |
|
|---|
| 212 | export type gpuItem = typeof GPUTable.$inferSelect;
|
|---|
| 213 | export type gpuInsert = typeof GPUTable.$inferInsert;
|
|---|
| 214 |
|
|---|
| 215 | export type memoryItem = typeof memoryTable.$inferSelect;
|
|---|
| 216 | export type memoryInsert = typeof memoryTable.$inferInsert;
|
|---|
| 217 |
|
|---|
| 218 | export type powerSupplyItem = typeof powerSupplyTable.$inferSelect;
|
|---|
| 219 | export type powerSupplyInsert = typeof powerSupplyTable.$inferInsert;
|
|---|
| 220 |
|
|---|
| 221 | export type caseItem = typeof pcCasesTable.$inferSelect;
|
|---|
| 222 | export type caseInsert = typeof pcCasesTable.$inferInsert;
|
|---|
| 223 |
|
|---|
| 224 | export type caseStorageFormFactorsItem = typeof caseStorageFormFactorsTable.$inferSelect;
|
|---|
| 225 | export type caseStorageFormFactorsInsert = typeof caseStorageFormFactorsTable.$inferInsert;
|
|---|
| 226 |
|
|---|
| 227 | export type casePsFormFactorsItem = typeof casePsFormFactorsTable.$inferSelect;
|
|---|
| 228 | export type casePsFormFactorsInsert = typeof casePsFormFactorsTable.$inferInsert;
|
|---|
| 229 |
|
|---|
| 230 | export type caseMoboFormFactorsItem = typeof caseMoboFormFactorsTable.$inferSelect;
|
|---|
| 231 | export type caseMoboFormFactorsInsert = typeof caseMoboFormFactorsTable.$inferInsert;
|
|---|
| 232 |
|
|---|
| 233 | export type coolerItem = typeof coolersTable.$inferSelect;
|
|---|
| 234 | export type coolerInsert = typeof coolersTable.$inferInsert;
|
|---|
| 235 |
|
|---|
| 236 | export type coolerCPUSocketsItem = typeof coolerCPUSocketsTable.$inferSelect;
|
|---|
| 237 | export type coolerCPUSocketsInsert = typeof coolerCPUSocketsTable.$inferInsert;
|
|---|
| 238 |
|
|---|
| 239 | export type motherboardItem = typeof motherboardsTable.$inferSelect;
|
|---|
| 240 | export type motherboardInsert = typeof motherboardsTable.$inferInsert;
|
|---|
| 241 |
|
|---|
| 242 | export type storageItem = typeof storageTable.$inferSelect;
|
|---|
| 243 | export type storageInsert = typeof storageTable.$inferInsert
|
|---|
| 244 |
|
|---|
| 245 | export type memoryCardItem = typeof memoryCardsTable.$inferSelect;
|
|---|
| 246 | export type memoryCardInsert = typeof memoryCardsTable.$inferInsert;
|
|---|
| 247 |
|
|---|
| 248 | export type opticalDriveItem = typeof opticalDrivesTable.$inferSelect;
|
|---|
| 249 | export type opticalDriveInsert = typeof opticalDrivesTable.$inferInsert;
|
|---|
| 250 |
|
|---|
| 251 | export type soundCardItem = typeof soundCardsTable.$inferSelect;
|
|---|
| 252 | export type soundCardInsert = typeof soundCardsTable.$inferInsert;
|
|---|
| 253 |
|
|---|
| 254 | export type cablesItem = typeof cablesTable.$inferSelect;
|
|---|
| 255 | export type cablesInsert = typeof cablesTable.$inferInsert;
|
|---|
| 256 |
|
|---|
| 257 | export type networkAdapterItem = typeof networkAdaptersTable.$inferSelect;
|
|---|
| 258 | export type networkAdapterInsert = typeof networkAdaptersTable.$inferInsert;
|
|---|
| 259 |
|
|---|
| 260 | export type networkCardItem = typeof networkCardsTable.$inferSelect;
|
|---|
| 261 | export type networkCardInsert = typeof networkCardsTable.$inferInsert;
|
|---|
| 262 |
|
|---|