feat(sqlite): add thread_id columns to contacts schema

Update SQLite schema to include thread_id and thread_type columns.
This commit is contained in:
viettranx committed 2026-04-02 08:22:54 +07:00
1 parent 5d632a522e
commit 670000651d
2 files changed
+11 -3

No files matched your search

+7 -1
View File
@@ -14,7 +14,7 @@ var schemaSQL string
// SchemaVersion is the current SQLite schema version.
// Bump this when adding new migration steps below.
const SchemaVersion = 4
const SchemaVersion = 5
// migrations maps version → SQL to apply when upgrading FROM that version.
// schema.sql always represents the LATEST full schema (for fresh DBs).
@@ -42,6 +42,12 @@ UPDATE cron_jobs SET
deliver_to = COALESCE(json_extract(payload, '$.to'), ''),
wake_heartbeat = COALESCE(json_extract(payload, '$.wake_heartbeat'), 0)
WHERE payload IS NOT NULL;`,
// Version 4 → 5: add thread_id, thread_type columns to channel_contacts for forum topic support.
4: `ALTER TABLE channel_contacts ADD COLUMN thread_id VARCHAR(100);
ALTER TABLE channel_contacts ADD COLUMN thread_type VARCHAR(20);
DROP INDEX IF EXISTS idx_channel_contacts_tenant_type_sender;
CREATE UNIQUE INDEX idx_channel_contacts_tenant_type_sender
ON channel_contacts(tenant_id, channel_type, sender_id, COALESCE(thread_id, ''));`,
// Version 3 → 4: add subagent_tasks table for subagent lifecycle persistence.
3: `CREATE TABLE IF NOT EXISTS subagent_tasks (
id TEXT PRIMARY KEY,
+4 -2
View File
@@ -1042,6 +1042,8 @@ CREATE TABLE IF NOT EXISTS channel_contacts (
avatar_url TEXT,
peer_kind VARCHAR(20),
contact_type VARCHAR(20) NOT NULL DEFAULT 'user',
thread_id VARCHAR(100),
thread_type VARCHAR(20),
metadata TEXT DEFAULT '{}',
merged_id TEXT,
tenant_id TEXT NOT NULL REFERENCES tenants(id),
@@ -1049,8 +1051,8 @@ CREATE TABLE IF NOT EXISTS channel_contacts (
last_seen_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);
-- tenant-scoped unique (migration 27 Phase I)
CREATE UNIQUE INDEX IF NOT EXISTS idx_channel_contacts_tenant_type_sender ON channel_contacts(tenant_id, channel_type, sender_id);
-- tenant-scoped unique including thread_id for topic contacts (migration 35)
CREATE UNIQUE INDEX IF NOT EXISTS idx_channel_contacts_tenant_type_sender ON channel_contacts(tenant_id, channel_type, sender_id, COALESCE(thread_id, ''));
CREATE INDEX IF NOT EXISTS idx_channel_contacts_instance ON channel_contacts(channel_instance) WHERE channel_instance IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_channel_contacts_merged ON channel_contacts(merged_id) WHERE merged_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_channel_contacts_search ON channel_contacts(display_name, username);