ci: validate migrations before nas deploy
Backend CI / Backend (push) Successful in 13m6s

This commit is contained in:
2026-05-01 12:37:15 +08:00
parent 079b361679
commit 9074b7927b
2 changed files with 125 additions and 18 deletions
@@ -1,24 +1,60 @@
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;
DO $$
BEGIN
IF to_regclass('public.brand_question_versions') IS NOT NULL
AND EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'brand_questions'
AND column_name = 'current_version_id'
)
THEN
EXECUTE $sql$
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
),
q.question_text,
''
)
WHERE q.question_text IS NULL
$sql$;
ELSIF to_regclass('public.brand_question_versions') IS NOT NULL THEN
EXECUTE $sql$
UPDATE brand_questions q
SET question_text = COALESCE(
(
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
),
q.question_text,
''
)
WHERE q.question_text IS NULL
$sql$;
END IF;
END $$;
UPDATE brand_questions
SET question_text = ''
WHERE question_text IS NULL;
ALTER TABLE brand_questions
ALTER COLUMN question_text SET NOT NULL;