updated WIP:v0.9.0 changelog

This commit is contained in:
Gani Georgiev
2022-11-28 21:56:30 +02:00
parent 33539452de
commit 328b99a690
5 changed files with 103 additions and 50 deletions
+5 -12
View File
@@ -95,10 +95,10 @@ func Register(app core.App, rootCmd *cobra.Command, options *Options) error {
func (p *plugin) createCommand() *cobra.Command {
const cmdDesc = `Supported arguments are:
- up - runs all available migrations
- down [number] - reverts the last [number] applied migrations
- create name [folder] - creates new blank migration template file
- collections [folder] - creates new migration file with the latest local collections snapshot (similar to the automigrate but allows editing)
- up - runs all available migrations
- down [number] - reverts the last [number] applied migrations
- create name - creates new blank migration template file
- collections - creates new migration file with snapshot of the local collections configuration
`
command := &cobra.Command{
@@ -143,14 +143,7 @@ func (p *plugin) migrateCreateHandler(template string, args []string) error {
}
name := args[0]
var dir string
if len(args) == 2 {
dir = args[1]
}
if dir == "" {
dir = p.options.Dir
}
dir := p.options.Dir
resultFilePath := path.Join(
dir,
+3 -3
View File
@@ -164,7 +164,7 @@ func init() {
expectedName := "_created_new_name." + s.lang
if !strings.Contains(files[0].Name(), expectedName) {
t.Fatalf("Expected filename to contains %q, got %q", expectedName, files[0].Name())
t.Fatalf("[%d] Expected filename to contains %q, got %q", i, expectedName, files[0].Name())
}
fullPath := filepath.Join(migrationsDir, files[0].Name())
@@ -335,7 +335,7 @@ func init() {
expectedName := "_deleted_test456." + s.lang
if !strings.Contains(files[0].Name(), expectedName) {
t.Fatalf("Expected filename to contains %q, got %q", expectedName, files[0].Name())
t.Fatalf("[%d] Expected filename to contains %q, got %q", i, expectedName, files[0].Name())
}
fullPath := filepath.Join(migrationsDir, files[0].Name())
@@ -681,7 +681,7 @@ func init() {
expectedName := "_updated_test456." + s.lang
if !strings.Contains(files[0].Name(), expectedName) {
t.Fatalf("Expected filename to contains %q, got %q", expectedName, files[0].Name())
t.Fatalf("[%d] Expected filename to contains %q, got %q", i, expectedName, files[0].Name())
}
fullPath := filepath.Join(migrationsDir, files[0].Name())
+12 -10
View File
@@ -648,27 +648,29 @@ func (p *plugin) goDiffTemplate(new *models.Collection, old *models.Collection)
up := strings.Join(upParts, "\n\t\t")
down := strings.Join(downParts, "\n\t\t")
var optImports string
combined := up + down
// generate imports
// ---
var imports string
if strings.Contains(combined, "json.Unmarshal(") ||
strings.Contains(combined, "json.Marshal(") {
optImports += "\n\t\"encoding/json\"\n"
imports += "\n\t\"encoding/json\"\n"
}
optImports += "\n\t\"github.com/pocketbase/dbx\""
optImports += "\n\t\"github.com/pocketbase/pocketbase/daos\""
optImports += "\n\tm \"github.com/pocketbase/pocketbase/migrations\""
imports += "\n\t\"github.com/pocketbase/dbx\""
imports += "\n\t\"github.com/pocketbase/pocketbase/daos\""
imports += "\n\tm \"github.com/pocketbase/pocketbase/migrations\""
if strings.Contains(combined, "schema.SchemaField{") {
optImports += "\n\t\"github.com/pocketbase/pocketbase/models/schema\""
imports += "\n\t\"github.com/pocketbase/pocketbase/models/schema\""
}
if strings.Contains(combined, "types.Pointer(") {
optImports += "\n\t\"github.com/pocketbase/pocketbase/tools/types\""
imports += "\n\t\"github.com/pocketbase/pocketbase/tools/types\""
}
// ---
const template = `package %s
@@ -705,7 +707,7 @@ func init() {
return fmt.Sprintf(
template,
filepath.Base(p.options.Dir),
optImports,
imports,
old.Id, strings.TrimSpace(up),
new.Id, strings.TrimSpace(down),
), nil