refactor(tenant): drop legacy plugin_installations, migrate monitoring to desktop_clients

Hard cutover from the browser-extension plugin flow to desktop clients:
remove plugin_installations/plugin_sessions tables and related service,
handler, router, and generated model code; migrate monitoring quotas
and collector types to desktop_clients (UUID primary_client_id);
recreate platform_access_snapshots keyed by client_id; update dev-seed
and callback types accordingly; mark legacy design docs as historical.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-20 13:52:35 +08:00
parent f5a1cd81b2
commit 5ff2e2e74c
25 changed files with 535 additions and 1384 deletions
@@ -21,7 +21,7 @@ CREATE INDEX idx_monitoring_question_snapshot_active
CREATE TABLE monitoring_platform_access_snapshots (
id BIGSERIAL PRIMARY KEY,
tenant_id BIGINT NOT NULL,
installation_id BIGINT NOT NULL,
client_id UUID NOT NULL,
ai_platform_id VARCHAR(30) NOT NULL,
business_date DATE NOT NULL,
access_status VARCHAR(20) NOT NULL,
@@ -32,7 +32,7 @@ CREATE TABLE monitoring_platform_access_snapshots (
reason_message TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT uk_platform_access_snapshot UNIQUE (tenant_id, installation_id, ai_platform_id, business_date)
CONSTRAINT uk_platform_access_snapshot UNIQUE (tenant_id, client_id, ai_platform_id, business_date)
);
CREATE INDEX idx_platform_access_snapshot_lookup
@@ -45,9 +45,9 @@ CREATE TABLE monitoring_collect_tasks (
question_id BIGINT NOT NULL,
question_hash BYTEA NOT NULL,
ai_platform_id VARCHAR(30) NOT NULL,
collector_type VARCHAR(20) NOT NULL DEFAULT 'plugin',
collector_type VARCHAR(20) NOT NULL DEFAULT 'desktop',
trigger_source VARCHAR(20) NOT NULL DEFAULT 'automatic',
run_mode VARCHAR(30) NOT NULL DEFAULT 'plugin_standard',
run_mode VARCHAR(30) NOT NULL DEFAULT 'desktop_standard',
business_date DATE NOT NULL,
planned_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
status VARCHAR(20) NOT NULL DEFAULT 'pending',
@@ -77,9 +77,9 @@ CREATE TABLE question_monitor_runs (
question_text_snapshot TEXT NOT NULL,
question_hash BYTEA NOT NULL,
ai_platform_id VARCHAR(30) NOT NULL,
collector_type VARCHAR(20) NOT NULL DEFAULT 'plugin',
collector_type VARCHAR(20) NOT NULL DEFAULT 'desktop',
trigger_source VARCHAR(20) NOT NULL DEFAULT 'automatic',
run_mode VARCHAR(30) NOT NULL DEFAULT 'plugin_standard',
run_mode VARCHAR(30) NOT NULL DEFAULT 'desktop_standard',
business_date DATE NOT NULL,
provider_model VARCHAR(100),
provider_request_id VARCHAR(100),
@@ -187,7 +187,7 @@ CREATE TABLE monitoring_brand_daily (
id BIGSERIAL PRIMARY KEY,
tenant_id BIGINT NOT NULL,
brand_id BIGINT NOT NULL,
collector_type VARCHAR(20) NOT NULL DEFAULT 'plugin',
collector_type VARCHAR(20) NOT NULL DEFAULT 'desktop',
business_date DATE NOT NULL,
sample_status VARCHAR(20) NOT NULL,
desired_sample_count INT NOT NULL DEFAULT 0,
@@ -221,7 +221,7 @@ CREATE TABLE monitoring_brand_platform_daily (
tenant_id BIGINT NOT NULL,
brand_id BIGINT NOT NULL,
ai_platform_id VARCHAR(30) NOT NULL,
collector_type VARCHAR(20) NOT NULL DEFAULT 'plugin',
collector_type VARCHAR(20) NOT NULL DEFAULT 'desktop',
business_date DATE NOT NULL,
platform_sample_status VARCHAR(20) NOT NULL,
planned_sample_count INT NOT NULL DEFAULT 0,
@@ -0,0 +1,63 @@
DROP TABLE IF EXISTS monitoring_platform_access_snapshots;
CREATE TABLE monitoring_platform_access_snapshots (
id BIGSERIAL PRIMARY KEY,
tenant_id BIGINT NOT NULL,
installation_id BIGINT NOT NULL,
ai_platform_id VARCHAR(30) NOT NULL,
business_date DATE NOT NULL,
access_status VARCHAR(20) NOT NULL,
connected BOOLEAN NOT NULL DEFAULT false,
accessible BOOLEAN NOT NULL DEFAULT false,
detected_at TIMESTAMPTZ NOT NULL,
reason_code VARCHAR(50),
reason_message TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT uk_platform_access_snapshot UNIQUE (tenant_id, installation_id, ai_platform_id, business_date)
);
CREATE INDEX idx_platform_access_snapshot_lookup
ON monitoring_platform_access_snapshots(tenant_id, business_date, ai_platform_id, access_status);
ALTER TABLE monitoring_collect_tasks
ALTER COLUMN collector_type SET DEFAULT 'plugin';
ALTER TABLE monitoring_collect_tasks
ALTER COLUMN run_mode SET DEFAULT 'plugin_standard';
UPDATE monitoring_collect_tasks
SET collector_type = 'plugin'
WHERE collector_type = 'desktop';
UPDATE monitoring_collect_tasks
SET run_mode = 'plugin_standard'
WHERE run_mode = 'desktop_standard';
ALTER TABLE question_monitor_runs
ALTER COLUMN collector_type SET DEFAULT 'plugin';
ALTER TABLE question_monitor_runs
ALTER COLUMN run_mode SET DEFAULT 'plugin_standard';
UPDATE question_monitor_runs
SET collector_type = 'plugin'
WHERE collector_type = 'desktop';
UPDATE question_monitor_runs
SET run_mode = 'plugin_standard'
WHERE run_mode = 'desktop_standard';
ALTER TABLE monitoring_brand_daily
ALTER COLUMN collector_type SET DEFAULT 'plugin';
UPDATE monitoring_brand_daily
SET collector_type = 'plugin'
WHERE collector_type = 'desktop';
ALTER TABLE monitoring_brand_platform_daily
ALTER COLUMN collector_type SET DEFAULT 'plugin';
UPDATE monitoring_brand_platform_daily
SET collector_type = 'plugin'
WHERE collector_type = 'desktop';
@@ -0,0 +1,63 @@
DROP TABLE IF EXISTS monitoring_platform_access_snapshots;
CREATE TABLE monitoring_platform_access_snapshots (
id BIGSERIAL PRIMARY KEY,
tenant_id BIGINT NOT NULL,
client_id UUID NOT NULL,
ai_platform_id VARCHAR(30) NOT NULL,
business_date DATE NOT NULL,
access_status VARCHAR(20) NOT NULL,
connected BOOLEAN NOT NULL DEFAULT false,
accessible BOOLEAN NOT NULL DEFAULT false,
detected_at TIMESTAMPTZ NOT NULL,
reason_code VARCHAR(50),
reason_message TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT uk_platform_access_snapshot UNIQUE (tenant_id, client_id, ai_platform_id, business_date)
);
CREATE INDEX idx_platform_access_snapshot_lookup
ON monitoring_platform_access_snapshots(tenant_id, business_date, ai_platform_id, access_status);
ALTER TABLE monitoring_collect_tasks
ALTER COLUMN collector_type SET DEFAULT 'desktop';
ALTER TABLE monitoring_collect_tasks
ALTER COLUMN run_mode SET DEFAULT 'desktop_standard';
UPDATE monitoring_collect_tasks
SET collector_type = 'desktop'
WHERE collector_type = 'plugin';
UPDATE monitoring_collect_tasks
SET run_mode = 'desktop_standard'
WHERE run_mode = 'plugin_standard';
ALTER TABLE question_monitor_runs
ALTER COLUMN collector_type SET DEFAULT 'desktop';
ALTER TABLE question_monitor_runs
ALTER COLUMN run_mode SET DEFAULT 'desktop_standard';
UPDATE question_monitor_runs
SET collector_type = 'desktop'
WHERE collector_type = 'plugin';
UPDATE question_monitor_runs
SET run_mode = 'desktop_standard'
WHERE run_mode = 'plugin_standard';
ALTER TABLE monitoring_brand_daily
ALTER COLUMN collector_type SET DEFAULT 'desktop';
UPDATE monitoring_brand_daily
SET collector_type = 'desktop'
WHERE collector_type = 'plugin';
ALTER TABLE monitoring_brand_platform_daily
ALTER COLUMN collector_type SET DEFAULT 'desktop';
UPDATE monitoring_brand_platform_daily
SET collector_type = 'desktop'
WHERE collector_type = 'plugin';