Changeset 1ebac59 for database/drizzle
- Timestamp:
- 12/20/25 00:55:47 (7 months ago)
- Branches:
- main
- Children:
- b69759d
- Parents:
- c30935a
- Location:
- database/drizzle
- Files:
-
- 3 added
- 3 edited
-
queries/builds.ts (added)
-
queries/components.ts (added)
-
queries/index.ts (added)
-
schema/builds.ts (modified) (6 diffs)
-
schema/components.ts (modified) (15 diffs)
-
schema/relations.ts (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
database/drizzle/schema/builds.ts
rc30935a r1ebac59 3 3 import { componentsTable } from "./components"; 4 4 5 export const build Table = pgTable("build", {5 export const buildsTable = pgTable("build", { 6 6 id: serial("id").primaryKey(), 7 7 userId: integer("user_id") … … 15 15 }); 16 16 17 export const buildComponent Table = pgTable("build_component", {17 export const buildComponentsTable = pgTable("build_component", { 18 18 buildId: integer("build_id") 19 19 .notNull() 20 .references(() => build Table.id, { onDelete: "cascade", onUpdate: "cascade" }),20 .references(() => buildsTable.id, { onDelete: "cascade", onUpdate: "cascade" }), 21 21 componentId: integer("component_id") 22 22 .notNull() … … 28 28 ); 29 29 30 export const favoriteBuild Table = pgTable("favorite_build", {30 export const favoriteBuildsTable = pgTable("favorite_build", { 31 31 buildId: integer("build_id") 32 32 .notNull() 33 .references(() => build Table.id, { onDelete: "cascade", onUpdate: "cascade" }),33 .references(() => buildsTable.id, { onDelete: "cascade", onUpdate: "cascade" }), 34 34 userId: integer("user_id") 35 35 .notNull() … … 41 41 ); 42 42 43 export const ratingBuild Table = pgTable("rating_build", {43 export const ratingBuildsTable = pgTable("rating_build", { 44 44 buildId: integer("build_id") 45 45 .notNull() 46 .references(() => build Table.id, { onDelete: "cascade", onUpdate: "cascade" }),46 .references(() => buildsTable.id, { onDelete: "cascade", onUpdate: "cascade" }), 47 47 userId: integer("user_id") 48 48 .notNull() … … 55 55 ); 56 56 57 export const review Table = pgTable("review", {57 export const reviewsTable = pgTable("review", { 58 58 id: serial("id").primaryKey(), 59 59 60 60 buildId: integer("build_id") 61 61 .notNull() 62 .references(() => build Table.id, { onDelete: "cascade", onUpdate: "cascade" }),62 .references(() => buildsTable.id, { onDelete: "cascade", onUpdate: "cascade" }), 63 63 userId: integer("user_id") 64 64 .notNull() … … 68 68 }); 69 69 70 export type buildItem = typeof build Table.$inferSelect;71 export type buildInsert = typeof build Table.$inferInsert;70 export type buildItem = typeof buildsTable.$inferSelect; 71 export type buildInsert = typeof buildsTable.$inferInsert; 72 72 73 export type buildComponentItem = typeof buildComponent Table.$inferSelect;74 export type buildComponentInsert = typeof buildComponent Table.$inferInsert;73 export type buildComponentItem = typeof buildComponentsTable.$inferSelect; 74 export type buildComponentInsert = typeof buildComponentsTable.$inferInsert; 75 75 76 export type favoriteBuildItem = typeof favoriteBuild Table.$inferSelect;77 export type favoriteBuildInsert = typeof favoriteBuild Table.$inferInsert;76 export type favoriteBuildItem = typeof favoriteBuildsTable.$inferSelect; 77 export type favoriteBuildInsert = typeof favoriteBuildsTable.$inferInsert; 78 78 79 export type ratingBuildItem = typeof ratingBuild Table.$inferSelect;80 export type ratingBuildInsert = typeof ratingBuild Table.$inferInsert;79 export type ratingBuildItem = typeof ratingBuildsTable.$inferSelect; 80 export type ratingBuildInsert = typeof ratingBuildsTable.$inferInsert; 81 81 82 export type reviewItem = typeof review Table.$inferSelect;83 export type reviewInsert = typeof review Table.$inferInsert;82 export type reviewItem = typeof reviewsTable.$inferSelect; 83 export type reviewInsert = typeof reviewsTable.$inferInsert; -
database/drizzle/schema/components.ts
rc30935a r1ebac59 53 53 }); 54 54 55 export const pcCase Table = pgTable("pc_case", {55 export const pcCasesTable = pgTable("pc_case", { 56 56 componentId: integer("component_id") 57 57 .primaryKey() … … 65 65 caseId: integer("case_id") 66 66 .notNull() 67 .references(() => pcCase Table.componentId, {onDelete: "cascade", onUpdate: "cascade" }),67 .references(() => pcCasesTable.componentId, {onDelete: "cascade", onUpdate: "cascade" }), 68 68 formFactor: text("form_factor").notNull(), 69 num_slots: integer("num_slots").notNull(), 69 70 }, 70 71 (t) => ({ … … 76 77 caseId: integer("case_id") 77 78 .notNull() 78 .references(() => pcCase Table.componentId, { onDelete: "cascade", onUpdate: "cascade"}),79 .references(() => pcCasesTable.componentId, { onDelete: "cascade", onUpdate: "cascade"}), 79 80 formFactor: text("form_factor").notNull(), 80 81 }, … … 87 88 caseId: integer("case_id") 88 89 .notNull() 89 .references(() => pcCase Table.componentId, { onDelete: "cascade", onUpdate: "cascade"}),90 .references(() => pcCasesTable.componentId, { onDelete: "cascade", onUpdate: "cascade"}), 90 91 formFactor: text("form_factor").notNull(), 91 92 }, … … 95 96 ); 96 97 97 export const cooler Table = pgTable("cooler", {98 export const coolersTable = pgTable("cooler", { 98 99 componentId: integer("component_id") 99 100 .primaryKey() … … 108 109 cooler_id: integer("cooler_id") 109 110 .notNull() 110 .references(() => cooler Table.componentId, { onDelete: "cascade", onUpdate: "cascade" }),111 .references(() => coolersTable.componentId, { onDelete: "cascade", onUpdate: "cascade" }), 111 112 socket: text("socket").notNull(), 112 113 }, … … 116 117 ); 117 118 118 export const motherboard Table = pgTable("motherboard", {119 export const motherboardsTable = pgTable("motherboard", { 119 120 componentId: integer("component_id") 120 121 .primaryKey() … … 139 140 140 141 // Other Components 141 export const memoryCard Table = pgTable("memory_card", {142 export const memoryCardsTable = pgTable("memory_card", { 142 143 componentId: integer("component_id") 143 144 .primaryKey() … … 147 148 }); 148 149 149 export const opticalDrive Table = pgTable("optical_drive", {150 export const opticalDrivesTable = pgTable("optical_drive", { 150 151 componentId: integer("component_id") 151 152 .primaryKey() … … 158 159 }); 159 160 160 export const soundCard Table = pgTable("sound_card", {161 export const soundCardsTable = pgTable("sound_card", { 161 162 componentId: integer("component_id") 162 163 .primaryKey() … … 166 167 chipset: text("chipset").notNull(), 167 168 interface: text("interface").notNull(), 168 }); 169 170 // SoundCard multi-values 171 export const soundCardChannelsTable = pgTable("sound_card_channels", { 172 soundCardId: integer("sound_card_id") 173 .notNull() 174 .references(() => soundCardTable.componentId, { onDelete: "cascade", onUpdate: "cascade" }), 175 channel: text("channel").notNull(), 176 }, 177 (t) => ({ 178 pk: primaryKey({ columns: [t.soundCardId, t.channel] }), 179 }) 180 ); 169 channel: text("channel").notNull(), 170 }); 181 171 182 172 export const cablesTable = pgTable("cables", { … … 188 178 }); 189 179 190 export const networkAdapter Table = pgTable("network_adapter", {180 export const networkAdaptersTable = pgTable("network_adapter", { 191 181 componentId: integer("component_id") 192 182 .primaryKey() … … 197 187 }); 198 188 199 export const networkCard Table = pgTable("network_card", {189 export const networkCardsTable = pgTable("network_card", { 200 190 componentId: integer("component_id") 201 191 .primaryKey() … … 221 211 export type powerSupplyInsert = typeof powerSupplyTable.$inferInsert; 222 212 223 export type caseItem = typeof pcCase Table.$inferSelect;224 export type caseInsert = typeof pcCase Table.$inferInsert;213 export type caseItem = typeof pcCasesTable.$inferSelect; 214 export type caseInsert = typeof pcCasesTable.$inferInsert; 225 215 226 216 export type caseStorageFormFactorsItem = typeof caseStorageFormFactorsTable.$inferSelect; … … 233 223 export type caseMoboFormFactorsInsert = typeof caseMoboFormFactorsTable.$inferInsert; 234 224 235 export type coolerItem = typeof cooler Table.$inferSelect;236 export type coolerInsert = typeof cooler Table.$inferInsert;225 export type coolerItem = typeof coolersTable.$inferSelect; 226 export type coolerInsert = typeof coolersTable.$inferInsert; 237 227 238 228 export type coolerCPUSocketsItem = typeof coolerCPUSocketsTable.$inferSelect; 239 229 export type coolerCPUSocketsInsert = typeof coolerCPUSocketsTable.$inferInsert; 240 230 241 export type motherboardItem = typeof motherboard Table.$inferSelect;242 export type motherboardInsert = typeof motherboard Table.$inferInsert;231 export type motherboardItem = typeof motherboardsTable.$inferSelect; 232 export type motherboardInsert = typeof motherboardsTable.$inferInsert; 243 233 244 234 export type storageItem = typeof storageTable.$inferSelect; 245 235 export type storageInsert = typeof storageTable.$inferInsert 246 236 247 export type memoryCardItem = typeof memoryCardTable.$inferSelect; 248 export type memoryCardInsert = typeof memoryCardTable.$inferInsert; 249 250 export type opticalDriveItem = typeof opticalDriveTable.$inferSelect; 251 export type opticalDriveInsert = typeof opticalDriveTable.$inferInsert; 252 253 export type soundCardItem = typeof soundCardTable.$inferSelect; 254 export type soundCardInsert = typeof soundCardTable.$inferInsert; 255 256 export type soundCardChannelsItem = typeof soundCardChannelsTable.$inferSelect; 257 export type soundCardChannelsInsert = typeof soundCardChannelsTable.$inferInsert; 237 export type memoryCardItem = typeof memoryCardsTable.$inferSelect; 238 export type memoryCardInsert = typeof memoryCardsTable.$inferInsert; 239 240 export type opticalDriveItem = typeof opticalDrivesTable.$inferSelect; 241 export type opticalDriveInsert = typeof opticalDrivesTable.$inferInsert; 242 243 export type soundCardItem = typeof soundCardsTable.$inferSelect; 244 export type soundCardInsert = typeof soundCardsTable.$inferInsert; 258 245 259 246 export type cablesItem = typeof cablesTable.$inferSelect; 260 247 export type cablesInsert = typeof cablesTable.$inferInsert; 261 248 262 export type networkAdapterItem = typeof networkAdapter Table.$inferSelect;263 export type networkAdapterInsert = typeof networkAdapter Table.$inferInsert;264 265 export type networkCardItem = typeof networkCard Table.$inferSelect;266 export type networkCardInsert = typeof networkCard Table.$inferInsert;267 249 export type networkAdapterItem = typeof networkAdaptersTable.$inferSelect; 250 export type networkAdapterInsert = typeof networkAdaptersTable.$inferInsert; 251 252 export type networkCardItem = typeof networkCardsTable.$inferSelect; 253 export type networkCardInsert = typeof networkCardsTable.$inferInsert; 254 -
database/drizzle/schema/relations.ts
rc30935a r1ebac59 7 7 memoryTable, 8 8 powerSupplyTable, 9 pcCase Table,9 pcCasesTable, 10 10 caseStorageFormFactorsTable, 11 11 casePsFormFactorsTable, 12 12 caseMoboFormFactorsTable, 13 cooler Table,13 coolersTable, 14 14 coolerCPUSocketsTable, 15 motherboard Table,15 motherboardsTable, 16 16 storageTable, 17 memoryCardTable, 18 opticalDriveTable, 19 soundCardTable, 20 soundCardChannelsTable, 17 memoryCardsTable, 18 opticalDrivesTable, 19 soundCardsTable, 21 20 cablesTable, 22 networkAdapter Table,23 networkCard Table,21 networkAdaptersTable, 22 networkCardsTable, 24 23 25 24 } from "./components"; 26 25 27 26 import { 28 build Table,29 buildComponent Table,30 favoriteBuild Table,31 ratingBuild Table,32 review Table27 buildsTable, 28 buildComponentsTable, 29 favoriteBuildsTable, 30 ratingBuildsTable, 31 reviewsTable 33 32 } from "./builds" 34 33 … … 40 39 41 40 export const usersRelations = relations(usersTable, ({ many, one }) => ({ 42 builds: many(build Table),43 reviews: many(review Table),44 favorites: many(favoriteBuild Table),45 ratings: many(ratingBuild Table),41 builds: many(buildsTable), 42 reviews: many(reviewsTable), 43 favorites: many(favoriteBuildsTable), 44 ratings: many(ratingBuildsTable), 46 45 suggestions: many(suggestionsTable), 47 46 adminProfile: one(adminsTable, { … … 70 69 })); 71 70 72 export const buildRelations = relations(build Table, ({ one, many }) => ({71 export const buildRelations = relations(buildsTable, ({ one, many }) => ({ 73 72 owner: one(usersTable, { 74 fields: [build Table.userId],75 references: [usersTable.id], 76 }), 77 buildComponents: many(buildComponent Table),78 favorites: many(favoriteBuild Table),79 ratings: many(ratingBuild Table),80 reviews: many(review Table),81 })); 82 83 export const buildComponentRelations = relations(buildComponent Table, ({ one }) => ({84 build: one(build Table, {85 fields: [buildComponent Table.buildId],86 references: [build Table.id],87 }), 88 component: one(componentsTable, { 89 fields: [buildComponent Table.componentId],90 references: [componentsTable.id], 91 }), 92 })); 93 94 export const favoriteBuildRelations = relations(favoriteBuild Table, ({ one }) => ({73 fields: [buildsTable.userId], 74 references: [usersTable.id], 75 }), 76 buildComponents: many(buildComponentsTable), 77 favorites: many(favoriteBuildsTable), 78 ratings: many(ratingBuildsTable), 79 reviews: many(reviewsTable), 80 })); 81 82 export const buildComponentRelations = relations(buildComponentsTable, ({ one }) => ({ 83 build: one(buildsTable, { 84 fields: [buildComponentsTable.buildId], 85 references: [buildsTable.id], 86 }), 87 component: one(componentsTable, { 88 fields: [buildComponentsTable.componentId], 89 references: [componentsTable.id], 90 }), 91 })); 92 93 export const favoriteBuildRelations = relations(favoriteBuildsTable, ({ one }) => ({ 95 94 user: one(usersTable, { 96 fields: [favoriteBuild Table.userId],97 references: [usersTable.id], 98 }), 99 build: one(build Table, {100 fields: [favoriteBuild Table.buildId],101 references: [build Table.id],102 }), 103 })); 104 105 export const ratingBuildRelations = relations(ratingBuild Table, ({ one }) => ({95 fields: [favoriteBuildsTable.userId], 96 references: [usersTable.id], 97 }), 98 build: one(buildsTable, { 99 fields: [favoriteBuildsTable.buildId], 100 references: [buildsTable.id], 101 }), 102 })); 103 104 export const ratingBuildRelations = relations(ratingBuildsTable, ({ one }) => ({ 106 105 user: one(usersTable, { 107 fields: [ratingBuild Table.userId],108 references: [usersTable.id], 109 }), 110 build: one(build Table, {111 fields: [ratingBuild Table.buildId],112 references: [build Table.id],113 }), 114 })); 115 116 export const reviewRelations = relations(review Table, ({ one }) => ({106 fields: [ratingBuildsTable.userId], 107 references: [usersTable.id], 108 }), 109 build: one(buildsTable, { 110 fields: [ratingBuildsTable.buildId], 111 references: [buildsTable.id], 112 }), 113 })); 114 115 export const reviewRelations = relations(reviewsTable, ({ one }) => ({ 117 116 author: one(usersTable, { 118 fields: [review Table.userId],119 references: [usersTable.id], 120 }), 121 build: one(build Table, {122 fields: [review Table.buildId],123 references: [build Table.id],117 fields: [reviewsTable.userId], 118 references: [usersTable.id], 119 }), 120 build: one(buildsTable, { 121 fields: [reviewsTable.buildId], 122 references: [buildsTable.id], 124 123 }), 125 124 })); 126 125 127 126 export const componentsRelations = relations(componentsTable, ({ many, one }) => ({ 128 buildComponents: many(buildComponent Table),127 buildComponents: many(buildComponentsTable), 129 128 130 129 cpu: one(CPUTable, { … … 144 143 references: [powerSupplyTable.componentId] 145 144 }), 146 pcCase: one(pcCase Table, {147 fields: [componentsTable.id], 148 references: [pcCase Table.componentId]149 }), 150 cooler: one(cooler Table, {151 fields: [componentsTable.id], 152 references: [cooler Table.componentId]153 }), 154 motherboard: one(motherboard Table, {155 fields: [componentsTable.id], 156 references: [motherboard Table.componentId]145 pcCase: one(pcCasesTable, { 146 fields: [componentsTable.id], 147 references: [pcCasesTable.componentId] 148 }), 149 cooler: one(coolersTable, { 150 fields: [componentsTable.id], 151 references: [coolersTable.componentId] 152 }), 153 motherboard: one(motherboardsTable, { 154 fields: [componentsTable.id], 155 references: [motherboardsTable.componentId] 157 156 }), 158 157 storage: one(storageTable, { … … 160 159 references: [storageTable.componentId] 161 160 }), 162 memoryCard: one(memoryCard Table, {163 fields: [componentsTable.id], 164 references: [memoryCard Table.componentId]165 }), 166 opticalDrive: one(opticalDrive Table, {167 fields: [componentsTable.id], 168 references: [opticalDrive Table.componentId]169 }), 170 soundCard: one(soundCard Table, {171 fields: [componentsTable.id], 172 references: [soundCard Table.componentId]161 memoryCard: one(memoryCardsTable, { 162 fields: [componentsTable.id], 163 references: [memoryCardsTable.componentId] 164 }), 165 opticalDrive: one(opticalDrivesTable, { 166 fields: [componentsTable.id], 167 references: [opticalDrivesTable.componentId] 168 }), 169 soundCard: one(soundCardsTable, { 170 fields: [componentsTable.id], 171 references: [soundCardsTable.componentId] 173 172 }), 174 173 cables: one(cablesTable, { … … 176 175 references: [cablesTable.componentId] 177 176 }), 178 networkAdapter: one(networkAdapter Table, {179 fields: [componentsTable.id], 180 references: [networkAdapter Table.componentId]181 }), 182 networkCard: one(networkCard Table, {183 fields: [componentsTable.id], 184 references: [networkCard Table.componentId]177 networkAdapter: one(networkAdaptersTable, { 178 fields: [componentsTable.id], 179 references: [networkAdaptersTable.componentId] 180 }), 181 networkCard: one(networkCardsTable, { 182 fields: [componentsTable.id], 183 references: [networkCardsTable.componentId] 185 184 }), 186 185 })); … … 214 213 })); 215 214 216 export const motherboardRelations = relations(motherboard Table, ({ one }) => ({217 component: one(componentsTable, { 218 fields: [motherboard Table.componentId],215 export const motherboardRelations = relations(motherboardsTable, ({ one }) => ({ 216 component: one(componentsTable, { 217 fields: [motherboardsTable.componentId], 219 218 references: [componentsTable.id], 220 219 }), … … 228 227 })); 229 228 230 export const memoryCardRelations = relations(memoryCard Table, ({ one }) => ({231 component: one(componentsTable, { 232 fields: [memoryCard Table.componentId],233 references: [componentsTable.id], 234 }), 235 })); 236 237 export const opticalDriveRelations = relations(opticalDrive Table, ({ one }) => ({238 component: one(componentsTable, { 239 fields: [opticalDrive Table.componentId],229 export const memoryCardRelations = relations(memoryCardsTable, ({ one }) => ({ 230 component: one(componentsTable, { 231 fields: [memoryCardsTable.componentId], 232 references: [componentsTable.id], 233 }), 234 })); 235 236 export const opticalDriveRelations = relations(opticalDrivesTable, ({ one }) => ({ 237 component: one(componentsTable, { 238 fields: [opticalDrivesTable.componentId], 240 239 references: [componentsTable.id], 241 240 }), … … 249 248 })); 250 249 251 export const networkAdapterRelations = relations(networkAdapter Table, ({ one }) => ({252 component: one(componentsTable, { 253 fields: [networkAdapter Table.componentId],254 references: [componentsTable.id], 255 }), 256 })); 257 258 export const networkCardRelations = relations(networkCard Table, ({ one }) => ({259 component: one(componentsTable, { 260 fields: [networkCard Table.componentId],261 references: [componentsTable.id], 262 }), 263 })); 264 265 export const pcCaseRelations = relations(pcCase Table, ({ one, many }) => ({266 component: one(componentsTable, { 267 fields: [pcCase Table.componentId],250 export const networkAdapterRelations = relations(networkAdaptersTable, ({ one }) => ({ 251 component: one(componentsTable, { 252 fields: [networkAdaptersTable.componentId], 253 references: [componentsTable.id], 254 }), 255 })); 256 257 export const networkCardRelations = relations(networkCardsTable, ({ one }) => ({ 258 component: one(componentsTable, { 259 fields: [networkCardsTable.componentId], 260 references: [componentsTable.id], 261 }), 262 })); 263 264 export const pcCaseRelations = relations(pcCasesTable, ({ one, many }) => ({ 265 component: one(componentsTable, { 266 fields: [pcCasesTable.componentId], 268 267 references: [componentsTable.id], 269 268 }), … … 274 273 275 274 export const caseStorageFormFactorsRelations = relations(caseStorageFormFactorsTable, ({ one }) => ({ 276 pcCase: one(pcCase Table, {275 pcCase: one(pcCasesTable, { 277 276 fields: [caseStorageFormFactorsTable.caseId], 278 references: [pcCase Table.componentId],277 references: [pcCasesTable.componentId], 279 278 }), 280 279 })); 281 280 282 281 export const casePsFormFactorsRelations = relations(casePsFormFactorsTable, ({ one }) => ({ 283 pcCase: one(pcCase Table, {282 pcCase: one(pcCasesTable, { 284 283 fields: [casePsFormFactorsTable.caseId], 285 references: [pcCase Table.componentId],284 references: [pcCasesTable.componentId], 286 285 }), 287 286 })); 288 287 289 288 export const caseMoboFormFactorsRelations = relations(caseMoboFormFactorsTable, ({ one }) => ({ 290 pcCase: one(pcCase Table, {289 pcCase: one(pcCasesTable, { 291 290 fields: [caseMoboFormFactorsTable.caseId], 292 references: [pcCase Table.componentId],293 }), 294 })); 295 296 export const coolerRelations = relations(cooler Table, ({ one, many }) => ({297 component: one(componentsTable, { 298 fields: [cooler Table.componentId],291 references: [pcCasesTable.componentId], 292 }), 293 })); 294 295 export const coolerRelations = relations(coolersTable, ({ one, many }) => ({ 296 component: one(componentsTable, { 297 fields: [coolersTable.componentId], 299 298 references: [componentsTable.id], 300 299 }), … … 303 302 304 303 export const coolerCpuSocketsRelations = relations(coolerCPUSocketsTable, ({ one }) => ({ 305 cooler: one(cooler Table, {304 cooler: one(coolersTable, { 306 305 fields: [coolerCPUSocketsTable.cooler_id], 307 references: [coolerTable.componentId], 308 }), 309 })); 310 311 export const soundCardRelations = relations(soundCardTable, ({ one, many }) => ({ 312 component: one(componentsTable, { 313 fields: [soundCardTable.componentId], 314 references: [componentsTable.id], 315 }), 316 channels: many(soundCardChannelsTable), 317 })); 318 319 export const soundCardChannelsRelations = relations(soundCardChannelsTable, ({ one }) => ({ 320 soundCard: one(soundCardTable, { 321 fields: [soundCardChannelsTable.soundCardId], 322 references: [soundCardTable.componentId], 323 }), 324 })); 306 references: [coolersTable.componentId], 307 }), 308 })); 309 310 export const soundCardRelations = relations(soundCardsTable, ({ one, many }) => ({ 311 component: one(componentsTable, { 312 fields: [soundCardsTable.componentId], 313 references: [componentsTable.id], 314 }), 315 }));
Note:
See TracChangeset
for help on using the changeset viewer.
