Changes in / [a744c90:87b79bc]
- Location:
- database
- Files:
-
- 1 added
- 1 deleted
- 5 edited
-
drizzle/queries/builds.ts (modified) (6 diffs)
-
drizzle/queries/components.ts (modified) (14 diffs)
-
drizzle/schema/builds.ts (modified) (2 diffs)
-
migrations/0000_regular_kulan_gath.sql (added)
-
migrations/0000_shallow_darkhawk.sql (deleted)
-
migrations/meta/0000_snapshot.json (modified) (4 diffs)
-
migrations/meta/_journal.json (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
database/drizzle/queries/builds.ts
ra744c90 r87b79bc 200 200 .select({ 201 201 componentId: buildComponentsTable.componentId, 202 component: componentsTable, 203 quantity: buildComponentsTable.numComponents 202 component: componentsTable 204 203 }) 205 204 .from(buildComponentsTable) … … 293 292 return { 294 293 ...buildDetails, 295 components: components.map(c => ({ 296 ...c.component, 297 quantity: c.quantity 298 })), 294 components: components.map(c => c.component), 299 295 reviews: reviews.map(r => ({ 300 296 username: r.username, … … 423 419 424 420 const existing = await tx 425 .select({ 426 componentId: buildComponentsTable.componentId, 427 numComponents: buildComponentsTable.numComponents 428 }) 421 .select({ componentId: buildComponentsTable.componentId }) 429 422 .from(buildComponentsTable) 430 423 .where(eq(buildComponentsTable.buildId, buildId)); … … 435 428 buildId: newBuild.id, 436 429 componentId: r.componentId, 437 numComponents: r.numComponents438 430 })), 439 431 ); … … 553 545 const components = await tx 554 546 .select({ 555 componentId: buildComponentsTable.componentId, 556 quantity: buildComponentsTable.numComponents 547 componentId: buildComponentsTable.componentId 557 548 }) 558 549 .from(buildComponentsTable) … … 563 554 return { 564 555 build, 565 components: components.map(c => ({ 566 id: c.componentId, 567 quantity: c.quantity 568 })) 556 componentIds: components.map(c => c.componentId) 569 557 }; 570 558 }); -
database/drizzle/queries/components.ts
ra744c90 r87b79bc 196 196 id: componentsTable.id, 197 197 type: componentsTable.type, 198 quantity: buildComponentsTable.numComponents199 198 }) 200 199 .from(buildComponentsTable) … … 232 231 componentsDetails.push({ 233 232 ...comp, 234 quantity: comp.quantity,235 233 details: details 236 234 }); … … 258 256 259 257 if(!existingComponents) return null; 258 259 260 260 261 261 const existing = { … … 278 278 ...existing.networkAdapters, 279 279 ...existing.soundCards 280 ].reduce((sum: number, c: any) => { 281 if (!c) return sum; 282 return sum + (c.quantity || 1); 283 }, 0); 280 ].filter(Boolean).length; 284 281 285 282 const existingTDP = existingComponents.reduce((sum, c) => { 286 283 const tdp = c.details?.tdp ? Number(c.details.tdp) : 0; 287 return sum + (tdp * (c.quantity || 1));284 return sum + tdp; 288 285 }, 0); 289 286 … … 459 456 if (existing.memory.length > 0) { 460 457 const totalModules = existing.memory.reduce((sum: number, m: any) => 461 sum + (Number(m.details.modules) * m.quantity), 0458 sum + Number(m.details.modules), 0 462 459 ); 463 460 const totalCapacity = existing.memory.reduce((sum: number, m: any) => 464 sum + (Number(m.details.capacity) * m.quantity), 0461 sum + Number(m.details.capacity), 0 465 462 ); 466 463 … … 707 704 if (!caseStorageFormFactor) return false; 708 705 709 const usedSlots = existing.storage 710 .filter((s: any) => s.details.formFactor === stor.formFactor)711 .reduce((sum: number, s: any) => sum + s.quantity, 0);706 const usedSlots = existing.storage.filter( 707 (s: any) => s.details.formFactor === stor.formFactor 708 ).length; 712 709 713 710 return usedSlots < Number(caseStorageFormFactor.numSlots); … … 824 821 if (!storageFF) return false; 825 822 826 const usedSlots = existing.storage 827 .filter((s: any) => s.details.formFactor === stor.details.formFactor)828 .reduce((sum: number, s: any) => sum + s.quantity, 0);;823 const usedSlots = existing.storage.filter( 824 (s: any) => s.details.formFactor === stor.details.formFactor 825 ).length; 829 826 830 827 return usedSlots <= Number(storageFF.numSlots); … … 966 963 .values({ 967 964 buildId, 968 componentId, 969 numComponents: 1 970 }) 971 .onConflictDoUpdate({ 972 target: [buildComponentsTable.buildId, buildComponentsTable.componentId], 973 set: { 974 numComponents: sql`${buildComponentsTable.numComponents} + 1` 975 } 965 componentId 976 966 }); 977 967 … … 979 969 .select({ 980 970 price: componentsTable.price, 981 quantity: buildComponentsTable.numComponents982 971 }) 983 972 .from(buildComponentsTable) … … 990 979 ); 991 980 992 const totalPrice = buildComponents.reduce((sum, c) => 993 sum + (Number(c.price) * c.quantity), 0 994 ); 981 const totalPrice = buildComponents.reduce((sum, c) => sum + Number(c.price), 0); 995 982 996 983 await tx … … 1022 1009 if(!build || build.isApproved) return null; 1023 1010 1024 const [existing] = await tx 1025 .select({ 1026 quantity: buildComponentsTable.numComponents 1027 }) 1028 .from(buildComponentsTable) 1011 const result = await tx 1012 .delete(buildComponentsTable) 1029 1013 .where( 1030 1014 and( … … 1032 1016 eq(buildComponentsTable.componentId, componentId) 1033 1017 ) 1034 ) 1035 .limit(1); 1036 1037 if (!existing) return null; 1038 1039 if (existing.quantity > 1) { 1040 await tx 1041 .update(buildComponentsTable) 1042 .set({ 1043 numComponents: sql`${buildComponentsTable.numComponents} - 1` 1044 }) 1045 .where( 1046 and( 1047 eq(buildComponentsTable.buildId, buildId), 1048 eq(buildComponentsTable.componentId, componentId) 1049 ) 1050 ); 1051 } else { 1052 await tx 1053 .delete(buildComponentsTable) 1054 .where( 1055 and( 1056 eq(buildComponentsTable.buildId, buildId), 1057 eq(buildComponentsTable.componentId, componentId) 1058 ) 1059 ); 1060 } 1018 ); 1019 1020 if(result.rowCount === 0) return null; 1061 1021 1062 1022 const buildComponents = await tx 1063 1023 .select({ 1064 1024 price: componentsTable.price, 1065 quantity: buildComponentsTable.numComponents1066 1025 }) 1067 1026 .from(buildComponentsTable) … … 1074 1033 ); 1075 1034 1076 const totalPrice = buildComponents.reduce((sum, c) => 1077 sum + (Number(c.price) * c.quantity), 0 1078 ); 1035 const totalPrice = buildComponents.reduce((sum, c) => sum + Number(c.price), 0); 1079 1036 1080 1037 await tx … … 1087 1044 ); 1088 1045 1089 return componentId;1046 return result; 1090 1047 }) 1091 1048 } -
database/drizzle/schema/builds.ts
ra744c90 r87b79bc 17 17 18 18 export const buildComponentsTable = pgTable("build_component", { 19 id: serial("id").primaryKey(), 19 20 buildId: integer("build_id") 20 21 .notNull() … … 23 24 .notNull() 24 25 .references(() => componentsTable.id, { onDelete: "cascade", onUpdate: "cascade" }), 25 numComponents: integer("num_components")26 .notNull()27 .default(1),28 26 }, 29 (t) => ({30 pk: primaryKey({ columns: [t.buildId, t.componentId] }),31 }),32 27 ); 33 28 -
database/migrations/meta/0000_snapshot.json
ra744c90 r87b79bc 1 1 { 2 "id": " d1ab4ce8-e387-4d74-8d5b-511fdbe0a032",2 "id": "779a3882-651b-446d-8967-3728aeea2888", 3 3 "prevId": "00000000-0000-0000-0000-000000000000", 4 4 "version": "7", … … 9 9 "schema": "", 10 10 "columns": { 11 "id": { 12 "name": "id", 13 "type": "serial", 14 "primaryKey": true, 15 "notNull": true 16 }, 11 17 "build_id": { 12 18 "name": "build_id", … … 20 26 "primaryKey": false, 21 27 "notNull": true 22 },23 "num_components": {24 "name": "num_components",25 "type": "integer",26 "primaryKey": false,27 "notNull": true,28 "default": 129 28 } 30 29 }, … … 58 57 } 59 58 }, 60 "compositePrimaryKeys": { 61 "build_component_build_id_component_id_pk": { 62 "name": "build_component_build_id_component_id_pk", 63 "columns": [ 64 "build_id", 65 "component_id" 66 ] 67 } 68 }, 59 "compositePrimaryKeys": {}, 69 60 "uniqueConstraints": {}, 70 61 "policies": {}, -
database/migrations/meta/_journal.json
ra744c90 r87b79bc 6 6 "idx": 0, 7 7 "version": "7", 8 "when": 1769 598141213,9 "tag": "0000_ shallow_darkhawk",8 "when": 1769188258136, 9 "tag": "0000_regular_kulan_gath", 10 10 "breakpoints": true 11 11 }
Note:
See TracChangeset
for help on using the changeset viewer.
