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 <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-14 21:50:02 +08:00
committed by GitHub
co-authored by rogee
parent 6a3cb49781
commit 849304ac87
2 changed files with 15 additions and 0 deletions
+4
View File
@@ -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,
@@ -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) {