feat: make Kafka projector the Workbench realtime authority

This commit is contained in:
root
2026-07-10 05:23:03 +02:00
parent a685be0b78
commit ce83ffdf49
74 changed files with 7746 additions and 9863 deletions
+21 -11
View File
@@ -4,7 +4,8 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
import {
CLOUD_CORE_MIGRATION_ID,
CLOUD_CORE_MIGRATIONS,
CLOUD_RUNTIME_DURABLE_MIGRATION_ID,
CLOUD_RUNTIME_DURABLE_ADAPTER_SCHEMA_VERSION,
CLOUD_RUNTIME_DURABLE_MIGRATION_TABLE,
CLOUD_RUNTIME_DURABLE_MIGRATION_TABLE_COLUMNS,
@@ -25,7 +26,8 @@ import { ENVIRONMENT_DEV } from "../../internal/protocol/index.mjs";
import { ensureNotRepoReportsPath, tempReportPath } from "./report-paths.mjs";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const migrationPath = "internal/db/migrations/0001_cloud_core_skeleton.sql";
const migrationPaths = CLOUD_CORE_MIGRATIONS.map((migration) => migration.path);
const latestMigrationPath = migrationPaths.at(-1);
const defaultReportPath = tempReportPath("dev-runtime-migration-report.json");
const issue = "pikasTech/HWLAB#164";
@@ -55,7 +57,11 @@ export async function buildDevRuntimeMigrationReport(args = {}, options = {}) {
const env = options.env ?? process.env;
const now = options.now ?? (() => new Date().toISOString());
const root = options.repoRoot ?? repoRoot;
const sql = await readFile(path.join(root, migrationPath), "utf8");
const migrationSources = await Promise.all(migrationPaths.map(async (migrationPath) => ({
path: migrationPath,
sql: await readFile(path.join(root, migrationPath), "utf8")
})));
const sql = migrationSources.map((migration) => migration.sql).join("\n");
const sourceCheck = validateMigrationSource(sql);
const db = summarizeDbEnv(env);
const report = {
@@ -71,8 +77,9 @@ export async function buildDevRuntimeMigrationReport(args = {}, options = {}) {
dbEndpointAuthority: DEV_DB_ENV_CONTRACT.endpointAuthority.source
},
migration: {
id: CLOUD_CORE_MIGRATION_ID,
path: migrationPath,
id: CLOUD_RUNTIME_DURABLE_MIGRATION_ID,
path: latestMigrationPath,
paths: migrationPaths,
sha256: sha256(sql),
schemaVersion: CLOUD_RUNTIME_DURABLE_ADAPTER_SCHEMA_VERSION,
ledgerTable: CLOUD_RUNTIME_DURABLE_MIGRATION_TABLE,
@@ -195,7 +202,9 @@ export function validateMigrationSource(sql) {
continue;
}
for (const column of columns) {
if (!new RegExp(`\\b${column}\\b`, "u").test(tableMatch[1])) {
const created = new RegExp(`\\b${column}\\b`, "u").test(tableMatch[1]);
const added = new RegExp(`ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${column}\\b`, "u").test(sql);
if (!created && !added) {
missing.push(`column:${table}.${column}`);
}
}
@@ -214,8 +223,8 @@ export function validateMigrationSource(sql) {
}
}
if (!new RegExp(`'${CLOUD_CORE_MIGRATION_ID}'`, "u").test(sql)) {
missing.push(`ledger-id:${CLOUD_CORE_MIGRATION_ID}`);
if (!new RegExp(`'${CLOUD_RUNTIME_DURABLE_MIGRATION_ID}'`, "u").test(sql)) {
missing.push(`ledger-id:${CLOUD_RUNTIME_DURABLE_MIGRATION_ID}`);
}
if (!new RegExp(`'${CLOUD_RUNTIME_DURABLE_ADAPTER_SCHEMA_VERSION}'`, "u").test(sql)) {
missing.push(`schema-version:${CLOUD_RUNTIME_DURABLE_ADAPTER_SCHEMA_VERSION}`);
@@ -227,8 +236,9 @@ export function validateMigrationSource(sql) {
return {
ready: missing.length === 0,
checked: true,
migrationPath,
requiredMigrationId: CLOUD_CORE_MIGRATION_ID,
migrationPath: latestMigrationPath,
migrationPaths,
requiredMigrationId: CLOUD_RUNTIME_DURABLE_MIGRATION_ID,
requiredSchemaVersion: CLOUD_RUNTIME_DURABLE_ADAPTER_SCHEMA_VERSION,
requiredTables: Object.keys(CLOUD_RUNTIME_DURABLE_TABLE_COLUMNS),
requiredLedgerTable: CLOUD_RUNTIME_DURABLE_MIGRATION_TABLE,
@@ -456,7 +466,7 @@ function summarizeRuntimeMigration(migration = {}) {
checked: Boolean(migration.checked),
ready: Boolean(migration.ready),
table: migration.table ?? CLOUD_RUNTIME_DURABLE_MIGRATION_TABLE,
requiredMigrationId: migration.requiredMigrationId ?? CLOUD_CORE_MIGRATION_ID,
requiredMigrationId: migration.requiredMigrationId ?? CLOUD_RUNTIME_DURABLE_MIGRATION_ID,
requiredSchemaVersion: migration.requiredSchemaVersion ?? CLOUD_RUNTIME_DURABLE_ADAPTER_SCHEMA_VERSION,
appliedMigrationId: migration.appliedMigrationId ?? null,
appliedSchemaVersion: migration.appliedSchemaVersion ?? null,