mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
feat: model.Database -> model.AppDatabase
This commit is contained in:
parent
19f9c4635b
commit
1cd18a9938
@ -1,29 +1,26 @@
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
|
||||
error_log /var/log/nginx/error.log notice;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
# 设置网路连接序列化
|
||||
accept_mutex on;
|
||||
# 一个进程是否同时接受多个网络连接
|
||||
multi_accept on;
|
||||
# 事件驱动模型
|
||||
use epoll;
|
||||
# 最大连接数
|
||||
worker_connections 1024;
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
#http全局块
|
||||
include mime.types;
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
#server块
|
||||
server {
|
||||
#server全局块
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
#location块
|
||||
location / {
|
||||
root html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
}
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package model
|
||||
|
||||
type Database struct {
|
||||
type AppDatabase struct {
|
||||
BaseModel
|
||||
AppInstallId uint `json:"appInstallId" gorm:"type:integer;not null"`
|
||||
Key string `json:"key" gorm:"type:varchar(64);not null"`
|
||||
|
@ -70,7 +70,7 @@ func (c *CommonRepo) WithIdsNotIn(ids []uint) DBOption {
|
||||
}
|
||||
|
||||
func getTx(ctx context.Context, opts ...DBOption) *gorm.DB {
|
||||
if ctx == nil {
|
||||
if ctx == nil || ctx.Value("db") == nil {
|
||||
return getDb()
|
||||
}
|
||||
tx := ctx.Value("db").(*gorm.DB)
|
||||
|
@ -16,22 +16,22 @@ func (d DatabaseRepo) ByAppInstallId(installId uint) DBOption {
|
||||
}
|
||||
}
|
||||
|
||||
func (d DatabaseRepo) Create(ctx context.Context, database *model.Database) error {
|
||||
db := ctx.Value("db").(*gorm.DB).Model(&model.Database{})
|
||||
func (d DatabaseRepo) Create(ctx context.Context, database *model.AppDatabase) error {
|
||||
db := ctx.Value("db").(*gorm.DB).Model(&model.AppDatabase{})
|
||||
return db.Create(&database).Error
|
||||
}
|
||||
|
||||
func (d DatabaseRepo) DeleteBy(ctx context.Context, opts ...DBOption) error {
|
||||
db := ctx.Value("db").(*gorm.DB).Model(&model.Database{})
|
||||
db := ctx.Value("db").(*gorm.DB).Model(&model.AppDatabase{})
|
||||
for _, opt := range opts {
|
||||
db = opt(db)
|
||||
}
|
||||
return db.Delete(&model.Database{}).Error
|
||||
return db.Delete(&model.AppDatabase{}).Error
|
||||
}
|
||||
|
||||
func (d DatabaseRepo) GetBy(opts ...DBOption) ([]model.Database, error) {
|
||||
db := global.DB.Model(model.Database{})
|
||||
var databases []model.Database
|
||||
func (d DatabaseRepo) GetBy(opts ...DBOption) ([]model.AppDatabase, error) {
|
||||
db := global.DB.Model(model.AppDatabase{})
|
||||
var databases []model.AppDatabase
|
||||
for _, opt := range opts {
|
||||
db = opt(db)
|
||||
}
|
||||
@ -42,9 +42,9 @@ func (d DatabaseRepo) GetBy(opts ...DBOption) ([]model.Database, error) {
|
||||
return databases, nil
|
||||
}
|
||||
|
||||
func (d DatabaseRepo) GetFirst(opts ...DBOption) (model.Database, error) {
|
||||
db := global.DB.Model(model.Database{})
|
||||
var database model.Database
|
||||
func (d DatabaseRepo) GetFirst(opts ...DBOption) (model.AppDatabase, error) {
|
||||
db := global.DB.Model(model.AppDatabase{})
|
||||
var database model.AppDatabase
|
||||
for _, opt := range opts {
|
||||
db = opt(db)
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func (a AppService) PageInstalled(req dto.AppInstalledRequest) (int64, []dto.App
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
installDTOs := []dto.AppInstalled{}
|
||||
var installDTOs []dto.AppInstalled
|
||||
for _, in := range installed {
|
||||
installDto := dto.AppInstalled{
|
||||
AppInstall: in,
|
||||
@ -137,7 +137,7 @@ func (a AppService) GetAppDetail(appId uint, version string) (dto.AppDetailDTO,
|
||||
return appDetailDTO, err
|
||||
}
|
||||
paramMap := make(map[string]interface{})
|
||||
json.Unmarshal([]byte(detail.Params), ¶mMap)
|
||||
_ = json.Unmarshal([]byte(detail.Params), ¶mMap)
|
||||
appDetailDTO.AppDetail = detail
|
||||
appDetailDTO.Params = paramMap
|
||||
return appDetailDTO, nil
|
||||
@ -201,11 +201,11 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int
|
||||
|
||||
httpPort, err := checkPort("PANEL_APP_PORT_HTTP", params)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("%d port is in used", httpPort))
|
||||
return fmt.Errorf("%d port is in used", httpPort)
|
||||
}
|
||||
httpsPort, err := checkPort("PANEL_APP_PORT_HTTPS", params)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("%d port is in used", httpsPort))
|
||||
return fmt.Errorf("%d port is in used", httpPort)
|
||||
}
|
||||
|
||||
appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(appDetailId))
|
||||
@ -314,7 +314,7 @@ func (a AppService) DeleteBackup(req dto.AppBackupDeleteRequest) error {
|
||||
errStr.WriteString(err.Error())
|
||||
continue
|
||||
}
|
||||
if err := appInstallBackupRepo.Delete(nil, commonRepo.WithIdsIn(req.Ids)); err != nil {
|
||||
if err := appInstallBackupRepo.Delete(context.TODO(), commonRepo.WithIdsIn(req.Ids)); err != nil {
|
||||
errStr.WriteString(err.Error())
|
||||
}
|
||||
}
|
||||
@ -673,6 +673,9 @@ func (a AppService) GetUpdateVersions(installId uint) ([]dto.AppVersion, error)
|
||||
return versions, err
|
||||
}
|
||||
details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(app.ID))
|
||||
if err != nil {
|
||||
return versions, err
|
||||
}
|
||||
for _, detail := range details {
|
||||
if common.CompareVersion(detail.Version, install.Version) {
|
||||
versions = append(versions, dto.AppVersion{
|
||||
|
@ -34,13 +34,13 @@ var (
|
||||
Delete DatabaseOp = "delete"
|
||||
)
|
||||
|
||||
func execDockerCommand(database model.Database, dbInstall model.AppInstall, op DatabaseOp) error {
|
||||
func execDockerCommand(database model.AppDatabase, dbInstall model.AppInstall, op DatabaseOp) error {
|
||||
var auth dto.AuthParam
|
||||
var dbConfig dto.AppDatabase
|
||||
dbConfig.Password = database.Password
|
||||
dbConfig.DbUser = database.Username
|
||||
dbConfig.DbName = database.Dbname
|
||||
json.Unmarshal([]byte(dbInstall.Param), &auth)
|
||||
_ = json.Unmarshal([]byte(dbInstall.Param), &auth)
|
||||
execConfig := dto.ContainerExec{
|
||||
ContainerName: dbInstall.ContainerName,
|
||||
Auth: auth,
|
||||
@ -121,7 +121,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var database model.Database
|
||||
var database model.AppDatabase
|
||||
database.Dbname = dbConfig.DbName
|
||||
database.Username = dbConfig.DbUser
|
||||
database.Password = dbConfig.Password
|
||||
@ -185,7 +185,7 @@ func deleteLink(ctx context.Context, install *model.AppInstall) error {
|
||||
for _, re := range resources {
|
||||
if re.Key == "mysql" {
|
||||
database, _ := dataBaseRepo.GetFirst(commonRepo.WithByID(re.ResourceId))
|
||||
if reflect.DeepEqual(database, model.Database{}) {
|
||||
if reflect.DeepEqual(database, model.AppDatabase{}) {
|
||||
continue
|
||||
}
|
||||
appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(database.AppInstallId))
|
||||
|
@ -150,7 +150,7 @@ var AddTableCronjob = &gormigrate.Migration{
|
||||
var AddTableApp = &gormigrate.Migration{
|
||||
ID: "20200921-add-table-app",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.App{}, &model.AppDetail{}, &model.Tag{}, &model.AppTag{}, &model.AppInstall{}, &model.AppInstallResource{}, &model.Database{}, &model.AppInstallBackup{})
|
||||
return tx.AutoMigrate(&model.App{}, &model.AppDetail{}, &model.Tag{}, &model.AppTag{}, &model.AppInstall{}, &model.AppInstallResource{}, &model.AppDatabase{}, &model.AppInstallBackup{})
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user