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

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


The following commit(s) were added to refs/heads/main by this push:
     new 7c0a85f7 add generator for create-migration (#2355)
7c0a85f7 is described below

commit 7c0a85f7d18c684eb105cd020cf5bc8627105d69
Author: likyh <[email protected]>
AuthorDate: Mon Jun 27 11:23:17 2022 +0800

    add generator for create-migration (#2355)
    
    * add generate migrations
    
    * add init migration tool
    
    * use new migrations format in all plugins
    
    Co-authored-by: linyh <[email protected]>
---
 generator/README.md                                |  19 ++-
 generator/cmd/create_migration.go                  | 130 +++++++++++++++++++++
 generator/cmd/create_plugin.go                     |   3 +
 generator/cmd/init_migration.go                    |  93 +++++++++++++++
 generator/docs/generator.md                        |   2 +
 generator/docs/generator_create-migration.md       |  32 +++++
 generator/docs/generator_init-migration.md         |  31 +++++
 .../migrationscripts/init_schema.go-template       |  32 ++---
 .../migrationscripts/migration.go-template         |  31 ++---
 .../migration_with_config.go-template              |  39 ++++---
 .../template/migrationscripts/register.go-template |   8 +-
 models/migrationscripts/register.go                |   2 +-
 plugins/ae/impl/impl.go                            |   4 +-
 .../ae/models}/migrationscripts/register.go        |  14 +--
 plugins/feishu/feishu.go                           |   4 +-
 .../feishu/models}/migrationscripts/register.go    |  14 +--
 plugins/gitee/impl/impl.go                         |   4 +-
 .../gitee/models}/migrationscripts/register.go     |  14 +--
 plugins/github/impl/impl.go                        |   4 +-
 .../migrationscripts/init_schema_20220615.go       |  10 +-
 .../github/models}/migrationscripts/register.go    |   8 +-
 plugins/gitlab/impl/impl.go                        |   4 +-
 .../gitlab/models}/migrationscripts/register.go    |  14 +--
 plugins/jenkins/impl/impl.go                       |   4 +-
 .../jenkins/models}/migrationscripts/register.go   |  14 +--
 plugins/jira/impl/impl.go                          |  15 +--
 .../jira/models}/migrationscripts/register.go      |  25 ++--
 plugins/tapd/impl/impl.go                          |   2 +-
 .../tapd/models}/migrationscripts/register.go      |  14 +--
 29 files changed, 430 insertions(+), 160 deletions(-)

diff --git a/generator/README.md b/generator/README.md
index b129f940..0f1894d4 100644
--- a/generator/README.md
+++ b/generator/README.md
@@ -12,16 +12,25 @@ Help also integrate in it:
 go run generator/main.go help
 ```
 
-Usage Gif:
-![usage](https://user-images.githubusercontent.com/3294100/175464884-1dce09b0-fade-4c26-9a1b-b535d9651bc1.gif)
-
 ## Plugin Related
 
 * [create-collector](./docs/generator_create-collector.md)      - Create a new 
collector
 * [create-extractor](./docs/generator_create-extractor.md)      - Create a new 
extractor
-* [create-plugin](./docs/generator_create-plugin.md)    - Create a new plugin
+* [create-plugin](./docs/generator_create-plugin.md)
+
+Usage Gif:
+![usage](https://user-images.githubusercontent.com/3294100/175464884-1dce09b0-fade-4c26-9a1b-b535d9651bc1.gif)
+
+## Migration Related
+
+* [init-migration](./docs/generator_init-migration.md)      - Init migration 
for plugin
+* [create-migration](./docs/generator_create-migration.md)      - Create a new 
migration
+
+Usage Gif:
+![usage](https://user-images.githubusercontent.com/3294100/175537358-083809ce-9862-41f1-86e9-41448a44eaae.gif)
 
 ## Others
 
-* [completion](./docs/generator_completion.md)  - Generate the autocompletion 
script for the specified shell
+* [completion](./docs/generator_completion.md)               - Generate the 
autocompletion script for the specified shell
+* [generator-doc](./docs/generator_generator-doc.md)         - generate 
document for generator
 * [global options](./docs/generator.md)
diff --git a/generator/cmd/create_migration.go 
b/generator/cmd/create_migration.go
new file mode 100644
index 00000000..07f10b5a
--- /dev/null
+++ b/generator/cmd/create_migration.go
@@ -0,0 +1,130 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package cmd
+
+import (
+       "errors"
+       "fmt"
+       "github.com/apache/incubator-devlake/generator/util"
+       "github.com/manifoldco/promptui"
+       "github.com/spf13/cobra"
+       "io/ioutil"
+       "os"
+       "path/filepath"
+       "regexp"
+       "time"
+)
+
+func init() {
+       rootCmd.AddCommand(createMigrationCmd)
+}
+
+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`,
+       Run: func(cmd *cobra.Command, args []string) {
+               var pluginName string
+               var purpose string
+               var err error
+
+               // try to get plugin name and extractor name
+               if len(args) > 0 {
+                       pluginName = args[0]
+               }
+               if pluginName == `` {
+                       files, err := ioutil.ReadDir(`plugins`)
+                       cobra.CheckErr(err)
+                       pluginItems := []string{"framework"}
+                       for _, file := range files {
+                               if file.IsDir() {
+                                       pluginItems = append(pluginItems, 
file.Name())
+                               }
+                       }
+                       prompt := promptui.Select{
+                               Label: "plugin_name",
+                               Items: pluginItems,
+                       }
+                       _, pluginName, err = prompt.Run()
+                       cobra.CheckErr(err)
+               }
+
+               // check if migrationscripts inited
+               var migrationPath string
+               if pluginName == `framework` {
+                       migrationPath = filepath.Join(`models`, 
`migrationscripts`)
+               } else {
+                       migrationPath = filepath.Join(`plugins`, pluginName, 
`models`, `migrationscripts`)
+               }
+               _, err = os.Stat(migrationPath)
+               if os.IsNotExist(err) {
+                       cobra.CheckErr(errors.New(`migrationscripts not init. 
please run init-migration first`))
+               }
+               cobra.CheckErr(err)
+
+               prompt := promptui.Prompt{
+                       Label: "purpose",
+                       Validate: func(input string) error {
+                               if input == `` {
+                                       return errors.New("purpose requite")
+                               }
+                               return nil
+                       },
+               }
+               purpose, err = prompt.Run()
+               cobra.CheckErr(err)
+
+               selector := promptui.Select{
+                       Label: "with_config (is this migrations will use 
config?)",
+                       Items: []string{"No", "Yes"},
+               }
+               _, withConfig, err := selector.Run()
+               cobra.CheckErr(err)
+
+               // create vars
+               values := map[string]string{}
+               values[`Date`] = time.Now().Format(`20060102`)
+               values[`Purpose`] = purpose
+               existMigrations, err := ioutil.ReadDir(migrationPath)
+               cobra.CheckErr(err)
+               values[`Count`] = fmt.Sprintf(`%06d`, len(existMigrations))
+
+               // 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")
+               } else {
+                       
templates[`updateSchemas`+values[`Date`]+values[`Count`]+`.go`] = 
util.ReadTemplate("generator/template/migrationscripts/migration.go-template")
+               }
+               values = util.DetectExistVars(templates, values)
+               println(`vars in template:`, fmt.Sprint(values))
+
+               // write template
+               util.ReplaceVarInTemplates(templates, values)
+               util.WriteTemplates(migrationPath, templates)
+               if modifyExistCode {
+                       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`]),
+                       )
+               }
+       },
+}
diff --git a/generator/cmd/create_plugin.go b/generator/cmd/create_plugin.go
index 026cea13..5fce2803 100644
--- a/generator/cmd/create_plugin.go
+++ b/generator/cmd/create_plugin.go
@@ -40,6 +40,9 @@ func pluginNameNotExistValidate(input string) error {
        if !snakeNameReg.MatchString(input) {
                return errors.New("plugin name invalid (start with a-z and 
consist with a-z0-9_)")
        }
+       if strings.ToLower(input) == `framework` || strings.ToLower(input) == 
`core` || strings.ToLower(input) == `helper` {
+               return errors.New("plugin name cannot be `framework` or `core` 
or `helper`")
+       }
        _, err := os.Stat(`plugins/` + input)
        if os.IsNotExist(err) {
                return nil
diff --git a/generator/cmd/init_migration.go b/generator/cmd/init_migration.go
new file mode 100644
index 00000000..309e087a
--- /dev/null
+++ b/generator/cmd/init_migration.go
@@ -0,0 +1,93 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package cmd
+
+import (
+       "errors"
+       "fmt"
+       "github.com/apache/incubator-devlake/generator/util"
+       "github.com/manifoldco/promptui"
+       "github.com/spf13/cobra"
+       "github.com/stoewer/go-strcase"
+       "io/ioutil"
+       "os"
+       "path/filepath"
+       "time"
+)
+
+func init() {
+       rootCmd.AddCommand(initMigrationCmd)
+}
+
+var initMigrationCmd = &cobra.Command{
+       Use:   "init-migration [plugin_name]",
+       Short: "Init migration for plugin",
+       Long: `Init migration for plugin
+Type in which plugin do you want init migrations in, then generator will 
create a init migration in plugins/$plugin_name/models/migrationscripts/ for 
you.`,
+       Run: func(cmd *cobra.Command, args []string) {
+               var pluginName string
+
+               // try to get plugin name and extractor name
+               if len(args) > 0 {
+                       pluginName = args[0]
+               }
+               if pluginName == `` {
+                       files, err := ioutil.ReadDir(`plugins`)
+                       cobra.CheckErr(err)
+                       var pluginItems []string
+                       for _, file := range files {
+                               if file.IsDir() {
+                                       pluginItems = append(pluginItems, 
file.Name())
+                               }
+                       }
+                       prompt := promptui.Select{
+                               Label: "plugin_name",
+                               Items: pluginItems,
+                       }
+                       _, pluginName, err = prompt.Run()
+                       cobra.CheckErr(err)
+               }
+               migrationPath := filepath.Join(`plugins`, pluginName, `models`, 
`migrationscripts`)
+               _, err := os.Stat(migrationPath)
+               if !os.IsNotExist(err) {
+                       cobra.CheckErr(errors.New(`migrationscripts inited or 
path read file`))
+               }
+
+               // read template
+               templates := map[string]string{
+                       `initSchema.go`:     
util.ReadTemplate("generator/template/migrationscripts/init_schema.go-template"),
+                       `register.go`:       
util.ReadTemplate("generator/template/migrationscripts/register.go-template"),
+                       `archived/.gitkeep`: ``,
+               }
+
+               // create vars
+               values := map[string]string{}
+               util.GenerateAllFormatVar(values, `plugin_name`, pluginName)
+               values[`Date`] = time.Now().Format(`20060102`)
+               values = util.DetectExistVars(templates, values)
+               println(`vars in template:`, fmt.Sprint(values))
+
+               // write template
+               util.ReplaceVarInTemplates(templates, values)
+               util.WriteTemplates(migrationPath, templates)
+               if modifyExistCode {
+                       println("Last Step: add some code in plugin to 
implement Migratable like this:\n" +
+                               "func (plugin " + 
strcase.UpperCamelCase(pluginName) + ") MigrationScripts() []migration.Script 
{\n\treturn migrationscripts.All()\n}")
+               }
+       },
+}
diff --git a/generator/docs/generator.md b/generator/docs/generator.md
index 003fd86f..3e3bb0b1 100644
--- a/generator/docs/generator.md
+++ b/generator/docs/generator.md
@@ -15,7 +15,9 @@ Apache DevLake Cli Tool -- Code Generator
 * [generator completion](generator_completion.md)       - Generate the 
autocompletion script for the specified shell
 * [generator create-collector](generator_create-collector.md)   - Create a new 
collector
 * [generator create-extractor](generator_create-extractor.md)   - Create a new 
extractor
+* [generator create-migration](generator_create-migration.md)   - Create a new 
migration
 * [generator create-plugin](generator_create-plugin.md)         - Create a new 
plugin
 * [generator generator-doc](generator_generator-doc.md)         - generate 
document for generator
+* [generator init-migration](generator_init-migration.md)       - init 
migration for plugin
 
 ###### Auto generated by spf13/cobra on 24-Jun-2022
diff --git a/generator/docs/generator_create-migration.md 
b/generator/docs/generator_create-migration.md
new file mode 100644
index 00000000..95980cff
--- /dev/null
+++ b/generator/docs/generator_create-migration.md
@@ -0,0 +1,32 @@
+## generator create-migration
+
+Create a new migration
+
+### Synopsis
+
+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
+
+```
+generator create-migration [plugin_name/framework] [flags]
+```
+
+### Options
+
+```
+  -h, --help   help for create-migration
+```
+
+### Options inherited from parent commands
+
+```
+      --config string     config file (default is PROJECT/.env)
+      --modifyExistCode   allow generator modify exist code (default true)
+```
+
+### SEE ALSO
+
+* [generator](generator.md)     - Apache DevLake Cli Tool -- Code Generator
+
+###### Auto generated by spf13/cobra on 24-Jun-2022
diff --git a/generator/docs/generator_init-migration.md 
b/generator/docs/generator_init-migration.md
new file mode 100644
index 00000000..011a80a4
--- /dev/null
+++ b/generator/docs/generator_init-migration.md
@@ -0,0 +1,31 @@
+## generator init-migration
+
+init migration for plugin
+
+### Synopsis
+
+init migration for plugin
+Type in which plugin do you want init migrations in, then generator will 
create a init migration in plugins/$plugin_name/models/migrationscripts/ for 
you.
+
+```
+generator init-migration [plugin_name] [flags]
+```
+
+### Options
+
+```
+  -h, --help   help for init-migration
+```
+
+### Options inherited from parent commands
+
+```
+      --config string     config file (default is PROJECT/.env)
+      --modifyExistCode   allow generator modify exist code (default true)
+```
+
+### SEE ALSO
+
+* [generator](generator.md)     - Apache DevLake Cli Tool -- Code Generator
+
+###### Auto generated by spf13/cobra on 24-Jun-2022
diff --git a/models/migrationscripts/register.go 
b/generator/template/migrationscripts/init_schema.go-template
similarity index 54%
copy from models/migrationscripts/register.go
copy to generator/template/migrationscripts/init_schema.go-template
index 9f39472c..1ab56bcc 100644
--- a/models/migrationscripts/register.go
+++ b/generator/template/migrationscripts/init_schema.go-template
@@ -17,17 +17,23 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
-
-// RegisterAll register all the migration scripts of framework
-func All() []migration.Script {
-       return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
-       }
+import (
+       "context"
+       "gorm.io/gorm"
+)
+
+type initSchemas struct {}
+
+func (u *initSchemas) Up(ctx context.Context, db *gorm.DB) error {
+       return db.Migrator().AutoMigrate(
+               // TODO add you models
+       )
+}
+
+func (*initSchemas) Version() uint64 {
+       return {{ .Date }}000001
+}
+
+func (*initSchemas) Name() string {
+       return "{{ .pluginName }} init schemas {{ .Date }}"
 }
diff --git a/models/migrationscripts/register.go 
b/generator/template/migrationscripts/migration.go-template
similarity index 54%
copy from models/migrationscripts/register.go
copy to generator/template/migrationscripts/migration.go-template
index 9f39472c..7d89a29d 100644
--- a/models/migrationscripts/register.go
+++ b/generator/template/migrationscripts/migration.go-template
@@ -17,17 +17,22 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
-
-// RegisterAll register all the migration scripts of framework
-func All() []migration.Script {
-       return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
-       }
+import (
+       "context"
+       "gorm.io/gorm"
+)
+
+type updateSchemas{{ .Date }}{{ .Count }} struct{}
+
+func (*updateSchemas{{ .Date }}{{ .Count }}) Up(ctx context.Context, db 
*gorm.DB) error {
+       // TODO db.Migrator()...
+       return nil
+}
+
+func (*updateSchemas{{ .Date }}{{ .Count }}) Version() uint64 {
+       return {{ .Date }}{{ .Count }}
+}
+
+func (*updateSchemas{{ .Date }}{{ .Count }}) Name() string {
+       return "UpdateSchemas for {{ .Purpose }} in {{ .Date }}"
 }
diff --git a/models/migrationscripts/register.go 
b/generator/template/migrationscripts/migration_with_config.go-template
similarity index 54%
copy from models/migrationscripts/register.go
copy to generator/template/migrationscripts/migration_with_config.go-template
index 9f39472c..e6dae652 100644
--- a/models/migrationscripts/register.go
+++ b/generator/template/migrationscripts/migration_with_config.go-template
@@ -17,17 +17,30 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
-
-// RegisterAll register all the migration scripts of framework
-func All() []migration.Script {
-       return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
-       }
+import (
+       "context"
+       "gorm.io/gorm"
+
+       "github.com/apache/incubator-devlake/plugins/core"
+)
+
+type updateSchemas{{ .Date }}{{ .Count }} struct{
+       config core.ConfigGetter
+}
+
+func (u *updateSchemas{{ .Date }}{{ .Count }}) SetConfigGetter(config 
core.ConfigGetter) {
+       u.config = config
+}
+
+func (*updateSchemas{{ .Date }}{{ .Count }}) Up(ctx context.Context, db 
*gorm.DB) error {
+       // TODO db.Migrator()...
+       return nil
+}
+
+func (*updateSchemas{{ .Date }}{{ .Count }}) Version() uint64 {
+       return {{ .Date }}{{ .Count }}
+}
+
+func (*updateSchemas{{ .Date }}{{ .Count }}) Name() string {
+       return "UpdateSchemas for {{ .Purpose }} in {{ .Date }}"
 }
diff --git a/models/migrationscripts/register.go 
b/generator/template/migrationscripts/register.go-template
similarity index 63%
copy from models/migrationscripts/register.go
copy to generator/template/migrationscripts/register.go-template
index 9f39472c..51152508 100644
--- a/models/migrationscripts/register.go
+++ b/generator/template/migrationscripts/register.go-template
@@ -19,15 +19,9 @@ package migrationscripts
 
 import "github.com/apache/incubator-devlake/migration"
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
                new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
        }
 }
diff --git a/models/migrationscripts/register.go 
b/models/migrationscripts/register.go
index 9f39472c..f4585a2d 100644
--- a/models/migrationscripts/register.go
+++ b/models/migrationscripts/register.go
@@ -19,7 +19,7 @@ package migrationscripts
 
 import "github.com/apache/incubator-devlake/migration"
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts of framework
 func All() []migration.Script {
        return []migration.Script{
                new(initSchemas),
diff --git a/plugins/ae/impl/impl.go b/plugins/ae/impl/impl.go
index 21ee9df0..e567ecf3 100644
--- a/plugins/ae/impl/impl.go
+++ b/plugins/ae/impl/impl.go
@@ -99,9 +99,7 @@ func (plugin AE) RootPkgPath() string {
 }
 
 func (plugin AE) MigrationScripts() []migration.Script {
-       return []migration.Script{
-               new(migrationscripts.InitSchemas),
-       }
+       return migrationscripts.All()
 }
 
 func (plugin AE) ApiResources() map[string]map[string]core.ApiResourceHandler {
diff --git a/models/migrationscripts/register.go 
b/plugins/ae/models/migrationscripts/register.go
similarity index 58%
copy from models/migrationscripts/register.go
copy to plugins/ae/models/migrationscripts/register.go
index 9f39472c..06d924d0 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/ae/models/migrationscripts/register.go
@@ -17,17 +17,13 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "github.com/apache/incubator-devlake/migration"
+)
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
+               new(InitSchemas),
        }
 }
diff --git a/plugins/feishu/feishu.go b/plugins/feishu/feishu.go
index b5a5828f..1bce30e9 100644
--- a/plugins/feishu/feishu.go
+++ b/plugins/feishu/feishu.go
@@ -73,9 +73,7 @@ func (plugin Feishu) RootPkgPath() string {
 }
 
 func (plugin Feishu) MigrationScripts() []migration.Script {
-       return []migration.Script{
-               new(migrationscripts.InitSchemas), 
new(migrationscripts.UpdateSchemas20220524),
-       }
+       return migrationscripts.All()
 }
 
 func (plugin Feishu) ApiResources() 
map[string]map[string]core.ApiResourceHandler {
diff --git a/models/migrationscripts/register.go 
b/plugins/feishu/models/migrationscripts/register.go
similarity index 58%
copy from models/migrationscripts/register.go
copy to plugins/feishu/models/migrationscripts/register.go
index 9f39472c..57d8ea48 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/feishu/models/migrationscripts/register.go
@@ -17,17 +17,13 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "github.com/apache/incubator-devlake/migration"
+)
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
+               new(InitSchemas), new(UpdateSchemas20220524),
        }
 }
diff --git a/plugins/gitee/impl/impl.go b/plugins/gitee/impl/impl.go
index c7589f66..94cdddb0 100644
--- a/plugins/gitee/impl/impl.go
+++ b/plugins/gitee/impl/impl.go
@@ -167,9 +167,7 @@ func (plugin Gitee) RootPkgPath() string {
 }
 
 func (plugin Gitee) MigrationScripts() []migration.Script {
-       return []migration.Script{
-               new(migrationscripts.InitSchemas),
-       }
+       return migrationscripts.All()
 }
 
 func (plugin Gitee) ApiResources() 
map[string]map[string]core.ApiResourceHandler {
diff --git a/models/migrationscripts/register.go 
b/plugins/gitee/models/migrationscripts/register.go
similarity index 58%
copy from models/migrationscripts/register.go
copy to plugins/gitee/models/migrationscripts/register.go
index 9f39472c..06d924d0 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/gitee/models/migrationscripts/register.go
@@ -17,17 +17,13 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "github.com/apache/incubator-devlake/migration"
+)
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
+               new(InitSchemas),
        }
 }
diff --git a/plugins/github/impl/impl.go b/plugins/github/impl/impl.go
index 142d49c2..7f5a5ccd 100644
--- a/plugins/github/impl/impl.go
+++ b/plugins/github/impl/impl.go
@@ -113,9 +113,7 @@ func (plugin Github) RootPkgPath() string {
 }
 
 func (plugin Github) MigrationScripts() []migration.Script {
-       return []migration.Script{
-               new(migrationscripts.InitSchemas),
-       }
+       return migrationscripts.All()
 }
 
 func (plugin Github) ApiResources() 
map[string]map[string]core.ApiResourceHandler {
diff --git a/plugins/github/models/migrationscripts/init_schema_20220615.go 
b/plugins/github/models/migrationscripts/init_schema_20220615.go
index d1832a2c..532bcaac 100644
--- a/plugins/github/models/migrationscripts/init_schema_20220615.go
+++ b/plugins/github/models/migrationscripts/init_schema_20220615.go
@@ -40,15 +40,15 @@ func (GithubConnection20220615) TableName() string {
        return "_tool_github_connections"
 }
 
-type InitSchemas struct {
+type initSchemas struct {
        config core.ConfigGetter
 }
 
-func (u *InitSchemas) SetConfigGetter(config core.ConfigGetter) {
+func (u *initSchemas) SetConfigGetter(config core.ConfigGetter) {
        u.config = config
 }
 
-func (u *InitSchemas) Up(ctx context.Context, db *gorm.DB) error {
+func (u *initSchemas) Up(ctx context.Context, db *gorm.DB) error {
        if db.Migrator().HasTable(GithubConnection20220615{}) {
                err := db.Migrator().DropTable(GithubConnection20220615{})
                if err != nil {
@@ -128,10 +128,10 @@ func (u *InitSchemas) Up(ctx context.Context, db 
*gorm.DB) error {
        )
 }
 
-func (*InitSchemas) Version() uint64 {
+func (*initSchemas) Version() uint64 {
        return 20220615000001
 }
 
-func (*InitSchemas) Name() string {
+func (*initSchemas) Name() string {
        return "Github init schemas 20220611"
 }
diff --git a/models/migrationscripts/register.go 
b/plugins/github/models/migrationscripts/register.go
similarity index 63%
copy from models/migrationscripts/register.go
copy to plugins/github/models/migrationscripts/register.go
index 9f39472c..51152508 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/github/models/migrationscripts/register.go
@@ -19,15 +19,9 @@ package migrationscripts
 
 import "github.com/apache/incubator-devlake/migration"
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
                new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
        }
 }
diff --git a/plugins/gitlab/impl/impl.go b/plugins/gitlab/impl/impl.go
index c2bc16ff..3fd2908c 100644
--- a/plugins/gitlab/impl/impl.go
+++ b/plugins/gitlab/impl/impl.go
@@ -116,9 +116,7 @@ func (plugin Gitlab) RootPkgPath() string {
 }
 
 func (plugin Gitlab) MigrationScripts() []migration.Script {
-       return []migration.Script{
-               new(migrationscripts.InitSchemas),
-       }
+       return migrationscripts.All()
 }
 
 func (plugin Gitlab) MakePipelinePlan(connectionId uint64, scope 
[]*core.BlueprintScopeV100) (core.PipelinePlan, error) {
diff --git a/models/migrationscripts/register.go 
b/plugins/gitlab/models/migrationscripts/register.go
similarity index 58%
copy from models/migrationscripts/register.go
copy to plugins/gitlab/models/migrationscripts/register.go
index 9f39472c..06d924d0 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/gitlab/models/migrationscripts/register.go
@@ -17,17 +17,13 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "github.com/apache/incubator-devlake/migration"
+)
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
+               new(InitSchemas),
        }
 }
diff --git a/plugins/jenkins/impl/impl.go b/plugins/jenkins/impl/impl.go
index bb0885f5..bebf0180 100644
--- a/plugins/jenkins/impl/impl.go
+++ b/plugins/jenkins/impl/impl.go
@@ -96,9 +96,7 @@ func (plugin Jenkins) RootPkgPath() string {
 }
 
 func (plugin Jenkins) MigrationScripts() []migration.Script {
-       return []migration.Script{
-               new(migrationscripts.InitSchemas),
-       }
+       return migrationscripts.All()
 }
 
 func (plugin Jenkins) MakePipelinePlan(connectionId uint64, scope 
[]*core.BlueprintScopeV100) (core.PipelinePlan, error) {
diff --git a/models/migrationscripts/register.go 
b/plugins/jenkins/models/migrationscripts/register.go
similarity index 58%
copy from models/migrationscripts/register.go
copy to plugins/jenkins/models/migrationscripts/register.go
index 9f39472c..06d924d0 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/jenkins/models/migrationscripts/register.go
@@ -17,17 +17,13 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "github.com/apache/incubator-devlake/migration"
+)
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
+               new(InitSchemas),
        }
 }
diff --git a/plugins/jira/impl/impl.go b/plugins/jira/impl/impl.go
index 582b29a8..f61035d1 100644
--- a/plugins/jira/impl/impl.go
+++ b/plugins/jira/impl/impl.go
@@ -156,20 +156,7 @@ func (plugin Jira) RootPkgPath() string {
 }
 
 func (plugin Jira) MigrationScripts() []migration.Script {
-       return []migration.Script{
-               new(migrationscripts.InitSchemas),
-               new(migrationscripts.UpdateSchemas20220505),
-               new(migrationscripts.UpdateSchemas20220507),
-               new(migrationscripts.UpdateSchemas20220518),
-               new(migrationscripts.UpdateSchemas20220525),
-               new(migrationscripts.UpdateSchemas20220526),
-               new(migrationscripts.UpdateSchemas20220527),
-               new(migrationscripts.UpdateSchemas20220601),
-               new(migrationscripts.UpdateSchemas20220614),
-               new(migrationscripts.UpdateSchemas20220615),
-               new(migrationscripts.UpdateSchemas20220616),
-               new(migrationscripts.UpdateSchemas20220620),
-       }
+       return migrationscripts.All()
 }
 
 func (plugin Jira) ApiResources() 
map[string]map[string]core.ApiResourceHandler {
diff --git a/models/migrationscripts/register.go 
b/plugins/jira/models/migrationscripts/register.go
similarity index 58%
copy from models/migrationscripts/register.go
copy to plugins/jira/models/migrationscripts/register.go
index 9f39472c..e3fcd0b4 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/jira/models/migrationscripts/register.go
@@ -17,17 +17,24 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "github.com/apache/incubator-devlake/migration"
+)
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
+               new(InitSchemas),
+               new(UpdateSchemas20220505),
+               new(UpdateSchemas20220507),
+               new(UpdateSchemas20220518),
+               new(UpdateSchemas20220525),
+               new(UpdateSchemas20220526),
+               new(UpdateSchemas20220527),
+               new(UpdateSchemas20220601),
+               new(UpdateSchemas20220614),
+               new(UpdateSchemas20220615),
+               new(UpdateSchemas20220616),
+               new(UpdateSchemas20220620),
        }
 }
diff --git a/plugins/tapd/impl/impl.go b/plugins/tapd/impl/impl.go
index 26222a73..9e4b7247 100644
--- a/plugins/tapd/impl/impl.go
+++ b/plugins/tapd/impl/impl.go
@@ -168,7 +168,7 @@ func (plugin Tapd) RootPkgPath() string {
 }
 
 func (plugin Tapd) MigrationScripts() []migration.Script {
-       return []migration.Script{new(migrationscripts.InitSchemas)}
+       return migrationscripts.All()
 }
 
 func (plugin Tapd) ApiResources() 
map[string]map[string]core.ApiResourceHandler {
diff --git a/models/migrationscripts/register.go 
b/plugins/tapd/models/migrationscripts/register.go
similarity index 58%
copy from models/migrationscripts/register.go
copy to plugins/tapd/models/migrationscripts/register.go
index 9f39472c..06d924d0 100644
--- a/models/migrationscripts/register.go
+++ b/plugins/tapd/models/migrationscripts/register.go
@@ -17,17 +17,13 @@ limitations under the License.
 
 package migrationscripts
 
-import "github.com/apache/incubator-devlake/migration"
+import (
+       "github.com/apache/incubator-devlake/migration"
+)
 
-// RegisterAll register all the migration scripts of framework
+// All return all the migration scripts
 func All() []migration.Script {
        return []migration.Script{
-               new(initSchemas),
-               new(updateSchemas20220505), new(updateSchemas20220507), 
new(updateSchemas20220510),
-               new(updateSchemas20220513), new(updateSchemas20220524), 
new(updateSchemas20220526),
-               new(updateSchemas20220527), new(updateSchemas20220528), 
new(updateSchemas20220601),
-               new(updateSchemas20220602), new(updateSchemas20220612), 
new(updateSchemas20220613),
-               new(updateSchemas20220614), new(updateSchemas2022061402), 
new(updateSchemas20220616),
-               new(blueprintNormalMode),
+               new(InitSchemas),
        }
 }

Reply via email to