Restructure components into types + instances
Deploy to LXC / deploy (push) Successful in 29s

Components are now split into two concepts:
- Component (type definition): title, componentType, brand, partNumber,
  specs, notes, default condition/firmware/location
- Component Instance (individual physical unit): serialNumber, condition,
  firmwareVersion, notes, currentDeviceId, locationId

Key changes:
- New component_instances table with per-unit tracking
- Component list shows cards with total/installed/available counts
- Component detail page shows all instances with inline edit
- Add instances: bulk (quantity) or one at a time
- Each instance has install/remove/edit/delete actions
- Installation log now references instances, not components
- Device detail shows installed instances with instance numbers
- Dashboard and sidebar counts use instance totals
- Location pages show instances, not component types
- Labels show component type info (serial is per-instance)

IMPORTANT: Run db:push on the server after deploy to create the new
tables and columns. Existing component data will need manual migration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 14:41:06 +07:00
parent bb8a96d281
commit 5c4595ed16
26 changed files with 553 additions and 373 deletions
+6 -4
View File
@@ -1,6 +1,6 @@
import type { PageServerLoad } from './$types';
import { db } from '$lib/server/db/index.js';
import { devices, components, installationLog } from '$lib/server/db/schema.js';
import { devices, components, componentInstances, installationLog } from '$lib/server/db/schema.js';
import { count, eq, or, and, desc, sql } from 'drizzle-orm';
export const load: PageServerLoad = async () => {
@@ -16,7 +16,7 @@ export const load: PageServerLoad = async () => {
.select({ value: count() })
.from(devices)
.where(and(active, eq(devices.category, 'Audio Equipment')));
const [totalComponents] = await db.select({ value: count() }).from(components);
const [totalComponents] = await db.select({ value: count() }).from(componentInstances);
// Condition breakdown
const conditionBreakdown = await db
@@ -33,13 +33,15 @@ export const load: PageServerLoad = async () => {
.select({
action: installationLog.action,
performedAt: installationLog.performedAt,
componentId: installationLog.componentId,
instanceId: installationLog.instanceId,
instanceNumber: componentInstances.instanceNumber,
deviceId: installationLog.deviceId,
componentTitle: components.title,
deviceTitle: devices.title
})
.from(installationLog)
.innerJoin(components, eq(installationLog.componentId, components.id))
.innerJoin(componentInstances, eq(installationLog.instanceId, componentInstances.id))
.innerJoin(components, eq(componentInstances.componentId, components.id))
.innerJoin(devices, eq(installationLog.deviceId, devices.id))
.orderBy(desc(installationLog.performedAt))
.limit(10);