Files
dashboard/backend/database/migrations/011_create_ai_insights.sql
T
Alberto-Audrix 32a36cceff
CI / lint-and-test (push) Canceled after 0s
first commit
2026-07-28 08:55:05 +07:00

20 lines
836 B
SQL

-- Create AI Insights table for caching AI-generated insights
CREATE TABLE IF NOT EXISTS ai_insights (
id SERIAL PRIMARY KEY,
cycle_id VARCHAR(255) NOT NULL,
kandang_id VARCHAR(255), -- NULL means "all kandangs"
insight_text TEXT NOT NULL,
version VARCHAR(50) NOT NULL DEFAULT 'v1',
generated_at TIMESTAMP NOT NULL DEFAULT NOW(),
expires_at TIMESTAMP NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Create indexes for faster lookups
CREATE INDEX IF NOT EXISTS idx_ai_insights_cycle_kandang ON ai_insights (cycle_id, kandang_id);
CREATE INDEX IF NOT EXISTS idx_ai_insights_expires_at ON ai_insights (expires_at);
-- Add comment to table
COMMENT ON TABLE ai_insights IS 'Stores AI-generated insights with 6-hour TTL for cross-device caching';