mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 03:07:20 +08:00
feat: 初始化数据库服务
This commit is contained in:
@@ -16,5 +16,5 @@ type ChangePassword struct {
|
||||
}
|
||||
|
||||
type UpdatePort struct {
|
||||
Port uint `form:"port" json:"port" validate:"required"`
|
||||
Port uint `form:"port" json:"port" validate:"required,number,gte=1,lte=65535"`
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/TheTNB/panel/internal/app"
|
||||
"github.com/TheTNB/panel/internal/http/request"
|
||||
)
|
||||
|
||||
type DatabaseStatus string
|
||||
@@ -17,17 +18,17 @@ const (
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
DatabaseID uint `gorm:"not null" json:"database_id"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
Status DatabaseStatus `gorm:"not null" json:"status"`
|
||||
Username string `gorm:"not null" json:"username"`
|
||||
Password string `gorm:"not null" json:"password"`
|
||||
Remark string `gorm:"not null" json:"remark"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
ServerID uint `gorm:"not null" json:"server_id"`
|
||||
Name string `gorm:"not null" json:"name"`
|
||||
Status DatabaseStatus `gorm:"not null" json:"status"`
|
||||
Username string `gorm:"not null" json:"username"`
|
||||
Password string `gorm:"not null" json:"password"`
|
||||
Remark string `gorm:"not null" json:"remark"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
DatabaseServer *DatabaseServer `json:"database_server"`
|
||||
Server *DatabaseServer `gorm:"foreignKey:ServerID" json:"server"`
|
||||
}
|
||||
|
||||
func (r *Database) BeforeSave(tx *gorm.DB) error {
|
||||
@@ -57,3 +58,12 @@ func (r *Database) AfterFind(tx *gorm.DB) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type DatabaseRepo interface {
|
||||
Count() (int64, error)
|
||||
List(page, limit uint) ([]*Database, int64, error)
|
||||
Get(id uint) (*Database, error)
|
||||
Create(req *request.DatabaseCreate) error
|
||||
Update(req *request.DatabaseUpdate) error
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/TheTNB/panel/internal/app"
|
||||
"github.com/TheTNB/panel/internal/http/request"
|
||||
)
|
||||
|
||||
type DatabaseType string
|
||||
@@ -23,14 +24,14 @@ type DatabaseServer struct {
|
||||
Name string `gorm:"not null;unique" json:"name"`
|
||||
Type DatabaseType `gorm:"not null" json:"type"`
|
||||
Host string `gorm:"not null" json:"host"`
|
||||
Port int `gorm:"not null" json:"port"`
|
||||
Port uint `gorm:"not null" json:"port"`
|
||||
Username string `gorm:"not null" json:"username"`
|
||||
Password string `gorm:"not null" json:"password"`
|
||||
Remark string `gorm:"not null" json:"remark"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
Databases []*Database `json:"-"`
|
||||
Databases []*Database `gorm:"foreignKey:ServerID" json:"-"`
|
||||
}
|
||||
|
||||
func (r *DatabaseServer) BeforeSave(tx *gorm.DB) error {
|
||||
@@ -62,6 +63,7 @@ func (r *DatabaseServer) AfterFind(tx *gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO 检查放到业务层
|
||||
func (r *DatabaseServer) BeforeDelete(tx *gorm.DB) error {
|
||||
if r.Name == "local_mysql" && !app.IsCli {
|
||||
return errors.New("can't delete local_mysql, if you must delete it, please uninstall mysql")
|
||||
@@ -75,3 +77,12 @@ func (r *DatabaseServer) BeforeDelete(tx *gorm.DB) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type DatabaseServerRepo interface {
|
||||
Count() (int64, error)
|
||||
List(page, limit uint) ([]*DatabaseServer, int64, error)
|
||||
Get(id uint) (*DatabaseServer, error)
|
||||
Create(req *request.DatabaseServerCreate) error
|
||||
Update(req *request.DatabaseServerCreate) error
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
1
internal/data/database.go
Normal file
1
internal/data/database.go
Normal file
@@ -0,0 +1 @@
|
||||
package data
|
||||
1
internal/data/database_server.go
Normal file
1
internal/data/database_server.go
Normal file
@@ -0,0 +1 @@
|
||||
package data
|
||||
17
internal/http/request/database.go
Normal file
17
internal/http/request/database.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package request
|
||||
|
||||
type DatabaseCreate struct {
|
||||
ServerID string `form:"server_id" json:"server_id" validate:"required,exists=database_servers id"`
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Username string `form:"username" json:"username" validate:"required"`
|
||||
Password string `form:"password" json:"password" validate:"required"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
|
||||
type DatabaseUpdate struct {
|
||||
ID string `form:"id" json:"id" validate:"required,exists=databases id"`
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Username string `form:"username" json:"username" validate:"required"`
|
||||
Password string `form:"password" json:"password" validate:"required"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
22
internal/http/request/database_server.go
Normal file
22
internal/http/request/database_server.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package request
|
||||
|
||||
type DatabaseServerCreate struct {
|
||||
Name string `form:"name" json:"name" validate:"required,not_exists=database_servers name"`
|
||||
Type string `form:"type" json:"type" validate:"required,oneof=mysql postgresql redis"`
|
||||
Host string `form:"host" json:"host" validate:"required"`
|
||||
Port uint `form:"port" json:"port" validate:"required,number,gte=1,lte=65535"`
|
||||
Username string `form:"username" json:"username" validate:"required"`
|
||||
Password string `form:"password" json:"password" validate:"required"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
|
||||
type DatabaseServerUpdate struct {
|
||||
ID uint `form:"id" json:"id" validate:"required,exists=database_servers id"`
|
||||
Name string `form:"name" json:"name" validate:"required,not_exists=database_servers name"`
|
||||
Type string `form:"type" json:"type" validate:"required,oneof=mysql postgresql redis"`
|
||||
Host string `form:"host" json:"host" validate:"required"`
|
||||
Port uint `form:"port" json:"port" validate:"required,number,gte=1,lte=65535"`
|
||||
Username string `form:"username" json:"username" validate:"required"`
|
||||
Password string `form:"password" json:"password" validate:"required"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
1
internal/service/database.go
Normal file
1
internal/service/database.go
Normal file
@@ -0,0 +1 @@
|
||||
package service
|
||||
1
internal/service/database_server.go
Normal file
1
internal/service/database_server.go
Normal file
@@ -0,0 +1 @@
|
||||
package service
|
||||
Reference in New Issue
Block a user