add tables

This commit is contained in:
yanghao05
2023-01-31 16:58:35 +08:00
parent 05622922e9
commit e0191e30c1
22 changed files with 3069 additions and 484 deletions

View File

@@ -0,0 +1,56 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"github.com/gofrs/uuid"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_160904CreateUserMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_160904CreateUser struct {
id string
}
func New20230131_160904CreateUserMigration() contracts.Migration {
return &Migration20230131_160904CreateUser{id: "20230131_160904_create_user"}
}
func (m *Migration20230131_160904CreateUser) ID() string {
return m.id
}
func (m *Migration20230131_160904CreateUser) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_160904CreateUser) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_160904CreateUser) table() interface{} {
type User struct {
gorm.Model
UUID uuid.UUID `gorm:"index;comment:UUID"`
Username string `gorm:"index;comment:登录名"`
Password string `gorm:"comment:登录密码"`
Nickname string `gorm:"default:'';comment:昵称"`
Avatar string `gorm:"default:'';comment:头像"`
RoleID uint `gorm:"default:1;comment:角色ID"`
Phone string `gorm:"comment:手机号"`
Email string `gorm:"comment:邮箱"`
Status string `gorm:"default:ok;comment:用户状态"` // OK,BLOCKED,DISABLED,
}
return User{}
}

View File

@@ -0,0 +1,50 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_162400CreateSysApiMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_162400CreateSysApi struct {
id string
}
func New20230131_162400CreateSysApiMigration() contracts.Migration {
return &Migration20230131_162400CreateSysApi{id: "20230131_162400_create_sys_api"}
}
func (m *Migration20230131_162400CreateSysApi) ID() string {
return m.id
}
func (m *Migration20230131_162400CreateSysApi) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_162400CreateSysApi) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_162400CreateSysApi) table() interface{} {
type SysApi struct {
gorm.Model
Path string `gorm:"comment:路径"`
Description string `gorm:"comment:中文描述"`
ApiGroup string `gorm:"comment:组"`
Method string `gorm:"default:GET;comment:方法"`
}
return SysApi{}
}

View File

@@ -0,0 +1,50 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165134CreateSysDictionaryMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165134CreateSysDictionary struct {
id string
}
func New20230131_165134CreateSysDictionaryMigration() contracts.Migration {
return &Migration20230131_165134CreateSysDictionary{id: "20230131_165134_create_sys_dictionary"}
}
func (m *Migration20230131_165134CreateSysDictionary) ID() string {
return m.id
}
func (m *Migration20230131_165134CreateSysDictionary) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165134CreateSysDictionary) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165134CreateSysDictionary) table() interface{} {
type SysDictionary struct {
gorm.Model
Name string `gorm:"column:name;comment:字典名(中)"` // 字典名(中)
Type string `gorm:"column:type;comment:字典名(英)"` // 字典名(英)
Status *bool `gorm:"column:status;comment:状态"` // 状态
Desc string `gorm:"column:desc;comment:描述"` // 描述
}
return SysDictionary{}
}

View File

@@ -0,0 +1,51 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165218CreateSysDictionaryDetailMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165218CreateSysDictionaryDetail struct {
id string
}
func New20230131_165218CreateSysDictionaryDetailMigration() contracts.Migration {
return &Migration20230131_165218CreateSysDictionaryDetail{id: "20230131_165218_create_sys_dictionary_detail"}
}
func (m *Migration20230131_165218CreateSysDictionaryDetail) ID() string {
return m.id
}
func (m *Migration20230131_165218CreateSysDictionaryDetail) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165218CreateSysDictionaryDetail) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165218CreateSysDictionaryDetail) table() interface{} {
type SysDictionaryDetail struct {
gorm.Model
Label string `gorm:"column:label;comment:展示值"` // 展示值
Value int `gorm:"column:value;comment:字典值"` // 字典值
Status *bool `gorm:"column:status;comment:启用状态"` // 启用状态
Sort int `gorm:"column:sort;comment:排序标记"` // 排序标记
SysDictionaryID int `gorm:"column:sys_dictionary_id;comment:关联标记"` // 关联标记
}
return SysDictionaryDetail{}
}

View File

@@ -0,0 +1,46 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165352CreateUserRoleMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165352CreateUserRole struct {
id string
}
func New20230131_165352CreateUserRoleMigration() contracts.Migration {
return &Migration20230131_165352CreateUserRole{id: "20230131_165352_create_user_role"}
}
func (m *Migration20230131_165352CreateUserRole) ID() string {
return m.id
}
func (m *Migration20230131_165352CreateUserRole) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165352CreateUserRole) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165352CreateUserRole) table() interface{} {
type UserRole struct {
UserID uint `gorm:"column:user_id"`
RoleID uint `gorm:"column:role_id"`
}
return UserRole{}
}

View File

@@ -0,0 +1,50 @@
package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165509CreateSysRoleMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165509CreateSysRole struct {
id string
}
func New20230131_165509CreateSysRoleMigration() contracts.Migration {
return &Migration20230131_165509CreateSysRole{id: "20230131_165509_create_sys_role"}
}
func (m *Migration20230131_165509CreateSysRole) ID() string {
return m.id
}
func (m *Migration20230131_165509CreateSysRole) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165509CreateSysRole) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165509CreateSysRole) table() interface{} {
type SysRole struct {
gorm.Model
Alias string `gorm:"not null;unique;primary_key;comment:角色Alias;size:90"` // 角色ID
Name string `gorm:"comment:角色名"` // 角色名
ParentId *uint `gorm:"comment:父角色ID"` // 父角色ID
DefaultRouter string `gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
}
return SysRole{}
}