diff --git a/CHANGELOG.md b/CHANGELOG.md index 25676179..bf84f794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,8 @@ filesystem.Serve(res, req, e.ServedPath, e.ServedName) ``` +- Fixed concurrent multi-relation cascade update/delete ([#1138](https://github.com/pocketbase/pocketbase/issues/1138)). + ## v0.8.0 diff --git a/plugins/migratecmd/automigrate.go b/plugins/migratecmd/automigrate.go index cbb56874..a31ef3f2 100644 --- a/plugins/migratecmd/automigrate.go +++ b/plugins/migratecmd/automigrate.go @@ -6,13 +6,10 @@ import ( "fmt" "os" "path/filepath" - "sort" "time" "github.com/pocketbase/pocketbase/core" - m "github.com/pocketbase/pocketbase/migrations" "github.com/pocketbase/pocketbase/models" - "github.com/pocketbase/pocketbase/tools/list" ) const collectionsCacheKey = "migratecmd_collections" @@ -31,7 +28,7 @@ func (p *plugin) afterCollectionChange() func(*core.ModelEvent) error { return err } - old, _ := oldCollections[e.Model.GetId()] + old := oldCollections[e.Model.GetId()] new, err := p.app.Dao().FindCollectionByNameOrId(e.Model.GetId()) if err != nil && !errors.Is(err, sql.ErrNoRows) { @@ -108,53 +105,3 @@ func (p *plugin) getCachedCollections() (map[string]*models.Collection, error) { return result, nil } - -// getAllMigrationNames return sorted slice with both applied and new -// local migration file names. -func (p *plugin) getAllMigrationNames() ([]string, error) { - names := []string{} - - for _, migration := range m.AppMigrations.Items() { - names = append(names, migration.File) - } - - localFiles, err := p.getLocalMigrationNames() - if err != nil { - return nil, err - } - for _, name := range localFiles { - if !list.ExistInSlice(name, names) { - names = append(names, name) - } - } - - sort.Slice(names, func(i int, j int) bool { - return names[i] < names[j] - }) - - return names, nil -} - -// getLocalMigrationNames returns a list with all local migration files -// -// Returns an empty slice if the migrations directory doesn't exist. -func (p *plugin) getLocalMigrationNames() ([]string, error) { - files, err := os.ReadDir(p.options.Dir) - if err != nil { - if os.IsNotExist(err) { - return []string{}, nil - } - return nil, err - } - - result := make([]string, 0, len(files)) - - for _, f := range files { - if f.IsDir() { - continue - } - result = append(result, f.Name()) - } - - return result, nil -} diff --git a/plugins/migratecmd/templates.go b/plugins/migratecmd/templates.go index 26265278..7665bf16 100644 --- a/plugins/migratecmd/templates.go +++ b/plugins/migratecmd/templates.go @@ -720,7 +720,7 @@ func marhshalWithoutEscape(v any, prefix string, indent string) ([]byte, error) } // unescape escaped unicode characters - unescaped, err := strconv.Unquote(strings.Replace(strconv.Quote(string(raw)), `\\u`, `\u`, -1)) + unescaped, err := strconv.Unquote(strings.ReplaceAll(strconv.Quote(string(raw)), `\\u`, `\u`)) if err != nil { return nil, err }