From 849304ac878ea07212df5348479c74fd13ec60d8 Mon Sep 17 00:00:00 2001 From: Rogee Date: Fri, 14 Aug 2026 21:50:02 +0800 Subject: [PATCH] H-130: reject empty rollback migration path (#21) * H-130: reject empty rollback migration path * H-130: lock Captain inbox assistant uniqueness --------- Co-authored-by: Rogee --- backend/internal/database/migrate.go | 4 ++++ .../internal/repository/captain_inbox_repo_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/backend/internal/database/migrate.go b/backend/internal/database/migrate.go index cb158521..fabc4d3b 100644 --- a/backend/internal/database/migrate.go +++ b/backend/internal/database/migrate.go @@ -116,6 +116,10 @@ func MigrateSteps(dbURL string, migrationsPath string, steps int) error { // RollbackMigrations rolls back all migrations (drops all tables). func RollbackMigrations(dbURL string, migrationsPath string) error { + if migrationsPath == "" { + return errors.New("migrations path is required") + } + m, err := migrate.New( fmt.Sprintf("file://%s", migrationsPath), dbURL, diff --git a/backend/internal/repository/captain_inbox_repo_test.go b/backend/internal/repository/captain_inbox_repo_test.go index e19b5312..406c89ab 100644 --- a/backend/internal/repository/captain_inbox_repo_test.go +++ b/backend/internal/repository/captain_inbox_repo_test.go @@ -34,6 +34,17 @@ func TestCaptainInboxRepo_Create(t *testing.T) { assert.Equal(t, uint(100), ci.AccountID) } +func TestCaptainInboxRepo_Create_OnlyOneActiveAssistantPerInbox(t *testing.T) { + db := setupTestDB(t, &model.CaptainInbox{}) + repo := NewCaptainInboxRepo(db) + ctx := context.Background() + + require.NoError(t, repo.Create(ctx, newTestCaptainInbox(1, 10, 100))) + require.Error(t, repo.Create(ctx, newTestCaptainInbox(2, 10, 100))) + require.NoError(t, repo.Delete(ctx, 1, 10)) + require.NoError(t, repo.Create(ctx, newTestCaptainInbox(2, 10, 100))) +} + // ========== Delete ========== func TestCaptainInboxRepo_Delete(t *testing.T) {