Files
pikasTech-HWLAB/internal/db/schema.mjs
T
2026-05-22 22:44:41 +00:00

88 lines
2.1 KiB
JavaScript

import { TABLES } from "../protocol/index.mjs";
export const CLOUD_CORE_MIGRATION_ID = "0001_cloud_core_skeleton";
export const CLOUD_RUNTIME_DURABLE_ADAPTER_SCHEMA_VERSION = "runtime-durable-postgres-v1";
export const FROZEN_CLOUD_CORE_TABLES = Object.freeze([...TABLES]);
export const CLOUD_RUNTIME_DURABLE_TABLE_COLUMNS = Object.freeze({
gateway_sessions: Object.freeze([
"id",
"project_id",
"gateway_service_id",
"status",
"started_at",
"ended_at",
"gateway_session_json"
]),
box_resources: Object.freeze([
"id",
"project_id",
"gateway_session_id",
"resource_state",
"labels_json",
"resource_json",
"updated_at"
]),
box_capabilities: Object.freeze([
"id",
"box_resource_id",
"capability_type",
"capability_json",
"updated_at"
]),
hardware_operations: Object.freeze([
"id",
"project_id",
"requested_by",
"operation_type",
"operation_json",
"status",
"requested_at",
"updated_at"
]),
audit_events: Object.freeze([
"id",
"request_id",
"actor",
"source",
"operation",
"target",
"result",
"timestamp",
"event_json"
]),
evidence_records: Object.freeze([
"id",
"project_id",
"operation_id",
"evidence_type",
"uri",
"metadata_json",
"created_at"
])
});
export const CLOUD_CORE_MIGRATIONS = Object.freeze([
{
id: CLOUD_CORE_MIGRATION_ID,
path: "internal/db/migrations/0001_cloud_core_skeleton.sql",
tables: FROZEN_CLOUD_CORE_TABLES,
connectsToDatabase: false,
runtimeDurableAdapterSchemaVersion: CLOUD_RUNTIME_DURABLE_ADAPTER_SCHEMA_VERSION
}
]);
export function assertFrozenCloudCoreTables(tables = FROZEN_CLOUD_CORE_TABLES) {
const missing = TABLES.filter((table) => !tables.includes(table));
if (missing.length > 0) {
throw new Error(`cloud core schema is missing frozen tables: ${missing.join(", ")}`);
}
}
export function requiredRuntimeDurableColumns() {
return Object.entries(CLOUD_RUNTIME_DURABLE_TABLE_COLUMNS).flatMap(([table, columns]) =>
columns.map((column) => `${table}.${column}`)
);
}