20 lines
836 B
SQL
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';
|