nxtgauge-backend-rust/crates/db/migrations/20260608020000_ai_phase4_columns.up.sql
Ashwin Kumar Sivakumar d48983ee21
Some checks failed
build-and-push / detect-changes (push) Successful in 6s
build-and-push / build (catering-services) (push) Failing after 5s
build-and-push / build (companies) (push) Failing after 6s
build-and-push / build (cron) (push) Failing after 5s
build-and-push / build (customers) (push) Failing after 5s
build-and-push / build (developers) (push) Failing after 5s
build-and-push / build (employees) (push) Successful in 11s
build-and-push / build (fitness-trainers) (push) Successful in 11s
build-and-push / build (graphic-designers) (push) Successful in 12s
build-and-push / build (gateway) (push) Successful in 25s
build-and-push / build (jobs) (push) Failing after 18s
build-and-push / build (leads) (push) Failing after 19s
build-and-push / build (makeup-artists) (push) Failing after 4s
build-and-push / build (payments) (push) Failing after 4s
build-and-push / build (photographers) (push) Failing after 18s
build-and-push / build (job-seekers) (push) Failing after 1m30s
build-and-push / build (tutors) (push) Failing after 5s
build-and-push / build (social-media-managers) (push) Failing after 20s
build-and-push / build (ugc-content-creators) (push) Failing after 5s
build-and-push / build (users) (push) Failing after 6s
build-and-push / build (video-editors) (push) Failing after 5s
feat(ai): Phase 4 - multilingual, voice, A/B testing, analytics (with stubs)
2026-06-08 06:41:10 +05:30

32 lines
1.3 KiB
PL/PgSQL

-- Phase 4: Add language/voice/tokens columns to ai_conversations.
-- All non-destructive with defaults so this is safe on existing rows.
BEGIN;
-- 1. Detected language of the user message. 2-letter ISO code (en, es, fr,
-- de, hi, zh, ja, pt, ar, ru). Defaults to 'en' for back-compat.
ALTER TABLE ai_conversations
ADD COLUMN IF NOT EXISTS language VARCHAR(8) NOT NULL DEFAULT 'en';
-- 2. Voice-input metadata: did this conversation come from a voice
-- transcript, and how long was the audio?
ALTER TABLE ai_conversations
ADD COLUMN IF NOT EXISTS has_voice BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS voice_duration_ms INTEGER;
-- 3. Context-window management: a rough char-based token estimate for the
-- query+response pair, plus a one-line LLM-generated summary that we can
-- splice in when the conversation gets long.
ALTER TABLE ai_conversations
ADD COLUMN IF NOT EXISTS tokens_estimate INTEGER,
ADD COLUMN IF NOT EXISTS summary TEXT;
-- Hot path: "all conversations in a given language for analytics"
CREATE INDEX IF NOT EXISTS idx_ai_conversations_language
ON ai_conversations (language, created_at DESC);
-- Hot path: "find voice conversations"
CREATE INDEX IF NOT EXISTS idx_ai_conversations_voice
ON ai_conversations (user_id, has_voice) WHERE has_voice = TRUE;
COMMIT;