[#2551] auto register the initial generated snapshot migration to prevent incorrectly reapplying the snapshot on container restart
This commit is contained in:
@@ -6,11 +6,14 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||
"github.com/pocketbase/pocketbase/tests"
|
||||
"github.com/pocketbase/pocketbase/tools/migrate"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
@@ -776,3 +779,36 @@ func TestAutomigrateCollectionNoChanges(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitialAutoSnapshot(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
migrationsDir := filepath.Join(app.DataDir(), "_test_auto_snapshot_")
|
||||
|
||||
migratecmd.MustRegister(app, nil, &migratecmd.Options{
|
||||
TemplateLang: migratecmd.TemplateLangJS,
|
||||
Automigrate: true,
|
||||
Dir: migrationsDir,
|
||||
})
|
||||
|
||||
app.Bootstrap()
|
||||
|
||||
app.OnBeforeServe().Trigger(&core.ServeEvent{
|
||||
App: app,
|
||||
})
|
||||
|
||||
var foundFiles []string
|
||||
|
||||
err := app.Dao().NonconcurrentDB().Select("file").
|
||||
From(migrate.DefaultMigrationsTable).
|
||||
Where(dbx.NewExp("file like '%collections_snapshot.js'")).
|
||||
Column(&foundFiles)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(foundFiles) != 1 {
|
||||
t.Fatalf("Expected 1 collections_snapshot migration, found %v", foundFiles)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user