mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 15:44:28 +00:00
feat(agent): refactor database session storage to normalized DAG entries and lazy thread sync
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "agent_session_entries" ADD COLUMN "asset_id" TEXT,
|
||||
ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN "data" JSONB,
|
||||
ADD COLUMN "parent_id" TEXT,
|
||||
ADD COLUMN "type" TEXT,
|
||||
ALTER COLUMN "session_id" DROP NOT NULL,
|
||||
ALTER COLUMN "entry" DROP NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "agent_session_entries_parent_id_idx" ON "agent_session_entries"("parent_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "agent_session_entries_asset_id_idx" ON "agent_session_entries"("asset_id");
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
-- Migrate existing entry JSON data to new columns
|
||||
UPDATE agent_session_entries
|
||||
SET
|
||||
type = entry->>'type',
|
||||
parent_id = entry->>'parentId',
|
||||
asset_id = (SELECT s.asset_id FROM agent_sessions s WHERE s.id = agent_session_entries.session_id),
|
||||
created_at = CASE
|
||||
WHEN entry->>'timestamp' IS NOT NULL THEN (entry->>'timestamp')::timestamptz
|
||||
ELSE created_at
|
||||
END,
|
||||
data = (entry::jsonb - 'id' - 'type' - 'parentId' - 'timestamp')::text::json
|
||||
WHERE entry IS NOT NULL;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `entry` on the `agent_session_entries` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "agent_session_entries" DROP COLUMN "entry";
|
||||
Reference in New Issue
Block a user