diff --git a/CHANGELOG.md b/CHANGELOG.md index fc74091..d4d362a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # 变更记录 - @go/db +## [1.5.11] - 2026-08-22 +- SQLite schema 同步支持删除定义中已经移除的字段,并同步处理影子删除表。 + ## [1.5.10] - 2026-08-13 - 修复 schema 同步中的字段转义解析。 diff --git a/Schema.go b/Schema.go index dd35136..85e605c 100644 --- a/Schema.go +++ b/Schema.go @@ -581,6 +581,9 @@ func (db *DB) CheckTable(table *TableStruct) error { for keyId := range oldIndexes { if keyId != "PRIMARY" && !isPostgres && strings.ToLower(keySetFields[keyId]) != strings.ToLower(oldIndexes[keyId]) { if strings.HasPrefix(db.Config.Type, "sqlite") { + if table.Name == "_Table" || table.Name == "_Field" { + continue + } if strings.HasPrefix(keyId, "sqlite_autoindex_") { continue } @@ -646,7 +649,12 @@ func (db *DB) CheckTable(table *TableStruct) error { for oldFieldName := range oldFields { if !newFieldExists[oldFieldName] { - if !strings.HasPrefix(db.Config.Type, "sqlite") && !isPostgres { + if strings.HasPrefix(db.Config.Type, "sqlite") { + if table.Name == "_Table" || table.Name == "_Field" { + continue + } + actions = append(actions, "ALTER TABLE "+db.Quote(table.Name)+" DROP COLUMN "+db.Quote(oldFieldName)) + } else if !isPostgres { actions = append(actions, "DROP COLUMN "+db.Quote(oldFieldName)) } } diff --git a/SchemaSync_test.go b/SchemaSync_test.go index 22a86dc..e37bf1c 100644 --- a/SchemaSync_test.go +++ b/SchemaSync_test.go @@ -42,6 +42,24 @@ test_table SD // Test table with shadow delete if res.IntOnR1C1() != 1 { t.Fatal("Shadow delete failed") } + + withoutStatus := `== Default == +test_table SD // Test table with shadow delete + id AI // ID + name v50 U + autoVersion ubi // Version +` + if err := dbInst.Sync(withoutStatus); err != nil { + t.Fatal("Sync removed field:", err) + } + for _, tableName := range []string{"test_table", "test_table_deleted"} { + fields := dbInst.Query("PRAGMA table_info(" + dbInst.Quote(tableName) + ")").MapResults() + for _, field := range fields { + if field["name"] == "status" { + t.Fatalf("removed field remains in physical table %s", tableName) + } + } + } } func TestAutoDetectShadow(t *testing.T) { diff --git a/TEST.md b/TEST.md index 6ea5987..544b16a 100644 --- a/TEST.md +++ b/TEST.md @@ -1,5 +1,9 @@ # @go/db 测试报告 +## v1.5.11 验证 +- `TestSchemaSync` 覆盖 SQLite 主表与影子删除表的字段移除。 +- `go test -v ./...` 与 `go test -bench=. ./...` 通过。 + ## v1.5.9 验证 - `go list -m all`:模块图使用 `redis v1.5.11` 与稳定版 `redigo v1.9.3`。 - `go test -v ./...`:通过完整测试。