36451a613d
- Added comprehensive technical design document for AI Brand Monitoring System V5, outlining system architecture, data models, sampling strategies, and monitoring protocols. - Key changes include a shift to a sampling-based trend monitoring approach, updated data collection and storage strategies, and new metrics for performance evaluation. - Implemented migration scripts to support the flattening of brand questions and versioning of question texts, ensuring historical data integrity and version control.
30 lines
690 B
SQL
30 lines
690 B
SQL
ALTER TABLE brand_questions
|
|
ADD COLUMN IF NOT EXISTS question_text TEXT;
|
|
|
|
UPDATE brand_questions q
|
|
SET question_text = COALESCE(
|
|
(
|
|
SELECT v.question_text
|
|
FROM brand_question_versions v
|
|
WHERE v.id = q.current_version_id
|
|
LIMIT 1
|
|
),
|
|
(
|
|
SELECT v.question_text
|
|
FROM brand_question_versions v
|
|
WHERE v.question_id = q.id
|
|
ORDER BY v.version_no DESC, v.id DESC
|
|
LIMIT 1
|
|
),
|
|
''
|
|
)
|
|
WHERE q.question_text IS NULL;
|
|
|
|
ALTER TABLE brand_questions
|
|
ALTER COLUMN question_text SET NOT NULL;
|
|
|
|
ALTER TABLE brand_questions
|
|
DROP COLUMN IF EXISTS current_version_id;
|
|
|
|
DROP TABLE IF EXISTS brand_question_versions;
|