diff --git a/DBPacth/v1.0.1-v1.0.2.sql b/DBPacth/v1.0.1-v1.0.2.sql new file mode 100644 index 0000000..25a5992 --- /dev/null +++ b/DBPacth/v1.0.1-v1.0.2.sql @@ -0,0 +1,2 @@ +ALTER TABLE `package` +ADD COLUMN `deployment_version_id` INT NULL AFTER `deployment_id`; \ No newline at end of file diff --git a/README.md b/README.md index eae3653..bf86ee5 100644 --- a/README.md +++ b/README.md @@ -120,10 +120,5 @@ chmod +x code-push-go ${CODE_PUSH_SERVER_URL} ``` -## Developing -- [X] Delete app -- [X] Delete deployment -- [ ] Rollback bundel - ## License MIT License [Read](https://github.com/htdcx/code-push-server-go/blob/main/LICENSE) diff --git a/code-push.sql b/code-push.sql index 645eee5..445684e 100644 --- a/code-push.sql +++ b/code-push.sql @@ -109,6 +109,7 @@ DROP TABLE IF EXISTS `package`; CREATE TABLE `package` ( `id` int NOT NULL AUTO_INCREMENT, `deployment_id` int DEFAULT NULL, + `deployment_version_id` int DEFAULT NULL, `size` bigint DEFAULT NULL, `hash` varchar(256) DEFAULT NULL, `description` TEXT DEFAULT NULL, diff --git a/main.go b/main.go index 0a5a9fc..ca2553b 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ func main() { authApi.POST("/lsDeployment", request.App{}.LsDeployment) authApi.GET("/lsApp", request.App{}.LsApp) authApi.POST("/uploadBundle", request.App{}.UploadBundle) + authApi.POST("/rollback", request.App{}.Rollback) } g.Run(configs.Port) diff --git a/model/deploymentVersion.go b/model/deploymentVersion.go index 360e2a3..9cd0e6a 100644 --- a/model/deploymentVersion.go +++ b/model/deploymentVersion.go @@ -31,3 +31,7 @@ func (DeploymentVersion) GetNewVersionByKeyDeploymentId(deploymentId int) *Deplo } return deploymentVersion } + +func (DeploymentVersion) UpdateCurrentPackage(id int, pid *int) { + userDb.Raw("update deployment_version set current_package=? where id=?", pid, id).Scan(&DeploymentVersion{}) +} diff --git a/model/package.go b/model/package.go index c75ce0a..1c4e000 100644 --- a/model/package.go +++ b/model/package.go @@ -1,16 +1,17 @@ package model type Package struct { - Id *int `gorm:"primarykey;autoIncrement;size:32"` - DeploymentId *int `json:"deploymentId"` - Size *int64 `json:"size"` - Hash *string `json:"hash"` - Download *string `json:"download"` - Active *int `json:"active"` - Failed *int `json:"failed"` - Installed *int `json:"installed"` - CreateTime *int64 `json:"create_time"` - Description *string `json:"description"` + Id *int `gorm:"primarykey;autoIncrement;size:32"` + DeploymentId *int `json:"deploymentId"` + DeploymentVersionId *int `json:"deploymentVersionId"` + Size *int64 `json:"size"` + Hash *string `json:"hash"` + Download *string `json:"download"` + Active *int `json:"active"` + Failed *int `json:"failed"` + Installed *int `json:"installed"` + CreateTime *int64 `json:"create_time"` + Description *string `json:"description"` } func (Package) TableName() string { @@ -28,3 +29,12 @@ func (Package) AddFailed(pid int) { func (Package) AddInstalled(pid int) { userDb.Raw("update package set installed=installed+1 where id=?", pid).Scan(&Package{}) } + +func (Package) GetRollbackPack(deploymentId int, lastPakcId int, deploymentVersionId int) *Package { + var lastPackage *Package + err := userDb.Where("deployment_id=?", deploymentId).Where("id