(c *gin.Context)
| 1046 | } |
| 1047 | |
| 1048 | func dropProjectTable(c *gin.Context) { |
| 1049 | r := struct { |
| 1050 | DB proto.DatabaseID `json:"db" json:"project" form:"db" form:"project" uri:"db" uri:"project" binding:"required,len=64"` |
| 1051 | Table string `json:"table" form:"table" uri:"table" binding:"required,max=128"` |
| 1052 | }{} |
| 1053 | |
| 1054 | _ = c.ShouldBindUri(&r) |
| 1055 | |
| 1056 | if err := c.ShouldBind(&r); err != nil { |
| 1057 | abortWithError(c, http.StatusBadRequest, err) |
| 1058 | return |
| 1059 | } |
| 1060 | |
| 1061 | _, projectDB, err := getProjectDB(c, r.DB) |
| 1062 | if err != nil { |
| 1063 | _ = c.Error(err) |
| 1064 | abortWithError(c, http.StatusForbidden, ErrLoadProjectDatabaseFailed) |
| 1065 | return |
| 1066 | } |
| 1067 | |
| 1068 | pc, ptc, err := model.GetProjectTableConfig(projectDB, r.Table) |
| 1069 | if err != nil { |
| 1070 | _ = c.Error(err) |
| 1071 | abortWithError(c, http.StatusInternalServerError, ErrGetProjectTableConfigFailed) |
| 1072 | return |
| 1073 | } |
| 1074 | |
| 1075 | if ptc.IsDeleted { |
| 1076 | _ = c.Error(err) |
| 1077 | abortWithError(c, http.StatusNotFound, ErrTableNotExists) |
| 1078 | return |
| 1079 | } |
| 1080 | |
| 1081 | // rename table |
| 1082 | newName := fmt.Sprintf("%s_%s_%d", deletedTablePrefix, r.Table, pc.ID) |
| 1083 | _, err = projectDB.Exec(fmt.Sprintf( |
| 1084 | `ALTER TABLE "%s" RENAME TO "%s"`, r.Table, newName)) |
| 1085 | if err != nil { |
| 1086 | _ = c.Error(err) |
| 1087 | abortWithError(c, http.StatusInternalServerError, ErrDDLExecuteFailed) |
| 1088 | return |
| 1089 | } |
| 1090 | |
| 1091 | ptc.IsDeleted = true |
| 1092 | |
| 1093 | err = model.UpdateProjectConfig(projectDB, pc) |
| 1094 | if err != nil { |
| 1095 | _ = c.Error(err) |
| 1096 | abortWithError(c, http.StatusInternalServerError, ErrUpdateProjectConfigFailed) |
| 1097 | return |
| 1098 | } |
| 1099 | |
| 1100 | responseWithData(c, http.StatusOK, gin.H{ |
| 1101 | "project": r.DB, |
| 1102 | "db": r.DB, |
| 1103 | "table": r.Table, |
| 1104 | "created": formatUnixTime(pc.Created), |
| 1105 | "last_updated": formatUnixTime(pc.LastUpdated), |
nothing calls this directly
no test coverage detected