api_migrate.template 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. package version
  2. import (
  3. "gorm.io/gorm"
  4. "runtime"
  5. "time"
  6. "github.com/go-admin-team/go-admin-core/sdk/pkg"
  7. "go-admin/cmd/migrate/migration"
  8. common "go-admin/common/models"
  9. )
  10. type Menu struct {
  11. MenuId int `json:"menuId" gorm:"primaryKey;autoIncrement"`
  12. MenuName string `json:"menuName" gorm:"size:128;"`
  13. Title string `json:"title" gorm:"size:128;"`
  14. Icon string `json:"icon" gorm:"size:128;"`
  15. Path string `json:"path" gorm:"size:128;"`
  16. Paths string `json:"paths" gorm:"size:128;"`
  17. MenuType string `json:"menuType" gorm:"size:1;"`
  18. Action string `json:"action" gorm:"size:16;"`
  19. Permission string `json:"permission" gorm:"size:255;"`
  20. ParentId int `json:"parentId" gorm:"size:11;"`
  21. NoCache bool `json:"noCache" gorm:"size:8;"`
  22. Breadcrumb string `json:"breadcrumb" gorm:"size:255;"`
  23. Component string `json:"component" gorm:"size:255;"`
  24. Sort int `json:"sort" gorm:"size:4;"`
  25. Visible string `json:"visible" gorm:"size:1;"`
  26. CreateBy string `json:"createBy" gorm:"size:128;"`
  27. UpdateBy string `json:"updateBy" gorm:"size:128;"`
  28. IsFrame string `json:"isFrame" gorm:"size:1;DEFAULT:0;"`
  29. CreatedAt time.Time `json:"createdAt"`
  30. UpdatedAt time.Time `json:"updatedAt"`
  31. DeletedAt *time.Time `json:"deletedAt"`
  32. }
  33. func (Menu) TableName() string {
  34. return "sys_menu"
  35. }
  36. func init() {
  37. _, fileName, _, _ := runtime.Caller(0)
  38. migration.Migrate.SetVersion(migration.GetFilename(fileName), _{{.GenerateTime}}Test)
  39. }
  40. func _{{.GenerateTime}}Test(db *gorm.DB, version string) error {
  41. return db.Transaction(func(tx *gorm.DB) error {
  42. timeNow := pkg.GetCurrentTime()
  43. Mmenu := Menu{}
  44. Mmenu.MenuName = "{{.TBName}}Manage"
  45. Mmenu.Title = "{{.TableComment}}"
  46. Mmenu.Icon = "pass"
  47. Mmenu.Path = "/{{.TBName}}"
  48. Mmenu.MenuType = "M"
  49. Mmenu.Action = "无"
  50. Mmenu.ParentId = 0
  51. Mmenu.NoCache = false
  52. Mmenu.Component = "Layout"
  53. Mmenu.Sort = 0
  54. Mmenu.Visible = "0"
  55. Mmenu.IsFrame = "0"
  56. Mmenu.CreateBy = "1"
  57. Mmenu.UpdateBy = "1"
  58. Mmenu.CreatedAt = timeNow
  59. Mmenu.UpdatedAt = timeNow
  60. // Mmenu.MenuId, err = Mmenu.Create(db)
  61. err := tx.Create(&Mmenu).Error
  62. if err != nil {
  63. return err
  64. }
  65. Cmenu := Menu{}
  66. Cmenu.MenuName = "{{.TBName}}"
  67. Cmenu.Title = "{{.TableComment}}"
  68. Cmenu.Icon = "pass"
  69. Cmenu.Path = "{{.TBName}}"
  70. Cmenu.MenuType = "C"
  71. Cmenu.Action = "无"
  72. Cmenu.Permission = "{{.PackageName}}:{{.BusinessName}}:list"
  73. Cmenu.ParentId = Mmenu.MenuId
  74. Cmenu.NoCache = false
  75. Cmenu.Component = "/{{.BusinessName}}/index"
  76. Cmenu.Sort = 0
  77. Cmenu.Visible = "0"
  78. Cmenu.IsFrame = "0"
  79. Cmenu.CreateBy = "1"
  80. Cmenu.UpdateBy = "1"
  81. Cmenu.CreatedAt = timeNow
  82. Cmenu.UpdatedAt = timeNow
  83. // Cmenu.MenuId, err = Cmenu.Create(db)
  84. err = tx.Create(&Cmenu).Error
  85. if err != nil {
  86. return err
  87. }
  88. MList := Menu{}
  89. MList.MenuName = ""
  90. MList.Title = "分页获取{{.TableComment}}"
  91. MList.Icon = ""
  92. MList.Path = "{{.TBName}}"
  93. MList.MenuType = "F"
  94. MList.Action = "无"
  95. MList.Permission = "{{.PackageName}}:{{.BusinessName}}:query"
  96. MList.ParentId = Cmenu.MenuId
  97. MList.NoCache = false
  98. MList.Sort = 0
  99. MList.Visible = "0"
  100. MList.IsFrame = "0"
  101. MList.CreateBy = "1"
  102. MList.UpdateBy = "1"
  103. MList.CreatedAt = timeNow
  104. MList.UpdatedAt = timeNow
  105. // MList.MenuId, err = MList.Create(db)
  106. err = tx.Create(&MList).Error
  107. if err != nil {
  108. return err
  109. }
  110. MCreate := Menu{}
  111. MCreate.MenuName = ""
  112. MCreate.Title = "创建{{.TableComment}}"
  113. MCreate.Icon = ""
  114. MCreate.Path = "{{.TBName}}"
  115. MCreate.MenuType = "F"
  116. MCreate.Action = "无"
  117. MCreate.Permission = "{{.PackageName}}:{{.BusinessName}}:add"
  118. MCreate.ParentId = Cmenu.MenuId
  119. MCreate.NoCache = false
  120. MCreate.Sort = 0
  121. MCreate.Visible = "0"
  122. MCreate.IsFrame = "0"
  123. MCreate.CreateBy = "1"
  124. MCreate.UpdateBy = "1"
  125. MCreate.CreatedAt = timeNow
  126. MCreate.UpdatedAt = timeNow
  127. // MCreate.MenuId, err = MCreate.Create(db)
  128. err = tx.Create(&MCreate).Error
  129. if err != nil {
  130. return err
  131. }
  132. MUpdate := Menu{}
  133. MUpdate.MenuName = ""
  134. MUpdate.Title = "修改{{.TableComment}}"
  135. MUpdate.Icon = ""
  136. MUpdate.Path = "{{.TBName}}"
  137. MUpdate.MenuType = "F"
  138. MUpdate.Action = "无"
  139. MUpdate.Permission ="{{.PackageName}}:{{.BusinessName}}:edit"
  140. MUpdate.ParentId = Cmenu.MenuId
  141. MUpdate.NoCache = false
  142. MUpdate.Sort = 0
  143. MUpdate.Visible = "0"
  144. MUpdate.IsFrame = "0"
  145. MUpdate.CreateBy = "1"
  146. MUpdate.UpdateBy = "1"
  147. MUpdate.CreatedAt = timeNow
  148. MUpdate.UpdatedAt = timeNow
  149. // MUpdate.MenuId, err = MUpdate.Create(db)
  150. err = tx.Create(&MUpdate).Error
  151. if err != nil {
  152. return err
  153. }
  154. MDelete := Menu{}
  155. MDelete.MenuName = ""
  156. MDelete.Title = "删除{{.TableComment}}"
  157. MDelete.Icon = ""
  158. MDelete.Path = "{{.TBName}}"
  159. MDelete.MenuType = "F"
  160. MDelete.Action = "无"
  161. MDelete.Permission = "{{.PackageName}}:{{.BusinessName}}:remove"
  162. MDelete.ParentId = Cmenu.MenuId
  163. MDelete.NoCache = false
  164. MDelete.Sort = 0
  165. MDelete.Visible = "0"
  166. MDelete.IsFrame = "0"
  167. MDelete.CreateBy = "1"
  168. MDelete.UpdateBy = "1"
  169. MDelete.CreatedAt = timeNow
  170. MDelete.UpdatedAt = timeNow
  171. // MDelete.MenuId, err = MDelete.Create(db)
  172. err = tx.Create(&MDelete).Error
  173. if err != nil {
  174. return err
  175. }
  176. var InterfaceId = 63
  177. Amenu := Menu{}
  178. Amenu.MenuName = "{{.TBName}}"
  179. Amenu.Title = "{{.TableComment}}"
  180. Amenu.Icon = "bug"
  181. Amenu.Path = "{{.TBName}}"
  182. Amenu.MenuType = "M"
  183. Amenu.Action = "无"
  184. Amenu.ParentId = InterfaceId
  185. Amenu.NoCache = false
  186. Amenu.Sort = 0
  187. Amenu.Visible = "1"
  188. Amenu.IsFrame = "0"
  189. Amenu.CreateBy = "1"
  190. Amenu.UpdateBy = "1"
  191. Amenu.CreatedAt = timeNow
  192. Amenu.UpdatedAt = timeNow
  193. // Amenu.MenuId, err = Amenu.Create(db)
  194. err = tx.Create(&Amenu).Error
  195. if err != nil {
  196. return err
  197. }
  198. AList := Menu{}
  199. AList.MenuName = ""
  200. AList.Title = "分页获取{{.TableComment}}"
  201. AList.Icon = "bug"
  202. AList.Path = "/api/v1/{{.ModuleName}}"
  203. AList.MenuType = "A"
  204. AList.Action = "GET"
  205. AList.ParentId = Amenu.MenuId
  206. AList.NoCache = false
  207. AList.Sort = 0
  208. AList.Visible = "1"
  209. AList.IsFrame = "0"
  210. AList.CreateBy = "1"
  211. AList.UpdateBy = "1"
  212. AList.CreatedAt = timeNow
  213. AList.UpdatedAt = timeNow
  214. // AList.MenuId, err = AList.Create(db)
  215. err = tx.Create(&AList).Error
  216. if err != nil {
  217. return err
  218. }
  219. AGet := Menu{}
  220. AGet.MenuName = ""
  221. AGet.Title = "根据id获取{{.TableComment}}"
  222. AGet.Icon = "bug"
  223. AGet.Path = "/api/v1/{{.ModuleName}}/:id"
  224. AGet.MenuType = "A"
  225. AGet.Action = "GET"
  226. AGet.ParentId = Amenu.MenuId
  227. AGet.NoCache = false
  228. AGet.Sort = 0
  229. AGet.Visible = "1"
  230. AGet.IsFrame = "0"
  231. AGet.CreateBy = "1"
  232. AGet.UpdateBy = "1"
  233. AGet.CreatedAt = timeNow
  234. AGet.UpdatedAt = timeNow
  235. // AGet.MenuId, err = AGet.Create(db)
  236. err = tx.Create(&AGet).Error
  237. if err != nil {
  238. return err
  239. }
  240. ACreate := Menu{}
  241. ACreate.MenuName = ""
  242. ACreate.Title = "创建{{.TableComment}}"
  243. ACreate.Icon = "bug"
  244. ACreate.Path = "/api/v1/{{.ModuleName}}"
  245. ACreate.MenuType = "A"
  246. ACreate.Action = "POST"
  247. ACreate.ParentId = Amenu.MenuId
  248. ACreate.NoCache = false
  249. ACreate.Sort = 0
  250. ACreate.Visible = "1"
  251. ACreate.IsFrame = "0"
  252. ACreate.CreateBy = "1"
  253. ACreate.UpdateBy = "1"
  254. ACreate.CreatedAt = timeNow
  255. ACreate.UpdatedAt = timeNow
  256. // ACreate.MenuId, err = ACreate.Create(db)
  257. err = tx.Create(&ACreate).Error
  258. if err != nil {
  259. return err
  260. }
  261. AUpdate := Menu{}
  262. AUpdate.MenuName = ""
  263. AUpdate.Title = "修改{{.TableComment}}"
  264. AUpdate.Icon = "bug"
  265. AUpdate.Path = "/api/v1/{{.ModuleName}}/:id"
  266. AUpdate.MenuType = "A"
  267. AUpdate.Action = "PUT"
  268. AUpdate.ParentId = Amenu.MenuId
  269. AUpdate.NoCache = false
  270. AUpdate.Sort = 0
  271. AUpdate.Visible = "1"
  272. AUpdate.IsFrame = "0"
  273. AUpdate.CreateBy = "1"
  274. AUpdate.UpdateBy = "1"
  275. AUpdate.CreatedAt = timeNow
  276. AUpdate.UpdatedAt = timeNow
  277. // AUpdate.MenuId, err = AUpdate.Create(db)
  278. err = tx.Create(&AUpdate).Error
  279. if err != nil {
  280. return err
  281. }
  282. ADelete := Menu{}
  283. ADelete.MenuName = ""
  284. ADelete.Title = "删除{{.TableComment}}"
  285. ADelete.Icon = "bug"
  286. ADelete.Path = "/api/v1/{{.ModuleName}}"
  287. ADelete.MenuType = "A"
  288. ADelete.Action = "DELETE"
  289. ADelete.ParentId = Amenu.MenuId
  290. ADelete.NoCache = false
  291. ADelete.Sort = 0
  292. ADelete.Visible = "1"
  293. ADelete.IsFrame = "0"
  294. ADelete.CreateBy = "1"
  295. ADelete.UpdateBy = "1"
  296. ADelete.CreatedAt = timeNow
  297. ADelete.UpdatedAt = timeNow
  298. //ADelete.MenuId, err = ADelete.Create(db)
  299. err = tx.Create(&ADelete).Error
  300. if err != nil {
  301. return err
  302. }
  303. return tx.Create(&common.Migration{
  304. Version: version,
  305. }).Error
  306. })
  307. }