(c *gin.Context)
| 792 | } |
| 793 | |
| 794 | func createProjectTable(c *gin.Context) { |
| 795 | r := struct { |
| 796 | DB proto.DatabaseID `json:"db" json:"project" form:"db" form:"project" uri:"db" uri:"project" binding:"required,len=64"` |
| 797 | Table string `json:"table" form:"table" uri:"table" binding:"required,max=128"` |
| 798 | ColumnNames []string `json:"names" form:"names" binding:"required,min=1,dive,required,max=32"` |
| 799 | ColumnTypes []string `json:"types" form:"types" binding:"required,min=1,dive,required,max=16"` |
| 800 | PrimaryKey string `json:"primary_key" form:"primary_key" binding:"omitempty,max=32"` |
| 801 | AutoIncrement bool `json:"auto_increment" form:"auto_increment"` |
| 802 | }{} |
| 803 | |
| 804 | _ = c.ShouldBindUri(&r) |
| 805 | |
| 806 | if err := c.ShouldBind(&r); err != nil { |
| 807 | abortWithError(c, http.StatusBadRequest, err) |
| 808 | return |
| 809 | } |
| 810 | |
| 811 | if len(r.ColumnNames) != len(r.ColumnTypes) { |
| 812 | abortWithError(c, http.StatusBadRequest, ErrMismatchedColumnNamesAndTypes) |
| 813 | return |
| 814 | } |
| 815 | |
| 816 | if strings.EqualFold(r.Table, metaTableProjectConfig) || strings.EqualFold(r.Table, metaTableUserInfo) || |
| 817 | strings.EqualFold(r.Table, metaTableSession) || strings.HasPrefix(r.Table, deletedTablePrefix) { |
| 818 | abortWithError(c, http.StatusBadRequest, ErrReservedTableName) |
| 819 | return |
| 820 | } |
| 821 | |
| 822 | // try find primary key in columns |
| 823 | pkIdx := -1 |
| 824 | |
| 825 | if r.PrimaryKey != "" { |
| 826 | for idx, colName := range r.ColumnNames { |
| 827 | if strings.EqualFold(colName, r.PrimaryKey) { |
| 828 | pkIdx = idx |
| 829 | |
| 830 | if r.AutoIncrement && |
| 831 | !strings.EqualFold(r.ColumnTypes[idx], "NUMBER") && |
| 832 | !strings.EqualFold(r.ColumnTypes[idx], "INTEGER") { |
| 833 | abortWithError(c, http.StatusBadRequest, ErrInvalidAutoIncrementColumnType) |
| 834 | return |
| 835 | } |
| 836 | |
| 837 | break |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | if pkIdx == -1 { |
| 842 | abortWithError(c, http.StatusBadRequest, ErrUnknownPrimaryKeyColumn) |
| 843 | return |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | _, projectDB, err := getProjectDB(c, r.DB) |
| 848 | if err != nil { |
| 849 | _ = c.Error(err) |
| 850 | abortWithError(c, http.StatusForbidden, ErrLoadProjectDatabaseFailed) |
| 851 | return |
nothing calls this directly
no test coverage detected