mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-09-08 15:41:18 +02:00
fixed multiline index column and utrigger index validations if failing to parse all columns
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
indexRegex = regexp.MustCompile(`(?im)\s*create\s+(unique\s+)?\s*index\s*(if\s+not\s+exists\s+)?(\S*)\s+on\s+(\S*)\s*\(([\s\S]*?)\)(?:\s+where\s+([\s\S]*?))?\s*$`)
|
||||
indexColumnRegex = regexp.MustCompile(`(?im)^([\s\S]+?)(?:\s+collate\s+([\w]+))?(?:\s+(asc|desc))?$`)
|
||||
indexRegex = regexp.MustCompile(`(?i)\s*create\s+(unique\s+)?\s*index\s*(if\s+not\s+exists\s+)?(\S*)\s+on\s+(\S*)\s*\(([\s\S]*?)\)(?:\s+where\s+([\s\S]*?))?\s*$`)
|
||||
indexColumnRegex = regexp.MustCompile(`(?i)^([\s\S]+?)(?:\s+collate\s+([\w]+))?(?:\s+(asc|desc))?\s*$`)
|
||||
)
|
||||
|
||||
// IndexColumn represents a single parsed SQL index column.
|
||||
@@ -187,6 +187,11 @@ func ParseIndex(createIndexExpr string) Index {
|
||||
})
|
||||
}
|
||||
|
||||
if len(rawColumns) != len(result.Columns) {
|
||||
// unset to trigger validation error
|
||||
result.Columns = []IndexColumn{}
|
||||
}
|
||||
|
||||
// WHERE expression
|
||||
// ---
|
||||
result.Where = strings.TrimSpace(matches[6])
|
||||
|
||||
@@ -57,10 +57,10 @@ func TestParseIndex(t *testing.T) {
|
||||
`CREATE UNIQUE INDEX IF NOT EXISTS "schemaname".[indexname] on 'tablename' (
|
||||
col0,
|
||||
` + "`" + `col1` + "`" + `,
|
||||
json_extract("col2", "$.a") asc,
|
||||
json_extract("col2_multiline",` + "\n" + ` "$.a") asc,
|
||||
"col3" collate NOCASE,
|
||||
"col4" collate RTRIM desc
|
||||
) where cast(test1 as int) = 1 and test2 != ''`,
|
||||
) where cast(test1 as ` + "\n" + `int) = 1 and test2 != ''`,
|
||||
dbutils.Index{
|
||||
Unique: true,
|
||||
Optional: true,
|
||||
@@ -70,11 +70,11 @@ func TestParseIndex(t *testing.T) {
|
||||
Columns: []dbutils.IndexColumn{
|
||||
{Name: "col0"},
|
||||
{Name: "col1"},
|
||||
{Name: `json_extract("col2", "$.a")`, Sort: "ASC"},
|
||||
{Name: `json_extract("col2_multiline",` + "\n" + ` "$.a")`, Sort: "ASC"},
|
||||
{Name: `col3`, Collate: "NOCASE"},
|
||||
{Name: `col4`, Collate: "RTRIM", Sort: "DESC"},
|
||||
},
|
||||
Where: "cast(test1 as int) = 1 and test2 != ''",
|
||||
Where: "cast(test1 as \nint) = 1 and test2 != ''",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user