From 2daeb43c5a464a32958b0a795176ad950047cc27 Mon Sep 17 00:00:00 2001 From: wangziqi Date: Thu, 30 Jul 2026 23:57:07 +0800 Subject: [PATCH] fix(education): validate content node migration --- ...__add_content_node_authoring_lifecycle.sql | 3 +-- ...ucationFlywayMigrationIntegrationTest.java | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/yudao-module-education/src/main/resources/db/migration/education/V4100__add_content_node_authoring_lifecycle.sql b/yudao-module-education/src/main/resources/db/migration/education/V4100__add_content_node_authoring_lifecycle.sql index a49ce894..63c47883 100644 --- a/yudao-module-education/src/main/resources/db/migration/education/V4100__add_content_node_authoring_lifecycle.sql +++ b/yudao-module-education/src/main/resources/db/migration/education/V4100__add_content_node_authoring_lifecycle.sql @@ -81,8 +81,7 @@ BEGIN NEW.name IS DISTINCT FROM OLD.name OR NEW.title IS DISTINCT FROM OLD.title OR NEW.node_type IS DISTINCT FROM OLD.node_type OR NEW.marker_type IS DISTINCT FROM OLD.marker_type OR NEW.is_leaf IS DISTINCT FROM OLD.is_leaf OR NEW.is_selectable IS DISTINCT FROM OLD.is_selectable OR - NEW.is_hidden IS DISTINCT FROM OLD.is_hidden OR NEW.sort_order IS DISTINCT FROM OLD.sort_order OR - NEW.metadata IS DISTINCT FROM OLD.metadata) THEN + NEW.sort_order IS DISTINCT FROM OLD.sort_order OR NEW.metadata IS DISTINCT FROM OLD.metadata) THEN RAISE EXCEPTION 'active content node content is immutable' USING ERRCODE = '23514'; END IF; RETURN NEW; diff --git a/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/test/EducationFlywayMigrationIntegrationTest.java b/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/test/EducationFlywayMigrationIntegrationTest.java index 21e848d1..10a0b128 100644 --- a/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/test/EducationFlywayMigrationIntegrationTest.java +++ b/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/test/EducationFlywayMigrationIntegrationTest.java @@ -119,7 +119,7 @@ class EducationFlywayMigrationIntegrationTest { assertThat(queryStrings(schema, "SELECT COALESCE(version, 'BASELINE') FROM flyway_schema_history ORDER BY installed_rank")) - .containsExactly("4009", "4010", "4020", "4030", "4040", "4050", "4060", "4070", "4080", "4090"); + .containsExactly("4009", "4010", "4020", "4030", "4040", "4050", "4060", "4070", "4080", "4090", "4100"); assertThat(queryLong(schema, "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = current_schema() " + "AND table_name = 'education_idempotency'")) @@ -181,7 +181,7 @@ class EducationFlywayMigrationIntegrationTest { assertThat(queryStrings(schema, "SELECT version FROM flyway_schema_history WHERE success = TRUE ORDER BY installed_rank")) - .containsExactly("4010", "4020", "4030", "4040", "4050", "4060", "4070", "4080", "4090"); + .containsExactly("4010", "4020", "4030", "4040", "4050", "4060", "4070", "4080", "4090", "4100"); assertThat(queryStrings(schema, "SELECT table_name FROM information_schema.tables " + "WHERE table_schema = current_schema() AND table_name IN (" + @@ -405,9 +405,21 @@ class EducationFlywayMigrationIntegrationTest { (id, tenant_id, scope, entry_key, name, entry_type) VALUES (100, 10, 'TENANT_OWNED', 'questions', 'Questions', 'question'); INSERT INTO education_content_node - (id, tenant_id, scope, entry_id, name, node_type) - VALUES (200, 10, 'TENANT_OWNED', 100, 'Algebra', 'category'), - (201, 10, 'TENANT_OWNED', 100, 'Geometry', 'category'); + (id, tenant_id, scope, entry_id, name, node_type, publication_status, is_active, is_hidden) + VALUES (200, 10, 'TENANT_OWNED', 100, 'Algebra', 'category', 'DRAFT', false, true), + (201, 10, 'TENANT_OWNED', 100, 'Geometry', 'category', 'DRAFT', false, true); + DO $activate_nodes$ + BEGIN + UPDATE education_content_node + SET publication_status = 'ACTIVE', is_active = true, is_hidden = false, + authoring_version = 1 + WHERE id IN (200, 201); + INSERT INTO education_content_node_lifecycle_audit + (tenant_id, node_id, authoring_version, actor_id, from_status, to_status) + VALUES (10, 200, 1, 7, 'DRAFT', 'ACTIVE'), + (10, 201, 1, 7, 'DRAFT', 'ACTIVE'); + END + $activate_nodes$; INSERT INTO education_question (id, tenant_id, scope, stem, type, options, correct_answer) VALUES (300, 10, 'TENANT_OWNED', 'Placed draft', 'text', '[]', 'answer');