minor internal indexes handling adjustments and test
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
@@ -403,14 +402,17 @@ func (form *CollectionUpsert) checkIndexes(value any) error {
|
||||
}
|
||||
}
|
||||
|
||||
if !strings.EqualFold(parsed.TableName, form.Name) {
|
||||
return validation.Errors{
|
||||
strconv.Itoa(i): validation.NewError(
|
||||
"validation_invalid_index_table",
|
||||
fmt.Sprintf("The index table must be the same as the collection name."),
|
||||
),
|
||||
}
|
||||
}
|
||||
// note: we don't check the index table because it is always
|
||||
// overwritten by the daos.SyncRecordTableSchema to allow
|
||||
// easier partial modifications (eg. changing only the collection name).
|
||||
// if !strings.EqualFold(parsed.TableName, form.Name) {
|
||||
// return validation.Errors{
|
||||
// strconv.Itoa(i): validation.NewError(
|
||||
// "validation_invalid_index_table",
|
||||
// fmt.Sprintf("The index table must be the same as the collection name."),
|
||||
// ),
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -506,10 +508,15 @@ func (form *CollectionUpsert) Submit(interceptors ...InterceptorFunc[*models.Col
|
||||
// view schema is autogenerated on save and cannot have indexes
|
||||
if !form.collection.IsView() {
|
||||
form.collection.Schema = form.Schema
|
||||
form.collection.Indexes = append(
|
||||
types.JsonArray{},
|
||||
list.ToInterfaceSlice(list.ToUniqueStringSlice(form.Indexes))...,
|
||||
)
|
||||
|
||||
// normalize indexes format
|
||||
form.collection.Indexes = types.JsonArray{}
|
||||
for _, rawIdx := range form.Indexes {
|
||||
form.collection.Indexes = append(
|
||||
form.collection.Indexes,
|
||||
dbutils.ParseIndex(rawIdx).Build(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
form.collection.ListRule = form.ListRule
|
||||
|
||||
Reference in New Issue
Block a user