fix: restore DB script and migrations

This commit is contained in:
Apple
2025-11-30 14:06:45 -08:00
parent 534bd72183
commit d71da0bae3
2 changed files with 16 additions and 19 deletions

View File

@@ -1,5 +1,7 @@
-- Create agent_prompts table
CREATE TABLE IF NOT EXISTS agent_prompts (
-- Re-create agent_prompts table to ensure correct schema (with updated_at)
DROP TABLE IF EXISTS agent_prompts CASCADE;
CREATE TABLE agent_prompts (
id text PRIMARY KEY DEFAULT ('ap_' || substr(md5(random()::text), 1, 12)),
agent_id text NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
kind text NOT NULL CHECK (kind IN ('core', 'safety', 'governance', 'tools')),
@@ -13,11 +15,9 @@ CREATE TABLE IF NOT EXISTS agent_prompts (
);
-- Create indexes
CREATE UNIQUE INDEX IF NOT EXISTS ux_agent_prompts_agent_kind_version ON agent_prompts(agent_id, kind, version);
CREATE INDEX IF NOT EXISTS ix_agent_prompts_agent_id ON agent_prompts(agent_id);
CREATE INDEX IF NOT EXISTS ix_agent_prompts_agent_kind_active ON agent_prompts(agent_id, kind) WHERE is_active = true;
CREATE UNIQUE INDEX ux_agent_prompts_agent_kind_version ON agent_prompts(agent_id, kind, version);
CREATE INDEX ix_agent_prompts_agent_id ON agent_prompts(agent_id);
CREATE INDEX ix_agent_prompts_agent_kind_active ON agent_prompts(agent_id, kind) WHERE is_active = true;
-- Grant permissions (adjust based on your RBAC)
-- Grant permissions
GRANT ALL ON agent_prompts TO postgres;
-- GRANT SELECT, INSERT, UPDATE ON agent_prompts TO app_user; -- Uncomment if needed