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

View File

@@ -15,23 +15,20 @@ else
docker exec dagi-postgres psql -U postgres -c "CREATE DATABASE daarion_memory;"
fi
# 3. Apply all migrations in order
# 3. Setup extensions
echo "Enabling extensions..."
docker exec dagi-postgres psql -U postgres -d daarion_memory -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'
# 4. Apply all migrations in order
echo "Applying migrations..."
for f in migrations/*.sql; do
echo "Applying $f..."
# Check if migration needed?
# For simplicity in this recovery script, we assume psql will handle "IF NOT EXISTS" errors
# or we just run them.
# Real production migration tools track versions.
# Here we rely on SQL idempotency or manual check.
# Most of our recent migrations use "CREATE TABLE IF NOT EXISTS".
# Let's run them.
docker exec -i dagi-postgres psql -U postgres -d daarion_memory < "$f"
docker exec -i dagi-postgres psql -U postgres -d daarion_memory < "$f" || echo "Warning: Migration $f had errors, continuing..."
done
# 4. Rebuild and restart city-service
# 5. Rebuild and restart city-service
echo "Restarting city-service..."
docker-compose up -d --build city-service
docker compose up -d --build city-service
echo "Deployment and DB restoration complete!"