Skip to content

Commit

Permalink
[pocketbase#2693] removed the implicit autosnapshot migration creatio…
Browse files Browse the repository at this point in the history
…n as it is not clear to the users when it happens
  • Loading branch information
ganigeorgiev committed Jun 14, 2023
1 parent 745b230 commit bd95a5b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 58 deletions.
22 changes: 0 additions & 22 deletions plugins/migratecmd/migratecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

"github.com/AlecAivazis/survey/v2"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/models"
Expand Down Expand Up @@ -93,27 +92,6 @@ func Register(app core.App, rootCmd *cobra.Command, config Config) error {
// when migrations are applied on server start
p.app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
p.refreshCachedCollections()

cachedCollections, _ := p.getCachedCollections()
// create a full initial snapshot, if there are no custom
// migrations but there is already at least 1 collection created,
// to ensure that the automigrate will work with up-to-date collections data
if !p.hasCustomMigrations() && len(cachedCollections) > 1 {
snapshotFile, err := p.migrateCollectionsHandler(nil, false)
if err != nil {
return err
}

// insert the snapshot migration entry
_, insertErr := p.app.Dao().NonconcurrentDB().Insert(migrate.DefaultMigrationsTable, dbx.Params{
"file": snapshotFile,
"applied": time.Now().Unix(),
}).Execute()
if insertErr != nil {
return insertErr
}
}

return nil
})

Expand Down
36 changes: 0 additions & 36 deletions plugins/migratecmd/migratecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ 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"
)

Expand Down Expand Up @@ -779,36 +776,3 @@ 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.Config{
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)
}
}

0 comments on commit bd95a5b

Please sign in to comment.