新增发布校准数据库结构

This commit is contained in:
Codex
2026-06-24 11:04:38 +08:00
parent 7cd54738cc
commit f3d26e148a
2 changed files with 149 additions and 0 deletions
@@ -0,0 +1,74 @@
CREATE TABLE IF NOT EXISTS rubric_versions (
id TEXT PRIMARY KEY,
version TEXT NOT NULL,
name TEXT NOT NULL,
dimensions TEXT NOT NULL,
formula TEXT NOT NULL,
is_active INTEGER NOT NULL,
created_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS scoring_runs (
id TEXT PRIMARY KEY,
job_id TEXT NOT NULL,
revision INTEGER NOT NULL,
rubric_version_id TEXT NOT NULL,
dimension_scores TEXT NOT NULL,
composite_score REAL NOT NULL,
rationale TEXT NOT NULL,
created_at TEXT NOT NULL,
FOREIGN KEY (job_id, revision)
REFERENCES optimized_articles(job_id, revision) ON DELETE CASCADE,
FOREIGN KEY (rubric_version_id) REFERENCES rubric_versions(id)
);
CREATE TABLE IF NOT EXISTS publication_records (
id TEXT PRIMARY KEY,
job_id TEXT NOT NULL,
revision INTEGER NOT NULL,
platform TEXT NOT NULL,
url TEXT NOT NULL,
published_at TEXT NOT NULL,
status TEXT NOT NULL,
notes TEXT NOT NULL,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
FOREIGN KEY (job_id, revision)
REFERENCES optimized_articles(job_id, revision) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS performance_snapshots (
id TEXT PRIMARY KEY,
publication_id TEXT NOT NULL,
source TEXT NOT NULL,
window_label TEXT NOT NULL,
metrics TEXT NOT NULL,
feedback_summary TEXT NOT NULL,
raw_reference TEXT,
snapshot_at TEXT NOT NULL,
FOREIGN KEY (publication_id) REFERENCES publication_records(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS calibration_events (
id TEXT PRIMARY KEY,
publication_id TEXT NOT NULL,
scoring_run_id TEXT NOT NULL,
performance_snapshot_id TEXT NOT NULL,
direction TEXT NOT NULL,
observations TEXT NOT NULL,
recommended_action TEXT NOT NULL,
created_at TEXT NOT NULL,
FOREIGN KEY (publication_id) REFERENCES publication_records(id) ON DELETE CASCADE,
FOREIGN KEY (scoring_run_id) REFERENCES scoring_runs(id) ON DELETE CASCADE,
FOREIGN KEY (performance_snapshot_id)
REFERENCES performance_snapshots(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_scoring_runs_job_revision
ON scoring_runs(job_id, revision);
CREATE INDEX IF NOT EXISTS idx_publication_records_job_revision
ON publication_records(job_id, revision);
CREATE INDEX IF NOT EXISTS idx_performance_snapshots_publication
ON performance_snapshots(publication_id);
+75
View File
@@ -60,5 +60,80 @@ export function initializeSchema(db: Database.Database) {
foreign key (job_id, revision)
references optimized_articles(job_id, revision) on delete cascade
);
create table if not exists rubric_versions (
id text primary key,
version text not null,
name text not null,
dimensions text not null,
formula text not null,
is_active integer not null,
created_at text not null
);
create table if not exists scoring_runs (
id text primary key,
job_id text not null,
revision integer not null,
rubric_version_id text not null,
dimension_scores text not null,
composite_score real not null,
rationale text not null,
created_at text not null,
foreign key (job_id, revision)
references optimized_articles(job_id, revision) on delete cascade,
foreign key (rubric_version_id) references rubric_versions(id)
);
create table if not exists publication_records (
id text primary key,
job_id text not null,
revision integer not null,
platform text not null,
url text not null,
published_at text not null,
status text not null,
notes text not null,
created_at text not null,
updated_at text not null,
foreign key (job_id, revision)
references optimized_articles(job_id, revision) on delete cascade
);
create table if not exists performance_snapshots (
id text primary key,
publication_id text not null,
source text not null,
window_label text not null,
metrics text not null,
feedback_summary text not null,
raw_reference text,
snapshot_at text not null,
foreign key (publication_id) references publication_records(id) on delete cascade
);
create table if not exists calibration_events (
id text primary key,
publication_id text not null,
scoring_run_id text not null,
performance_snapshot_id text not null,
direction text not null,
observations text not null,
recommended_action text not null,
created_at text not null,
foreign key (publication_id) references publication_records(id) on delete cascade,
foreign key (scoring_run_id) references scoring_runs(id) on delete cascade,
foreign key (performance_snapshot_id)
references performance_snapshots(id) on delete cascade
);
create index if not exists idx_scoring_runs_job_revision
on scoring_runs(job_id, revision);
create index if not exists idx_publication_records_job_revision
on publication_records(job_id, revision);
create index if not exists idx_performance_snapshots_publication
on performance_snapshots(publication_id);
`);
}