fix(backend): secure production startup and migrations

This commit is contained in:
2026-07-22 13:11:30 +08:00
parent 0daea4def9
commit 7980943660
13 changed files with 220 additions and 43 deletions

View File

@@ -5,17 +5,16 @@ package seed
import (
"context"
"fmt"
"os"
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/bcrypt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"senlinai-agent/backend/internal/models"
"senlinai-agent/backend/internal/testutil"
)
type demoSeedRunContextKey struct{}
@@ -28,13 +27,10 @@ const (
)
func TestPostgresDemoSeedSerializesConcurrentRunsForSameOwner(t *testing.T) {
dsn := os.Getenv("TEST_DATABASE_URL")
require.NotEmpty(t, dsn, "TEST_DATABASE_URL is required for integration tests and must point to an isolated database")
database, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
database := testutil.OpenIsolatedPostgres(t, &gorm.Config{
TranslateError: true,
Logger: logger.Default.LogMode(logger.Silent),
})
require.NoError(t, err)
require.NoError(t, models.AutoMigrate(database))
suffix := fmt.Sprint(time.Now().UnixNano())