Record project continuation changes

This commit is contained in:
2026-05-12 21:02:29 +03:00
parent 3059d1d7a3
commit 8f69d53193
339 changed files with 101111 additions and 1769 deletions
@@ -0,0 +1,8 @@
DROP INDEX IF EXISTS node_update_status_reports_latest_idx;
DROP INDEX IF EXISTS release_artifacts_match_idx;
DROP INDEX IF EXISTS release_versions_lookup_idx;
DROP TABLE IF EXISTS node_update_status_reports;
DROP TABLE IF EXISTS node_update_desired_policies;
DROP TABLE IF EXISTS release_artifacts;
DROP TABLE IF EXISTS release_versions;
@@ -0,0 +1,74 @@
CREATE TABLE IF NOT EXISTS release_versions (
id UUID PRIMARY KEY,
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
product TEXT NOT NULL,
version TEXT NOT NULL,
channel TEXT NOT NULL DEFAULT 'dev',
status TEXT NOT NULL DEFAULT 'active',
compatibility JSONB NOT NULL DEFAULT '{}'::jsonb,
changelog TEXT,
created_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
authority_payload JSONB NOT NULL DEFAULT '{}'::jsonb,
authority_signature JSONB NOT NULL DEFAULT '{}'::jsonb,
UNIQUE (cluster_id, product, version, channel)
);
CREATE TABLE IF NOT EXISTS release_artifacts (
id UUID PRIMARY KEY,
release_id UUID NOT NULL REFERENCES release_versions(id) ON DELETE CASCADE,
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
product TEXT NOT NULL,
version TEXT NOT NULL,
os TEXT NOT NULL,
arch TEXT NOT NULL,
install_type TEXT NOT NULL,
kind TEXT NOT NULL,
url TEXT NOT NULL,
sha256 TEXT NOT NULL,
size_bytes BIGINT NOT NULL DEFAULT 0,
signature TEXT,
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (release_id, os, arch, install_type, kind)
);
CREATE TABLE IF NOT EXISTS node_update_desired_policies (
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
product TEXT NOT NULL,
channel TEXT NOT NULL DEFAULT 'dev',
target_version TEXT,
strategy TEXT NOT NULL DEFAULT 'manual',
enabled BOOLEAN NOT NULL DEFAULT false,
rollback_allowed BOOLEAN NOT NULL DEFAULT true,
health_window_seconds INTEGER NOT NULL DEFAULT 180,
updated_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (cluster_id, node_id, product)
);
CREATE TABLE IF NOT EXISTS node_update_status_reports (
id UUID PRIMARY KEY,
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
product TEXT NOT NULL,
current_version TEXT NOT NULL DEFAULT '',
target_version TEXT NOT NULL DEFAULT '',
phase TEXT NOT NULL,
status TEXT NOT NULL,
attempt_id TEXT NOT NULL DEFAULT '',
error_message TEXT,
rollback_version TEXT,
payload JSONB NOT NULL DEFAULT '{}'::jsonb,
observed_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS release_versions_lookup_idx
ON release_versions (cluster_id, product, channel, status, created_at DESC);
CREATE INDEX IF NOT EXISTS release_artifacts_match_idx
ON release_artifacts (release_id, os, arch, install_type);
CREATE INDEX IF NOT EXISTS node_update_status_reports_latest_idx
ON node_update_status_reports (cluster_id, node_id, product, observed_at DESC);
@@ -0,0 +1,26 @@
DROP VIEW IF EXISTS cluster_admin_summaries;
CREATE VIEW cluster_admin_summaries AS
SELECT
c.id AS cluster_id,
c.slug,
c.name,
c.status,
c.region,
COALESCE(cas.authority_state, 'authoritative') AS authority_state,
COALESCE(cas.mutation_mode, 'normal') AS mutation_mode,
ca.key_algorithm AS cluster_key_algorithm,
ca.public_key_fingerprint AS cluster_key_fingerprint,
COUNT(DISTINCT cm.node_id) AS node_count,
COUNT(DISTINCT CASE WHEN n.health_status = 'healthy' THEN n.id END) AS healthy_node_count,
COUNT(DISTINCT CASE WHEN njr.status = 'pending' THEN njr.id END) AS pending_join_count,
COUNT(DISTINCT nra.id) AS active_role_assignment_count,
MAX(n.last_seen_at) AS last_node_seen_at
FROM clusters c
LEFT JOIN cluster_authority_states cas ON cas.cluster_id = c.id
LEFT JOIN cluster_authorities ca ON ca.cluster_id = c.id
LEFT JOIN cluster_memberships cm ON cm.cluster_id = c.id
LEFT JOIN nodes n ON n.id = cm.node_id
LEFT JOIN node_join_requests njr ON njr.cluster_id = c.id
LEFT JOIN node_role_assignments nra ON nra.cluster_id = c.id AND nra.status = 'active'
GROUP BY c.id, c.slug, c.name, c.status, c.region, cas.authority_state, cas.mutation_mode, ca.key_algorithm, ca.public_key_fingerprint;
@@ -0,0 +1,29 @@
DROP VIEW IF EXISTS cluster_admin_summaries;
CREATE VIEW cluster_admin_summaries AS
SELECT
c.id AS cluster_id,
c.slug,
c.name,
c.status,
c.region,
COALESCE(cas.authority_state, 'authoritative') AS authority_state,
COALESCE(cas.mutation_mode, 'normal') AS mutation_mode,
ca.key_algorithm AS cluster_key_algorithm,
ca.public_key_fingerprint AS cluster_key_fingerprint,
COUNT(DISTINCT cm.node_id) AS node_count,
COUNT(DISTINCT CASE
WHEN n.health_status = 'healthy'
AND n.last_seen_at >= NOW() - '1 minute'::interval THEN n.id
END) AS healthy_node_count,
COUNT(DISTINCT CASE WHEN njr.status = 'pending' THEN njr.id END) AS pending_join_count,
COUNT(DISTINCT nra.id) AS active_role_assignment_count,
MAX(n.last_seen_at) AS last_node_seen_at
FROM clusters c
LEFT JOIN cluster_authority_states cas ON cas.cluster_id = c.id
LEFT JOIN cluster_authorities ca ON ca.cluster_id = c.id
LEFT JOIN cluster_memberships cm ON cm.cluster_id = c.id
LEFT JOIN nodes n ON n.id = cm.node_id
LEFT JOIN node_join_requests njr ON njr.cluster_id = c.id
LEFT JOIN node_role_assignments nra ON nra.cluster_id = c.id AND nra.status = 'active'
GROUP BY c.id, c.slug, c.name, c.status, c.region, cas.authority_state, cas.mutation_mode, ca.key_algorithm, ca.public_key_fingerprint;
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS fabric_service_channel_route_feedback_latest;
DROP TABLE IF EXISTS fabric_service_channel_route_feedback_observations;
@@ -0,0 +1,45 @@
CREATE TABLE IF NOT EXISTS fabric_service_channel_route_feedback_observations (
id UUID PRIMARY KEY,
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
reporter_node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
route_id TEXT NOT NULL,
service_class TEXT NOT NULL,
feedback_status TEXT NOT NULL,
score_adjustment INTEGER NOT NULL DEFAULT 0,
reasons TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
last_error TEXT NOT NULL DEFAULT '',
consecutive_failures INTEGER NOT NULL DEFAULT 0,
stall_count INTEGER NOT NULL DEFAULT 0,
last_send_duration_ms BIGINT NOT NULL DEFAULT 0,
payload JSONB NOT NULL DEFAULT '{}'::JSONB,
observed_at TIMESTAMPTZ NOT NULL,
expires_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_fsc_route_feedback_observed
ON fabric_service_channel_route_feedback_observations (cluster_id, reporter_node_id, service_class, observed_at DESC);
CREATE INDEX IF NOT EXISTS idx_fsc_route_feedback_route
ON fabric_service_channel_route_feedback_observations (cluster_id, route_id, observed_at DESC);
CREATE TABLE IF NOT EXISTS fabric_service_channel_route_feedback_latest (
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
reporter_node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
route_id TEXT NOT NULL,
observation_id UUID NOT NULL REFERENCES fabric_service_channel_route_feedback_observations(id) ON DELETE CASCADE,
service_class TEXT NOT NULL,
feedback_status TEXT NOT NULL,
score_adjustment INTEGER NOT NULL DEFAULT 0,
reasons TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
last_error TEXT NOT NULL DEFAULT '',
consecutive_failures INTEGER NOT NULL DEFAULT 0,
stall_count INTEGER NOT NULL DEFAULT 0,
last_send_duration_ms BIGINT NOT NULL DEFAULT 0,
payload JSONB NOT NULL DEFAULT '{}'::JSONB,
observed_at TIMESTAMPTZ NOT NULL,
expires_at TIMESTAMPTZ NOT NULL,
PRIMARY KEY (cluster_id, reporter_node_id, route_id)
);
CREATE INDEX IF NOT EXISTS idx_fsc_route_feedback_latest_active
ON fabric_service_channel_route_feedback_latest (cluster_id, reporter_node_id, service_class, expires_at DESC);
@@ -0,0 +1 @@
DROP TABLE IF EXISTS fabric_service_channel_route_rebuild_attempts;
@@ -0,0 +1,43 @@
CREATE TABLE IF NOT EXISTS fabric_service_channel_route_rebuild_attempts (
id UUID PRIMARY KEY,
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
reporter_node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
service_class TEXT NOT NULL,
route_id TEXT NOT NULL,
replacement_route_id TEXT NOT NULL DEFAULT '',
rebuild_request_id TEXT NOT NULL,
rebuild_status TEXT NOT NULL,
rebuild_reason TEXT NOT NULL DEFAULT '',
rebuild_attempt INTEGER NOT NULL DEFAULT 0,
decision_source TEXT NOT NULL,
outcome TEXT NOT NULL,
generation TEXT NOT NULL DEFAULT '',
policy_fingerprint TEXT NOT NULL DEFAULT '',
observed_policy_fingerprint TEXT NOT NULL DEFAULT '',
observed_route_generation TEXT NOT NULL DEFAULT '',
effective_route_generation TEXT NOT NULL DEFAULT '',
feedback_status TEXT NOT NULL DEFAULT '',
feedback_score_adjustment INTEGER NOT NULL DEFAULT 0,
feedback_effective_score_adjustment INTEGER NOT NULL DEFAULT 0,
feedback_reasons TEXT[] NOT NULL DEFAULT '{}',
last_error TEXT NOT NULL DEFAULT '',
consecutive_failures INTEGER NOT NULL DEFAULT 0,
stall_count INTEGER NOT NULL DEFAULT 0,
last_send_duration_ms BIGINT NOT NULL DEFAULT 0,
quality_window_sample_count INTEGER NOT NULL DEFAULT 0,
quality_window_failure_count INTEGER NOT NULL DEFAULT 0,
quality_window_drop_count INTEGER NOT NULL DEFAULT 0,
quality_window_slow_count INTEGER NOT NULL DEFAULT 0,
old_hops TEXT[] NOT NULL DEFAULT '{}',
replacement_hops TEXT[] NOT NULL DEFAULT '{}',
payload JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (cluster_id, reporter_node_id, service_class, route_id, rebuild_request_id)
);
CREATE INDEX IF NOT EXISTS idx_fsc_rebuild_attempts_cluster_reporter_updated
ON fabric_service_channel_route_rebuild_attempts (cluster_id, reporter_node_id, updated_at DESC);
CREATE INDEX IF NOT EXISTS idx_fsc_rebuild_attempts_cluster_route_updated
ON fabric_service_channel_route_rebuild_attempts (cluster_id, route_id, updated_at DESC);
@@ -0,0 +1 @@
DROP TABLE IF EXISTS fabric_service_channel_rebuild_alert_silences;
@@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS fabric_service_channel_rebuild_alert_silences (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
reporter_node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
route_id TEXT NOT NULL,
guard_status TEXT NOT NULL,
generation TEXT NOT NULL DEFAULT '',
reason TEXT NOT NULL DEFAULT '',
created_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
expires_at TIMESTAMPTZ NOT NULL,
payload JSONB NOT NULL DEFAULT '{}'::jsonb,
UNIQUE (cluster_id, reporter_node_id, route_id, guard_status, generation)
);
CREATE INDEX IF NOT EXISTS idx_fsc_rebuild_alert_silences_active
ON fabric_service_channel_rebuild_alert_silences (cluster_id, expires_at DESC);
@@ -0,0 +1,23 @@
DROP INDEX IF EXISTS idx_fsc_rebuild_attempts_cluster_guard_updated;
ALTER TABLE fabric_service_channel_route_rebuild_attempts
DROP COLUMN IF EXISTS correlation_snapshot_at,
DROP COLUMN IF EXISTS correlation_timeline,
DROP COLUMN IF EXISTS guard_traffic_deadline_seconds,
DROP COLUMN IF EXISTS guard_transition_deadline_seconds,
DROP COLUMN IF EXISTS guard_reason,
DROP COLUMN IF EXISTS guard_severity,
DROP COLUMN IF EXISTS guard_status,
DROP COLUMN IF EXISTS post_rebuild_send_flow_dropped,
DROP COLUMN IF EXISTS post_rebuild_send_flow_packets,
DROP COLUMN IF EXISTS post_rebuild_send_failures,
DROP COLUMN IF EXISTS post_rebuild_send_packets,
DROP COLUMN IF EXISTS post_rebuild_selected_route_id,
DROP COLUMN IF EXISTS node_route_generation_matched,
DROP COLUMN IF EXISTS node_route_generation_withdrawn_at,
DROP COLUMN IF EXISTS node_route_generation_applied_at,
DROP COLUMN IF EXISTS node_route_generation_status,
DROP COLUMN IF EXISTS node_transition_matched,
DROP COLUMN IF EXISTS node_transition_observed_at,
DROP COLUMN IF EXISTS node_transition_generation,
DROP COLUMN IF EXISTS node_transition_status;
@@ -0,0 +1,24 @@
ALTER TABLE fabric_service_channel_route_rebuild_attempts
ADD COLUMN IF NOT EXISTS node_transition_status TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS node_transition_generation TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS node_transition_observed_at TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS node_transition_matched BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS node_route_generation_status TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS node_route_generation_applied_at TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS node_route_generation_withdrawn_at TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS node_route_generation_matched BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS post_rebuild_selected_route_id TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS post_rebuild_send_packets BIGINT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS post_rebuild_send_failures BIGINT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS post_rebuild_send_flow_packets BIGINT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS post_rebuild_send_flow_dropped BIGINT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS guard_status TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS guard_severity TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS guard_reason TEXT NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS guard_transition_deadline_seconds BIGINT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS guard_traffic_deadline_seconds BIGINT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS correlation_timeline JSONB NOT NULL DEFAULT '[]'::jsonb,
ADD COLUMN IF NOT EXISTS correlation_snapshot_at TIMESTAMPTZ;
CREATE INDEX IF NOT EXISTS idx_fsc_rebuild_attempts_cluster_guard_updated
ON fabric_service_channel_route_rebuild_attempts (cluster_id, guard_severity, guard_status, updated_at DESC);
@@ -0,0 +1 @@
DROP TABLE IF EXISTS fabric_service_channel_leases;
@@ -0,0 +1,19 @@
CREATE TABLE IF NOT EXISTS fabric_service_channel_leases (
cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
channel_id UUID NOT NULL,
token_hash TEXT NOT NULL,
resource_id TEXT NOT NULL DEFAULT '',
service_class TEXT NOT NULL,
selected_entry_node_id UUID NULL REFERENCES nodes(id) ON DELETE SET NULL,
expires_at TIMESTAMPTZ NOT NULL,
lease JSONB NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (cluster_id, channel_id)
);
CREATE INDEX IF NOT EXISTS fabric_service_channel_leases_cluster_expires_idx
ON fabric_service_channel_leases(cluster_id, expires_at);
CREATE INDEX IF NOT EXISTS fabric_service_channel_leases_entry_idx
ON fabric_service_channel_leases(cluster_id, selected_entry_node_id, expires_at);
@@ -0,0 +1,17 @@
DELETE FROM mesh_qos_policies
WHERE service_class IN ('remote_workspace', 'video')
AND metadata->>'fabric_service_channel' = 'true';
ALTER TABLE mesh_route_intents
DROP CONSTRAINT IF EXISTS mesh_route_intents_service_class_check;
ALTER TABLE mesh_route_intents
ADD CONSTRAINT mesh_route_intents_service_class_check
CHECK (service_class IN ('input', 'control', 'synthetic', 'render', 'clipboard', 'file_transfer', 'vpn_packets', 'telemetry'));
ALTER TABLE mesh_qos_policies
DROP CONSTRAINT IF EXISTS mesh_qos_policies_service_class_check;
ALTER TABLE mesh_qos_policies
ADD CONSTRAINT mesh_qos_policies_service_class_check
CHECK (service_class IN ('input', 'control', 'synthetic', 'render', 'clipboard', 'file_transfer', 'vpn_packets', 'telemetry'));
@@ -0,0 +1,29 @@
ALTER TABLE mesh_route_intents
DROP CONSTRAINT IF EXISTS mesh_route_intents_service_class_check;
ALTER TABLE mesh_route_intents
ADD CONSTRAINT mesh_route_intents_service_class_check
CHECK (service_class IN ('input', 'control', 'synthetic', 'render', 'clipboard', 'file_transfer', 'vpn_packets', 'remote_workspace', 'video', 'telemetry'));
ALTER TABLE mesh_qos_policies
DROP CONSTRAINT IF EXISTS mesh_qos_policies_service_class_check;
ALTER TABLE mesh_qos_policies
ADD CONSTRAINT mesh_qos_policies_service_class_check
CHECK (service_class IN ('input', 'control', 'synthetic', 'render', 'clipboard', 'file_transfer', 'vpn_packets', 'remote_workspace', 'video', 'telemetry'));
INSERT INTO mesh_qos_policies (
cluster_id, service_class, priority, reliability_mode, drop_policy, bandwidth_policy, metadata
)
SELECT c.id, 'remote_workspace', 20, 'adaptive', 'adaptive', '{}'::jsonb,
'{"default":true,"fabric_service_channel":true,"interactive":true}'::jsonb
FROM clusters c
ON CONFLICT (cluster_id, service_class) DO NOTHING;
INSERT INTO mesh_qos_policies (
cluster_id, service_class, priority, reliability_mode, drop_policy, bandwidth_policy, metadata
)
SELECT c.id, 'video', 40, 'adaptive', 'adaptive', '{}'::jsonb,
'{"default":true,"fabric_service_channel":true,"adaptive":true}'::jsonb
FROM clusters c
ON CONFLICT (cluster_id, service_class) DO NOTHING;