From a399ba74190b7518a0f218c6a18ab522928d7faa Mon Sep 17 00:00:00 2001 From: Houmgaor Date: Thu, 26 Feb 2026 21:55:12 +0100 Subject: [PATCH] fix(shop): fix syntax error and update migration tests after #150 merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #150 introduced a double brace `{ {` on handlers_shop.go:109 that broke compilation. Migration tests were also hardcoded for 1 migration but 3 now exist (0001–0003). --- server/channelserver/handlers_shop.go | 4 ++-- server/migrations/migrations_test.go | 34 +++++++++++++++++---------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/server/channelserver/handlers_shop.go b/server/channelserver/handlers_shop.go index b679f2a64..8a1fbabfb 100644 --- a/server/channelserver/handlers_shop.go +++ b/server/channelserver/handlers_shop.go @@ -93,7 +93,7 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) { bf.WriteUint16(uint16(len(gachas))) bf.WriteUint16(uint16(len(gachas))) for _, g := range gachas { - if s.server.erupeConfig.RealClientMode >= cfg.GG{ + if s.server.erupeConfig.RealClientMode >= cfg.GG { //Before GG, there was no data for G1, so there was no data for G1 except for ID and name //But the difference between G2 and G3 still needs to be tested, and the data for G1 and GG are already clear bf.WriteUint32(g.ID) @@ -106,7 +106,7 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) { bf.WriteUint32(0) // only 0 in known packet } ps.Uint8(bf, g.Name, true) - if s.server.erupeConfig.RealClientMode <= cfg.GG{ { //For versions less than or equal to GG, each message sent to the name ends + if s.server.erupeConfig.RealClientMode <= cfg.GG { //For versions less than or equal to GG, each message sent to the name ends continue } ps.Uint8(bf, g.URLBanner, false) diff --git a/server/migrations/migrations_test.go b/server/migrations/migrations_test.go index 602fc3722..d337065a9 100644 --- a/server/migrations/migrations_test.go +++ b/server/migrations/migrations_test.go @@ -62,16 +62,16 @@ func TestMigrateEmptyDB(t *testing.T) { if err != nil { t.Fatalf("Migrate failed: %v", err) } - if applied != 1 { - t.Errorf("expected 1 migration applied, got %d", applied) + if applied != 3 { + t.Errorf("expected 3 migrations applied, got %d", applied) } ver, err := Version(db) if err != nil { t.Fatalf("Version failed: %v", err) } - if ver != 1 { - t.Errorf("expected version 1, got %d", ver) + if ver != 3 { + t.Errorf("expected version 3, got %d", ver) } } @@ -103,28 +103,36 @@ func TestMigrateExistingDBWithoutSchemaVersion(t *testing.T) { logger, _ := zap.NewDevelopment() - // Simulate an existing database: create a dummy table - _, err := db.Exec("CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT)") + // Simulate an existing database that has the full 0001 schema applied + // but no schema_version tracking yet (pre-migration-system installs). + // First, run all migrations normally to get the real schema... + _, err := Migrate(db, logger) if err != nil { - t.Fatalf("Failed to create dummy table: %v", err) + t.Fatalf("Initial Migrate failed: %v", err) + } + // ...then drop schema_version to simulate the pre-tracking state. + _, err = db.Exec("DROP TABLE schema_version") + if err != nil { + t.Fatalf("Failed to drop schema_version: %v", err) } - // Migrate should detect existing DB and auto-mark baseline + // Migrate should detect existing DB and auto-mark baseline, + // then apply remaining migrations (0002, 0003). applied, err := Migrate(db, logger) if err != nil { t.Fatalf("Migrate failed: %v", err) } - // Baseline (0001) is auto-marked, so 0 "new" migrations applied - if applied != 0 { - t.Errorf("expected 0 migrations applied (baseline auto-marked), got %d", applied) + // Baseline (0001) is auto-marked, then 0002+0003 are applied = 2 + if applied != 2 { + t.Errorf("expected 2 migrations applied (baseline auto-marked, 0002+0003 applied), got %d", applied) } ver, err := Version(db) if err != nil { t.Fatalf("Version failed: %v", err) } - if ver != 1 { - t.Errorf("expected version 1 (auto-marked baseline), got %d", ver) + if ver != 3 { + t.Errorf("expected version 3, got %d", ver) } }