from __future__ import annotations from dataclasses import dataclass @dataclass(frozen=True, slots=True) class ForeignKey: field: str target_table: str target_field: str nullable: bool = False @dataclass(frozen=True, slots=True) class TableSpec: name: str path: str primary_key: str required: tuple[str, ...] foreign_keys: tuple[ForeignKey, ...] = () def _spec(name: str, path: str, pk: str, required: tuple[str, ...], *fks: ForeignKey) -> TableSpec: return TableSpec(name, path, pk, required, tuple(fks)) TABLE_SPECS: dict[str, TableSpec] = { spec.name: spec for spec in ( _spec("organizations", "master/organizations.csv", "organizationId", ("organizationId", "name", "datasetType")), _spec("workshops", "master/workshops.csv", "workshopId", ("workshopId", "organizationId", "name"), ForeignKey("organizationId", "organizations", "organizationId")), _spec("workcenters", "master/workcenters.csv", "workcenterId", ("workcenterId", "workshopId", "name"), ForeignKey("workshopId", "workshops", "workshopId")), _spec("resources", "master/resources.csv", "resourceId", ("resourceId", "workcenterId", "resourceType", "exclusive", "capacity"), ForeignKey("workcenterId", "workcenters", "workcenterId")), _spec("resource-groups", "master/resource-groups.csv", "resourceGroupId", ("resourceGroupId", "name", "resourceType")), _spec("calendars", "master/calendars.csv", "calendarId", ("calendarId", "calendarType", "timezone")), _spec("shifts", "master/shifts.csv", "shiftId", ("shiftId", "calendarId", "startTime", "endTime"), ForeignKey("calendarId", "calendars", "calendarId")), _spec("skills", "master/skills.csv", "skillCode", ("skillCode", "name", "qualificationRequired")), _spec("teams", "master/teams.csv", "teamId", ("teamId", "workshopId", "crewSize", "skillCodes"), ForeignKey("workshopId", "workshops", "workshopId")), _spec("employees", "master/employees.csv", "employeeId", ("employeeId", "teamId", "name", "skillCodes"), ForeignKey("teamId", "teams", "teamId")), _spec("suppliers", "master/suppliers.csv", "supplierId", ("supplierId", "name", "supplierType", "monthlyCapacity")), _spec("warehouses", "master/warehouses.csv", "warehouseId", ("warehouseId", "name", "warehouseType")), _spec("locations", "master/locations.csv", "locationId", ("locationId", "warehouseId", "locationType"), ForeignKey("warehouseId", "warehouses", "warehouseId", True)), _spec("contracts", "projects/contracts.csv", "contractId", ("contractId", "projectId", "shipOwner", "effectiveDate", "deliveryDate")), _spec("ship-projects", "projects/ship-projects.csv", "projectId", ("projectId", "shipType", "priority", "plannedStart", "deliveryTarget")), _spec("milestones", "projects/milestones.csv", "milestoneId", ("milestoneId", "projectId", "milestoneCode", "plannedDate"), ForeignKey("projectId", "ship-projects", "projectId")), _spec("wbs", "projects/wbs.csv", "wbsId", ("wbsId", "projectId", "wbsType", "name"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("parentWbsId", "wbs", "wbsId", True)), _spec("blocks", "projects/blocks.csv", "blockId", ("blockId", "projectId", "blockType", "weightT", "lengthM", "widthM", "heightM"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("parentBlockId", "blocks", "blockId", True)), _spec("zones", "projects/zones.csv", "zoneId", ("zoneId", "projectId", "zoneType", "name"), ForeignKey("projectId", "ship-projects", "projectId")), _spec("work-packages", "projects/work-packages.csv", "workPackageId", ("workPackageId", "projectId", "wbsId", "blockId", "zoneId", "needDate"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("wbsId", "wbs", "wbsId"), ForeignKey("blockId", "blocks", "blockId"), ForeignKey("zoneId", "zones", "zoneId")), _spec("drawings", "engineering/drawings.csv", "drawingId", ("drawingId", "projectId", "drawingType", "releaseStatus"), ForeignKey("projectId", "ship-projects", "projectId")), _spec("ebom", "engineering/ebom.csv", "bomLineId", ("bomLineId", "projectId", "parentMaterialId", "materialId", "quantity"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("materialId", "materials", "materialId"), ForeignKey("parentMaterialId", "materials", "materialId", True)), _spec("pbom", "engineering/pbom.csv", "bomLineId", ("bomLineId", "projectId", "workPackageId", "materialId", "quantity"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("workPackageId", "work-packages", "workPackageId"), ForeignKey("materialId", "materials", "materialId")), _spec("mbom", "engineering/mbom.csv", "bomLineId", ("bomLineId", "projectId", "productionOrderId", "materialId", "quantity"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("productionOrderId", "production-orders", "productionOrderId", True), ForeignKey("materialId", "materials", "materialId")), _spec("routings", "engineering/routings.csv", "routingId", ("routingId", "routingCode", "productGroup", "version")), _spec("routing-operations", "engineering/routing-operations.csv", "routingOperationId", ("routingOperationId", "routingId", "sequence", "operationCode", "resourceType", "requiredSkillCodes"), ForeignKey("routingId", "routings", "routingId")), _spec("engineering-releases", "engineering/engineering-releases.csv", "releaseId", ("releaseId", "projectId", "releaseType", "status", "effectiveDate"), ForeignKey("projectId", "ship-projects", "projectId")), _spec("materials", "materials/materials.csv", "materialId", ("materialId", "materialCode", "materialGroup", "sourcingMode", "fulfillmentMode", "unit")), _spec("inventory", "materials/inventory.csv", "inventoryId", ("inventoryId", "materialId", "warehouseId", "quantity", "qualityStatus"), ForeignKey("materialId", "materials", "materialId"), ForeignKey("warehouseId", "warehouses", "warehouseId")), _spec("inventory-allocations", "materials/inventory-allocations.csv", "allocationId", ("allocationId", "inventoryId", "projectId", "quantity", "releaseAllowed"), ForeignKey("inventoryId", "inventory", "inventoryId"), ForeignKey("projectId", "ship-projects", "projectId")), _spec("substitutes", "materials/substitutes.csv", "substituteId", ("substituteId", "materialId", "substituteMaterialId", "conversionFactor"), ForeignKey("materialId", "materials", "materialId"), ForeignKey("substituteMaterialId", "materials", "materialId")), _spec("planned-receipts", "materials/planned-receipts.csv", "plannedReceiptId", ("plannedReceiptId", "materialId", "supplierId", "quantity", "availableDate", "trusted"), ForeignKey("materialId", "materials", "materialId"), ForeignKey("supplierId", "suppliers", "supplierId", True)), _spec("material-requirements", "materials/material-requirements.csv", "requirementId", ("requirementId", "projectId", "wbsId", "bomLineId", "materialId", "grossRequirement", "netRequirement", "needDate"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("wbsId", "wbs", "wbsId"), ForeignKey("materialId", "materials", "materialId")), _spec("kit-readiness", "materials/kit-readiness.csv", "kitReadinessId", ("kitReadinessId", "workPackageId", "readinessPercent", "readyDate", "shortageCount"), ForeignKey("workPackageId", "work-packages", "workPackageId")), _spec("production-orders", "planning/production-orders.csv", "productionOrderId", ("productionOrderId", "projectId", "wbsId", "workPackageId", "routingId", "quantity", "needDate"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("wbsId", "wbs", "wbsId"), ForeignKey("workPackageId", "work-packages", "workPackageId"), ForeignKey("routingId", "routings", "routingId")), _spec("work-orders", "planning/work-orders.csv", "workOrderId", ("workOrderId", "productionOrderId", "projectId", "status", "materialReadyAt"), ForeignKey("productionOrderId", "production-orders", "productionOrderId"), ForeignKey("projectId", "ship-projects", "projectId")), _spec("operations", "planning/operations.csv", "operationId", ("operationId", "workOrderId", "sequence", "operationCode", "durationHours", "requiredResourceType", "requiredSkillCodes"), ForeignKey("workOrderId", "work-orders", "workOrderId")), _spec("purchase-suggestions", "planning/purchase-suggestions.csv", "purchaseSuggestionId", ("purchaseSuggestionId", "projectId", "wbsId", "requirementId", "materialId", "supplierId", "grossRequirement", "netRequirement", "needDate"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("wbsId", "wbs", "wbsId"), ForeignKey("requirementId", "material-requirements", "requirementId"), ForeignKey("materialId", "materials", "materialId"), ForeignKey("supplierId", "suppliers", "supplierId")), _spec("outsource-suggestions", "planning/outsource-suggestions.csv", "outsourceSuggestionId", ("outsourceSuggestionId", "outsourceOrderId", "projectId", "wbsId", "materialId", "operationId", "supplierId", "sendDate", "expectedReturnDate", "transportOutboundDays", "processDays", "inspectionDays", "transportReturnDays", "quantity", "status", "qualityStatus", "previousOperationId", "nextOperationId", "requiredCertificate", "riskLevel"), ForeignKey("projectId", "ship-projects", "projectId"), ForeignKey("wbsId", "wbs", "wbsId"), ForeignKey("materialId", "materials", "materialId"), ForeignKey("operationId", "operations", "operationId"), ForeignKey("supplierId", "suppliers", "supplierId")), _spec("capacity-demands", "planning/capacity-demands.csv", "capacityDemandId", ("capacityDemandId", "operationId", "resourceType", "demandHours"), ForeignKey("operationId", "operations", "operationId")), _spec("schedule-versions", "planning/schedule-versions.csv", "scheduleVersionId", ("scheduleVersionId", "scenarioId", "versionNo", "solveStatus", "algorithm", "inputDigest")), _spec("schedule-slots", "planning/schedule-slots.csv", "scheduleSlotId", ("scheduleSlotId", "scheduleVersionId", "operationId", "resourceId", "teamId", "start", "end", "explanation", "evidenceRefs"), ForeignKey("scheduleVersionId", "schedule-versions", "scheduleVersionId"), ForeignKey("operationId", "operations", "operationId"), ForeignKey("resourceId", "resources", "resourceId"), ForeignKey("teamId", "teams", "teamId")), _spec("resource-loads", "planning/resource-loads.csv", "resourceLoadId", ("resourceLoadId", "scheduleVersionId", "resourceId", "bucketStart", "loadHours", "capacityHours", "utilization"), ForeignKey("scheduleVersionId", "schedule-versions", "scheduleVersionId"), ForeignKey("resourceId", "resources", "resourceId")), _spec("conflicts", "planning/conflicts.csv", "conflictId", ("conflictId", "scenarioId", "conflictType", "severity", "detected", "expected", "resolutionStatus")), _spec("kpis", "planning/kpis.csv", "kpiId", ("kpiId", "scheduleVersionId", "kpiCode", "value", "unit"), ForeignKey("scheduleVersionId", "schedule-versions", "scheduleVersionId")), _spec("mes-orders", "execution/mes-orders.csv", "mesOrderId", ("mesOrderId", "workOrderId", "dispatchStatus", "frozen"), ForeignKey("workOrderId", "work-orders", "workOrderId")), _spec("operation-reports", "execution/operation-reports.csv", "operationReportId", ("operationReportId", "operationId", "reportStatus", "reportedQuantity"), ForeignKey("operationId", "operations", "operationId")), _spec("material-issues", "execution/material-issues.csv", "materialIssueId", ("materialIssueId", "workOrderId", "materialId", "quantity"), ForeignKey("workOrderId", "work-orders", "workOrderId"), ForeignKey("materialId", "materials", "materialId")), _spec("quality-inspections", "execution/quality-inspections.csv", "inspectionId", ("inspectionId", "operationId", "inspectionType", "holdPoint", "status"), ForeignKey("operationId", "operations", "operationId")), _spec("nonconformities", "execution/nonconformities.csv", "nonconformityId", ("nonconformityId", "inspectionId", "status", "severity"), ForeignKey("inspectionId", "quality-inspections", "inspectionId")), _spec("rework-orders", "execution/rework-orders.csv", "reworkOrderId", ("reworkOrderId", "nonconformityId", "operationId", "status", "reinspectionRequired"), ForeignKey("nonconformityId", "nonconformities", "nonconformityId"), ForeignKey("operationId", "operations", "operationId")), ) } TABLE_ORDER: tuple[str, ...] = tuple(TABLE_SPECS) def table_paths() -> tuple[str, ...]: return tuple(spec.path for spec in TABLE_SPECS.values())