You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-11-25 23:52:32 +02:00
fixed autogenerated go collection update migration template
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
@@ -59,11 +60,11 @@ func (p *plugin) automigrateOnCollectionChange(e *core.CollectionRequestEvent) e
|
||||
var action string
|
||||
switch {
|
||||
case new == nil:
|
||||
action = "deleted_" + old.Name
|
||||
action = "deleted_" + normalizeCollectionName(old.Name)
|
||||
case old == nil:
|
||||
action = "created_" + new.Name
|
||||
action = "created_" + normalizeCollectionName(new.Name)
|
||||
default:
|
||||
action = "updated_" + old.Name
|
||||
action = "updated_" + normalizeCollectionName(old.Name)
|
||||
}
|
||||
|
||||
name := fmt.Sprintf("%d_%s.%s", time.Now().Unix(), action, p.config.TemplateLang)
|
||||
@@ -93,3 +94,13 @@ func (p *plugin) automigrateOnCollectionChange(e *core.CollectionRequestEvent) e
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func normalizeCollectionName(name string) string {
|
||||
// adds an extra "_" suffix to the name in case the collection ends
|
||||
// with "test" to prevent accidentally resulting in "_test.go"/"_test.js" files
|
||||
if strings.HasSuffix(strings.ToLower(name), "test") {
|
||||
name += "_"
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user