This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 8002f8c814caccfb050c95b82865ff65f647fab9
Author: abeizn <[email protected]>
AuthorDate: Wed Jul 20 16:48:44 2022 +0800

    fix: create_migration adapt new migration rules
---
 generator/cmd/create_migration.go                              | 10 +++++-----
 generator/template/migrationscripts/migration.go-template      |  8 ++++----
 .../migrationscripts/migration_with_config.go-template         | 10 +++++-----
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/generator/cmd/create_migration.go 
b/generator/cmd/create_migration.go
index f963e410..5417de9b 100644
--- a/generator/cmd/create_migration.go
+++ b/generator/cmd/create_migration.go
@@ -38,8 +38,8 @@ var createMigrationCmd = &cobra.Command{
        Use:   "create-migration [plugin_name/framework]",
        Short: "Create a new migration",
        Long: `Create a new migration
-Type in what the purpose of migration is, then generator will create a new 
migration in 
plugins/$plugin_name/models/migrationscripts/updateSchemasXXXXXXXX.go for you.
-If framework passed, generator will create a new migration in 
models/migrationscripts/updateSchemasXXXXXXXX.go`,
+Type in what the purpose of migration is, then generator will create a new 
migration in plugins/$plugin_name/models/migrationscripts/$date_$purpose.go for 
you.
+If framework passed, generator will create a new migration in 
models/migrationscripts/$date_$purpose.go`,
        Run: func(cmd *cobra.Command, args []string) {
                var pluginName string
                var purpose string
@@ -103,9 +103,9 @@ If framework passed, generator will create a new migration 
in models/migrationsc
                // read template
                templates := map[string]string{}
                if withConfig == `Yes` {
-                       
templates[`updateSchemas`+values[`Date`]+values[`Count`]+`.go`] = 
util.ReadTemplate("generator/template/migrationscripts/migration_with_config.go-template")
+                       templates[values[`Date`]+`_`+values[`Purpose`]+`.go`] = 
util.ReadTemplate("generator/template/migrationscripts/migration_with_config.go-template")
                } else {
-                       
templates[`updateSchemas`+values[`Date`]+values[`Count`]+`.go`] = 
util.ReadTemplate("generator/template/migrationscripts/migration.go-template")
+                       templates[values[`Date`]+`_`+values[`Purpose`]+`.go`] = 
util.ReadTemplate("generator/template/migrationscripts/migration.go-template")
                }
                values = util.DetectExistVars(templates, values)
                println(`vars in template:`, fmt.Sprint(values))
@@ -117,7 +117,7 @@ If framework passed, generator will create a new migration 
in models/migrationsc
                        util.ReplaceVarInFile(
                                filepath.Join(migrationPath, `register.go`),
                                regexp.MustCompile(`(return 
+\[]migration\.Script ?\{ ?\n?)((\s*[\w.()]+,\n?)*)(\s*})`),
-                               
fmt.Sprintf("$1$2\t\tnew(updateSchemas%s%s),\n$4", values[`Date`], 
values[`Count`]),
+                               fmt.Sprintf("$1$2\t\tnew(%s),\n$4", 
values[`Purpose`]),
                        )
                }
        },
diff --git a/generator/template/migrationscripts/migration.go-template 
b/generator/template/migrationscripts/migration.go-template
index 7d89a29d..3a93a128 100644
--- a/generator/template/migrationscripts/migration.go-template
+++ b/generator/template/migrationscripts/migration.go-template
@@ -22,17 +22,17 @@ import (
        "gorm.io/gorm"
 )
 
-type updateSchemas{{ .Date }}{{ .Count }} struct{}
+type {{ .Purpose }} struct{}
 
-func (*updateSchemas{{ .Date }}{{ .Count }}) Up(ctx context.Context, db 
*gorm.DB) error {
+func (*{{ .Purpose }}) Up(ctx context.Context, db *gorm.DB) error {
        // TODO db.Migrator()...
        return nil
 }
 
-func (*updateSchemas{{ .Date }}{{ .Count }}) Version() uint64 {
+func (*{{ .Purpose }}) Version() uint64 {
        return {{ .Date }}{{ .Count }}
 }
 
-func (*updateSchemas{{ .Date }}{{ .Count }}) Name() string {
+func (*{{ .Purpose }}) Name() string {
        return "UpdateSchemas for {{ .Purpose }} in {{ .Date }}"
 }
diff --git 
a/generator/template/migrationscripts/migration_with_config.go-template 
b/generator/template/migrationscripts/migration_with_config.go-template
index e6dae652..d4db8db5 100644
--- a/generator/template/migrationscripts/migration_with_config.go-template
+++ b/generator/template/migrationscripts/migration_with_config.go-template
@@ -24,23 +24,23 @@ import (
        "github.com/apache/incubator-devlake/plugins/core"
 )
 
-type updateSchemas{{ .Date }}{{ .Count }} struct{
+type {{ .Purpose }} struct{
        config core.ConfigGetter
 }
 
-func (u *updateSchemas{{ .Date }}{{ .Count }}) SetConfigGetter(config 
core.ConfigGetter) {
+func (u *{{ .Purpose }}) SetConfigGetter(config core.ConfigGetter) {
        u.config = config
 }
 
-func (*updateSchemas{{ .Date }}{{ .Count }}) Up(ctx context.Context, db 
*gorm.DB) error {
+func (*{{ .Purpose }}) Up(ctx context.Context, db *gorm.DB) error {
        // TODO db.Migrator()...
        return nil
 }
 
-func (*updateSchemas{{ .Date }}{{ .Count }}) Version() uint64 {
+func (*{{ .Purpose }}) Version() uint64 {
        return {{ .Date }}{{ .Count }}
 }
 
-func (*updateSchemas{{ .Date }}{{ .Count }}) Name() string {
+func (*{{ .Purpose }}) Name() string {
        return "UpdateSchemas for {{ .Purpose }} in {{ .Date }}"
 }

Reply via email to