fix(education): close collection release gate gaps

This commit is contained in:
2026-07-31 10:10:10 +08:00
parent 1be0b420c8
commit eae5a6bb3a
6 changed files with 45 additions and 20 deletions

View File

@@ -16,14 +16,20 @@ BEGIN
LEFT JOIN education_question_collection_question membership ON membership.collection_id=collection.id AND NOT membership.deleted
LEFT JOIN education_question question ON question.id=membership.question_id
WHERE collection.scope='TENANT_OWNED' AND collection.is_active AND NOT collection.is_hidden AND NOT collection.deleted
AND (node.id IS NULL OR node.tenant_id IS DISTINCT FROM collection.tenant_id OR node.scope<>'TENANT_OWNED'
AND (collection.collection_type<>'MANUAL'
OR node.id IS NULL OR node.tenant_id IS DISTINCT FROM collection.tenant_id OR node.scope<>'TENANT_OWNED'
OR node.deleted OR NOT node.is_active OR node.is_hidden
OR collection.entry_id IS DISTINCT FROM node.entry_id
OR entry.id IS NULL OR entry.scope NOT IN ('PUBLIC','TENANT_OWNED')
OR (entry.scope='TENANT_OWNED' AND entry.tenant_id IS DISTINCT FROM collection.tenant_id)
OR entry.deleted OR NOT entry.is_active OR entry.is_hidden
OR (membership.id IS NOT NULL AND (question.id IS NULL OR question.tenant_id IS DISTINCT FROM collection.tenant_id
OR question.scope<>'TENANT_OWNED' OR question.deleted OR question.status<>'PUBLISHED' OR NOT question.is_published)))
OR (membership.id IS NOT NULL AND (membership.sort_order<0
OR question.id IS NULL OR question.tenant_id IS DISTINCT FROM collection.tenant_id
OR question.scope<>'TENANT_OWNED' OR question.deleted OR question.status<>'PUBLISHED' OR NOT question.is_published))
OR EXISTS (SELECT 1 FROM education_question_collection_question ordered_membership
WHERE ordered_membership.collection_id=collection.id AND NOT ordered_membership.deleted
GROUP BY ordered_membership.collection_id
HAVING count(*)<>count(DISTINCT ordered_membership.sort_order) OR min(ordered_membership.sort_order)<>0 OR max(ordered_membership.sort_order)<>count(*)-1))
ORDER BY collection.id,membership.question_id NULLS FIRST LIMIT 1;
IF bad_collection IS NOT NULL THEN
RAISE EXCEPTION 'invalid historical active collection % member % blocks V4110',bad_collection,COALESCE(bad_question,0) USING ERRCODE='23514';