mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-29 04:20:21 +00:00
- Consolidated PG migration 054: agent_hooks rename + junction table + deprecated column drop - Updated SQLite schema v19 with final consolidated migration - Removed obsolete schema rebuild files (v21, v23) - Updated Go store layer (pg/hooks.go, sqlitestore/hooks.go) - Updated integration tests to use new table names (hooks, hook_agents) - Updated TypeScript protocol, UI components, and i18n strings - Updated gateway methods to reflect schema changes Tables: agent_hooks → hooks, agent_hook_agents → hook_agents
42 lines
1.5 KiB
SQL
42 lines
1.5 KiB
SQL
-- 000054 — Add `name` column, N:M junction, rename tables, drop agent_id.
|
|
--
|
|
-- 1) name: user-facing label. Nullable so existing rows don't break.
|
|
-- 2) Junction table replaces the 1:N agent_id FK with many-to-many.
|
|
-- 3) Data migration: copy existing agent_id values into junction.
|
|
-- 4) Rename agent_hooks → hooks, agent_hook_agents → hook_agents.
|
|
-- 5) Drop deprecated agent_id column from hooks.
|
|
-- 6) Recreate indexes with new table names.
|
|
|
|
-- Step 1: add name column
|
|
ALTER TABLE agent_hooks ADD COLUMN IF NOT EXISTS name VARCHAR(255);
|
|
|
|
-- Step 2: create junction table
|
|
CREATE TABLE IF NOT EXISTS agent_hook_agents (
|
|
hook_id UUID NOT NULL REFERENCES agent_hooks(id) ON DELETE CASCADE,
|
|
agent_id UUID NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
|
PRIMARY KEY (hook_id, agent_id)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_hook_agents_agent
|
|
ON agent_hook_agents (agent_id);
|
|
|
|
-- Step 3: copy existing agent_id values into junction
|
|
INSERT INTO agent_hook_agents (hook_id, agent_id)
|
|
SELECT id, agent_id FROM agent_hooks
|
|
WHERE agent_id IS NOT NULL
|
|
ON CONFLICT DO NOTHING;
|
|
|
|
-- Step 4: rename tables
|
|
ALTER TABLE agent_hooks RENAME TO hooks;
|
|
ALTER TABLE agent_hook_agents RENAME TO hook_agents;
|
|
|
|
-- Step 5: drop deprecated column
|
|
ALTER TABLE hooks DROP COLUMN IF EXISTS agent_id;
|
|
|
|
-- Step 6: recreate indexes with new table/column names
|
|
DROP INDEX IF EXISTS idx_hooks_lookup;
|
|
CREATE INDEX idx_hooks_lookup ON hooks (tenant_id, event) WHERE enabled = TRUE;
|
|
|
|
DROP INDEX IF EXISTS idx_hook_agents_agent;
|
|
CREATE INDEX idx_hook_agents_agent ON hook_agents (agent_id);
|