From 77fddfa356b923b50f1ef6926715dffa88de4b64 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sun, 27 Sep 2026 16:07:07 +0800 Subject: [PATCH] =?UTF-8?q?test=E2=9C=85:=20hard-delete=20the=20generator?= =?UTF-8?q?=20fixtures,=20as=20the=20delete=20endpoint=20does?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dropFixture soft-deleted the sys_tables rows it cleaned up. The config page's business-name check counts soft-deleted rows, so a second test importing the same table could not save its configuration. The delete endpoint removes these rows with Unscoped; the fixture now does too. --- app/other/apis/tools/gen_primary_key_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/other/apis/tools/gen_primary_key_test.go b/app/other/apis/tools/gen_primary_key_test.go index 93b51bf0..7be331fe 100644 --- a/app/other/apis/tools/gen_primary_key_test.go +++ b/app/other/apis/tools/gen_primary_key_test.go @@ -197,11 +197,13 @@ func TestGeneratorHandlesEveryPrimaryKeyShape(t *testing.T) { func dropFixture(t *testing.T, db *gorm.DB, table string) { t.Helper() + // Unscoped, as the delete endpoint is: a soft-deleted row still holds its + // business name, and the config page's uniqueness check counts it. var ids []int - db.Model(&tools.SysTables{}).Where("table_name = ?", table).Pluck("table_id", &ids) + db.Unscoped().Model(&tools.SysTables{}).Where("table_name = ?", table).Pluck("table_id", &ids) if len(ids) > 0 { - db.Where("table_id IN ?", ids).Delete(&tools.SysColumns{}) - db.Where("table_id IN ?", ids).Delete(&tools.SysTables{}) + db.Unscoped().Where("table_id IN ?", ids).Delete(&tools.SysColumns{}) + db.Unscoped().Where("table_id IN ?", ids).Delete(&tools.SysTables{}) } if err := db.Exec("DROP TABLE IF EXISTS " + table).Error; err != nil { t.Fatalf("dropping %s: %v", table, err)