diff --git a/backend/app/dto/database.go b/backend/app/dto/database.go index 8fe07b443..37743ba7a 100644 --- a/backend/app/dto/database.go +++ b/backend/app/dto/database.go @@ -41,7 +41,7 @@ type MysqlDBInfo struct { Username string `json:"username"` Password string `json:"password"` Permission string `json:"permission"` - BackupCount int `json:"backupCount"` + IsDelete bool `json:"isDelete"` Description string `json:"description"` } diff --git a/backend/app/dto/database_postgresql.go b/backend/app/dto/database_postgresql.go index 6929c9601..503f25a36 100644 --- a/backend/app/dto/database_postgresql.go +++ b/backend/app/dto/database_postgresql.go @@ -20,7 +20,7 @@ type PostgresqlDBInfo struct { Username string `json:"username"` Password string `json:"password"` SuperUser bool `json:"superUser"` - BackupCount int `json:"backupCount"` + IsDelete bool `json:"isDelete"` Description string `json:"description"` } diff --git a/backend/app/model/database_mysql.go b/backend/app/model/database_mysql.go index 95bc41dbb..0a8734848 100644 --- a/backend/app/model/database_mysql.go +++ b/backend/app/model/database_mysql.go @@ -9,5 +9,6 @@ type DatabaseMysql struct { Username string `json:"username" gorm:"type:varchar(256);not null"` Password string `json:"password" gorm:"type:varchar(256);not null"` Permission string `json:"permission" gorm:"type:varchar(256);not null"` + IsDelete bool `json:"isDelete" gorm:"type:varchar(64)"` Description string `json:"description" gorm:"type:varchar(256);"` } diff --git a/backend/app/model/database_postgresql.go b/backend/app/model/database_postgresql.go index 35f52965f..7ea4ee59e 100644 --- a/backend/app/model/database_postgresql.go +++ b/backend/app/model/database_postgresql.go @@ -8,6 +8,7 @@ type DatabasePostgresql struct { Format string `json:"format" gorm:"type:varchar(64);not null"` Username string `json:"username" gorm:"type:varchar(256);not null"` Password string `json:"password" gorm:"type:varchar(256);not null"` - SuperUser bool `json:"superUser" gorm:"type:varchar(64)" ` + SuperUser bool `json:"superUser" gorm:"type:varchar(64)"` + IsDelete bool `json:"isDelete" gorm:"type:varchar(64)"` Description string `json:"description" gorm:"type:varchar(256);"` } diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index f46ed081c..33aa6a049 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -190,11 +190,13 @@ func (u *MysqlService) LoadFromRemote(req dto.MysqlLoadDB) error { if err != nil { return err } + deleteList := databases for _, data := range datas { hasOld := false - for _, oldData := range databases { - if strings.EqualFold(oldData.Name, data.Name) && strings.EqualFold(oldData.MysqlName, data.MysqlName) { + for i := 0; i < len(databases); i++ { + if strings.EqualFold(databases[i].Name, data.Name) && strings.EqualFold(databases[i].MysqlName, data.MysqlName) { hasOld = true + deleteList = append(deleteList[:i], deleteList[i+1:]...) break } } @@ -208,6 +210,9 @@ func (u *MysqlService) LoadFromRemote(req dto.MysqlLoadDB) error { } } } + for _, delItem := range deleteList { + _ = mysqlRepo.Update(delItem.ID, map[string]interface{}{"is_delete": true}) + } return nil } diff --git a/backend/app/service/database_postgresql.go b/backend/app/service/database_postgresql.go index f9a8b080f..b7fafc6a5 100644 --- a/backend/app/service/database_postgresql.go +++ b/backend/app/service/database_postgresql.go @@ -216,11 +216,13 @@ func (u *PostgresqlService) LoadFromRemote(database string) error { if err != nil { return err } + deleteList := databases for _, data := range datas { hasOld := false - for _, oldData := range databases { - if strings.EqualFold(oldData.Name, data.Name) && strings.EqualFold(oldData.PostgresqlName, data.PostgresqlName) { + for i := 0; i < len(databases); i++ { + if strings.EqualFold(databases[i].Name, data.Name) && strings.EqualFold(databases[i].PostgresqlName, data.PostgresqlName) { hasOld = true + deleteList = append(deleteList[:i], deleteList[i+1:]...) break } } @@ -234,6 +236,9 @@ func (u *PostgresqlService) LoadFromRemote(database string) error { } } } + for _, delItem := range deleteList { + _ = postgresqlRepo.Update(delItem.ID, map[string]interface{}{"is_delete": true}) + } return nil } diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index dcad5937f..daa868482 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -74,6 +74,7 @@ func Init() { migrations.UpdateWebDavConf, migrations.AddSnapshotIgnore, + migrations.AddDatabaseIsDelete, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/v_1_10.go b/backend/init/migration/migrations/v_1_10.go index f6897f006..fd07918b7 100644 --- a/backend/init/migration/migrations/v_1_10.go +++ b/backend/init/migration/migrations/v_1_10.go @@ -15,3 +15,13 @@ var AddSnapshotIgnore = &gormigrate.Migration{ return nil }, } + +var AddDatabaseIsDelete = &gormigrate.Migration{ + ID: "20240314-add-database-is-delete", + Migrate: func(tx *gorm.DB) error { + if err := tx.AutoMigrate(&model.DatabaseMysql{}, &model.DatabasePostgresql{}); err != nil { + return err + } + return nil + }, +} diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 6b518da0e..84fe1f740 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -17818,6 +17818,9 @@ const docTemplate = `{ "sessionTimeout": { "type": "string" }, + "snapshotIgnore": { + "type": "string" + }, "ssl": { "type": "string" }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 552c206ab..f48698549 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -17811,6 +17811,9 @@ "sessionTimeout": { "type": "string" }, + "snapshotIgnore": { + "type": "string" + }, "ssl": { "type": "string" }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index d611baf6c..0d1960faf 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -2538,6 +2538,8 @@ definitions: type: string sessionTimeout: type: string + snapshotIgnore: + type: string ssl: type: string sslType: diff --git a/frontend/src/api/interface/database.ts b/frontend/src/api/interface/database.ts index ed8784d5f..b7dfd4af3 100644 --- a/frontend/src/api/interface/database.ts +++ b/frontend/src/api/interface/database.ts @@ -23,6 +23,7 @@ export namespace Database { username: string; password: string; permission: string; + isDelete: string; description: string; } export interface BaseInfo { @@ -207,6 +208,7 @@ export namespace Database { username: string; password: string; superUser: boolean; + isDelete: string; description: string; } export interface ChangeInfo { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 86a77d8c4..a1b3901ac 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -364,6 +364,7 @@ const message = { goUpgrade: 'Go for upgrade', goInstall: 'Go for install', source: 'Source', + isDelete: 'Deleted', permission: 'Permission', permissionForIP: 'IP', permissionAll: 'All of them(%)', @@ -388,7 +389,7 @@ const message = { portHelper: 'This port is the exposed port of the container. You need to save the modification separately and restart the container!', - loadFromRemote: 'Load from server', + loadFromRemote: 'Sync from Server', userBind: 'Bind User', pgBindHelper: 'This operation is used to create a new user and bind it to the target database. Currently, selecting users already existing in the database is not supported.', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 72571c50b..df0b06733 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -360,6 +360,7 @@ const message = { goUpgrade: '去應用商店升級', goInstall: '去應用商店安裝', source: '來源', + isDelete: '已刪除', permission: '權限', permissionForIP: '指定 IP', permissionAll: '所有人(%)', @@ -380,7 +381,7 @@ const message = { confChange: '配置修改', confNotFound: '未能找到該應用配置文件,請在應用商店升級該應用至最新版本後重試!', - loadFromRemote: '從服務器獲取', + loadFromRemote: '從伺服器同步', userBind: '綁定使用者', pgBindHelper: '此操作用於創建新使用者並將其綁定到目標資料庫,暫不支援選擇已存在於資料庫中的使用者。', pgSuperUser: '超級使用者', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index e1026c326..c6e5f7c40 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -360,6 +360,7 @@ const message = { goUpgrade: '去应用列表升级', goInstall: '去应用商店安装', source: '来源', + isDelete: '已删除', permission: '权限', permissionForIP: '指定 IP', permissionAll: '所有人(%)', @@ -380,7 +381,7 @@ const message = { confChange: '配置修改', confNotFound: '未能找到该应用配置文件,请在应用商店升级该应用至最新版本后重试!', - loadFromRemote: '从服务器获取', + loadFromRemote: '从服务器同步', userBind: '绑定用户', pgBindHelper: '该操作用于创建新用户并将其绑定到目标数据库,暂不支持选择已存在于数据库中的用户。', pgSuperUser: '超级用户', diff --git a/frontend/src/views/database/mysql/index.vue b/frontend/src/views/database/mysql/index.vue index 7ea0b11e2..7fec71bbf 100644 --- a/frontend/src/views/database/mysql/index.vue +++ b/frontend/src/views/database/mysql/index.vue @@ -113,8 +113,19 @@