initdb.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright © 2020 SliverHorn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package gva
  14. import (
  15. "gin-vue-admin/cmd/datas"
  16. "gin-vue-admin/core"
  17. "gin-vue-admin/initialize"
  18. "github.com/gookit/color"
  19. _ "gin-vue-admin/core"
  20. "gin-vue-admin/global"
  21. "github.com/spf13/cobra"
  22. )
  23. // initdbCmd represents the initdb command
  24. var initdbCmd = &cobra.Command{
  25. Use: "initdb",
  26. Short: "gin-vue-admin初始化数据",
  27. Long: `gin-vue-admin初始化数据适配数据库情况:
  28. 1. mysql完美适配,
  29. 2. postgresql不能保证完美适配,
  30. 3. sqlite未适配,
  31. 4. sqlserver未适配`,
  32. Run: func(cmd *cobra.Command, args []string) {
  33. path, _ := cmd.Flags().GetString("path")
  34. core.Viper(path)
  35. db := initialize.GormMysql()
  36. switch global.GVA_CONFIG.System.DbType {
  37. case "mysql":
  38. datas.InitMysqlTables(db)
  39. datas.InitMysqlData(db)
  40. case "postgresql":
  41. datas.InitPostgresqlTables(db)
  42. datas.InitPostgresqlData(db)
  43. case "sqlite":
  44. color.Info.Println("sqlite功能开发中")
  45. case "sqlserver":
  46. color.Info.Println("sqlserver功能开发中")
  47. default:
  48. datas.InitMysqlTables(db)
  49. datas.InitMysqlData(db)
  50. color.Info.Println("sqlserver功能开发中")
  51. }
  52. frame, _ := cmd.Flags().GetString("frame")
  53. if frame == "gf" {
  54. color.Info.Println("gf功能开发中")
  55. return
  56. } else {
  57. return
  58. }
  59. },
  60. }
  61. func init() {
  62. rootCmd.AddCommand(initdbCmd)
  63. initdbCmd.Flags().StringP("path", "p", "./config.yaml", "自定配置文件路径(绝对路径)")
  64. initdbCmd.Flags().StringP("frame", "f", "gin", "可选参数为gin,gf")
  65. initdbCmd.Flags().StringP("type", "t", "mysql", "可选参数为mysql,postgresql,sqlite,sqlserver")
  66. }