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 -- Re-create agent_prompts table to ensure correct schema (with updated_at)
CREATE TABLE IF NOT EXISTS agent_prompts ( DROP TABLE IF EXISTS agent_prompts CASCADE;
CREATE TABLE agent_prompts (
id text PRIMARY KEY DEFAULT ('ap_' || substr(md5(random()::text), 1, 12)), id text PRIMARY KEY DEFAULT ('ap_' || substr(md5(random()::text), 1, 12)),
agent_id text NOT NULL REFERENCES agents(id) ON DELETE CASCADE, agent_id text NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
kind text NOT NULL CHECK (kind IN ('core', 'safety', 'governance', 'tools')), 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 indexes
CREATE UNIQUE INDEX IF NOT EXISTS ux_agent_prompts_agent_kind_version ON agent_prompts(agent_id, kind, version); CREATE UNIQUE INDEX 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 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 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 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;" docker exec dagi-postgres psql -U postgres -c "CREATE DATABASE daarion_memory;"
fi 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..." echo "Applying migrations..."
for f in migrations/*.sql; do for f in migrations/*.sql; do
echo "Applying $f..." echo "Applying $f..."
# Check if migration needed? docker exec -i dagi-postgres psql -U postgres -d daarion_memory < "$f" || echo "Warning: Migration $f had errors, continuing..."
# 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"
done done
# 4. Rebuild and restart city-service # 5. Rebuild and restart city-service
echo "Restarting 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!" echo "Deployment and DB restoration complete!"