update automigrate templates to check collection indexes
This commit is contained in:
parent
971916c20d
commit
95bb2eb871
|
@ -31,6 +31,9 @@ migrate((db) => {
|
||||||
"type": "auth",
|
"type": "auth",
|
||||||
"system": true,
|
"system": true,
|
||||||
"schema": [],
|
"schema": [],
|
||||||
|
"indexes": [
|
||||||
|
"create index test on new_name (id)"
|
||||||
|
],
|
||||||
"listRule": "@request.auth.id != '' && created > 0 || 'backtick` + "`" + `test' = 0",
|
"listRule": "@request.auth.id != '' && created > 0 || 'backtick` + "`" + `test' = 0",
|
||||||
"viewRule": "id = \"1\"",
|
"viewRule": "id = \"1\"",
|
||||||
"createRule": null,
|
"createRule": null,
|
||||||
|
@ -81,6 +84,9 @@ func init() {
|
||||||
"type": "auth",
|
"type": "auth",
|
||||||
"system": true,
|
"system": true,
|
||||||
"schema": [],
|
"schema": [],
|
||||||
|
"indexes": [
|
||||||
|
"create index test on new_name (id)"
|
||||||
|
],
|
||||||
"listRule": "@request.auth.id != '' && created > 0 || ` + "'backtick` + \"`\" + `test' = 0" + `",
|
"listRule": "@request.auth.id != '' && created > 0 || ` + "'backtick` + \"`\" + `test' = 0" + `",
|
||||||
"viewRule": "id = \"1\"",
|
"viewRule": "id = \"1\"",
|
||||||
"createRule": null,
|
"createRule": null,
|
||||||
|
@ -143,6 +149,7 @@ func init() {
|
||||||
collection.Updated = collection.Created
|
collection.Updated = collection.Created
|
||||||
collection.ListRule = types.Pointer("@request.auth.id != '' && created > 0 || 'backtick`test' = 0")
|
collection.ListRule = types.Pointer("@request.auth.id != '' && created > 0 || 'backtick`test' = 0")
|
||||||
collection.ViewRule = types.Pointer(`id = "1"`)
|
collection.ViewRule = types.Pointer(`id = "1"`)
|
||||||
|
collection.Indexes = types.JsonArray{"create index test on new_name (id)"}
|
||||||
collection.SetOptions(models.CollectionAuthOptions{
|
collection.SetOptions(models.CollectionAuthOptions{
|
||||||
ManageRule: types.Pointer("created > 0"),
|
ManageRule: types.Pointer("created > 0"),
|
||||||
MinPasswordLength: 20,
|
MinPasswordLength: 20,
|
||||||
|
@ -201,6 +208,9 @@ migrate((db) => {
|
||||||
"type": "auth",
|
"type": "auth",
|
||||||
"system": false,
|
"system": false,
|
||||||
"schema": [],
|
"schema": [],
|
||||||
|
"indexes": [
|
||||||
|
"create index test on test456 (id)"
|
||||||
|
],
|
||||||
"listRule": "@request.auth.id != '' && created > 0 || 'backtick` + "`" + `test' = 0",
|
"listRule": "@request.auth.id != '' && created > 0 || 'backtick` + "`" + `test' = 0",
|
||||||
"viewRule": "id = \"1\"",
|
"viewRule": "id = \"1\"",
|
||||||
"createRule": null,
|
"createRule": null,
|
||||||
|
@ -255,6 +265,9 @@ func init() {
|
||||||
"type": "auth",
|
"type": "auth",
|
||||||
"system": false,
|
"system": false,
|
||||||
"schema": [],
|
"schema": [],
|
||||||
|
"indexes": [
|
||||||
|
"create index test on test456 (id)"
|
||||||
|
],
|
||||||
"listRule": "@request.auth.id != '' && created > 0 || ` + "'backtick` + \"`\" + `test' = 0" + `",
|
"listRule": "@request.auth.id != '' && created > 0 || ` + "'backtick` + \"`\" + `test' = 0" + `",
|
||||||
"viewRule": "id = \"1\"",
|
"viewRule": "id = \"1\"",
|
||||||
"createRule": null,
|
"createRule": null,
|
||||||
|
@ -305,6 +318,7 @@ func init() {
|
||||||
collection.Updated = collection.Created
|
collection.Updated = collection.Created
|
||||||
collection.ListRule = types.Pointer("@request.auth.id != '' && created > 0 || 'backtick`test' = 0")
|
collection.ListRule = types.Pointer("@request.auth.id != '' && created > 0 || 'backtick`test' = 0")
|
||||||
collection.ViewRule = types.Pointer(`id = "1"`)
|
collection.ViewRule = types.Pointer(`id = "1"`)
|
||||||
|
collection.Indexes = types.JsonArray{"create index test on test456 (id)"}
|
||||||
collection.SetOptions(models.CollectionAuthOptions{
|
collection.SetOptions(models.CollectionAuthOptions{
|
||||||
ManageRule: types.Pointer("created > 0"),
|
ManageRule: types.Pointer("created > 0"),
|
||||||
MinPasswordLength: 20,
|
MinPasswordLength: 20,
|
||||||
|
@ -367,6 +381,9 @@ migrate((db) => {
|
||||||
collection.listRule = null
|
collection.listRule = null
|
||||||
collection.deleteRule = "updated > 0 && @request.auth.id != ''"
|
collection.deleteRule = "updated > 0 && @request.auth.id != ''"
|
||||||
collection.options = {}
|
collection.options = {}
|
||||||
|
collection.indexes = [
|
||||||
|
"create index test1 on test456_update (f1_name)"
|
||||||
|
]
|
||||||
|
|
||||||
// remove
|
// remove
|
||||||
collection.schema.removeField("f3_id")
|
collection.schema.removeField("f3_id")
|
||||||
|
@ -419,6 +436,9 @@ migrate((db) => {
|
||||||
"onlyEmailDomains": null,
|
"onlyEmailDomains": null,
|
||||||
"requireEmail": false
|
"requireEmail": false
|
||||||
}
|
}
|
||||||
|
collection.indexes = [
|
||||||
|
"create index test1 on test456 (f1_name)"
|
||||||
|
]
|
||||||
|
|
||||||
// add
|
// add
|
||||||
collection.schema.addField(new SchemaField({
|
collection.schema.addField(new SchemaField({
|
||||||
|
@ -488,6 +508,10 @@ func init() {
|
||||||
json.Unmarshal([]byte(` + "`" + `{}` + "`" + `), &options)
|
json.Unmarshal([]byte(` + "`" + `{}` + "`" + `), &options)
|
||||||
collection.SetOptions(options)
|
collection.SetOptions(options)
|
||||||
|
|
||||||
|
json.Unmarshal([]byte(` + "`" + `[
|
||||||
|
"create index test1 on test456_update (f1_name)"
|
||||||
|
]` + "`" + `), &collection.Indexes)
|
||||||
|
|
||||||
// remove
|
// remove
|
||||||
collection.Schema.RemoveField("f3_id")
|
collection.Schema.RemoveField("f3_id")
|
||||||
|
|
||||||
|
@ -554,6 +578,10 @@ func init() {
|
||||||
}` + "`" + `), &options)
|
}` + "`" + `), &options)
|
||||||
collection.SetOptions(options)
|
collection.SetOptions(options)
|
||||||
|
|
||||||
|
json.Unmarshal([]byte(` + "`" + `[
|
||||||
|
"create index test1 on test456 (f1_name)"
|
||||||
|
]` + "`" + `), &collection.Indexes)
|
||||||
|
|
||||||
// add
|
// add
|
||||||
del_f3_name := &schema.SchemaField{}
|
del_f3_name := &schema.SchemaField{}
|
||||||
json.Unmarshal([]byte(` + "`" + `{
|
json.Unmarshal([]byte(` + "`" + `{
|
||||||
|
@ -614,6 +642,7 @@ func init() {
|
||||||
collection.Updated = collection.Created
|
collection.Updated = collection.Created
|
||||||
collection.ListRule = types.Pointer("@request.auth.id != '' && created > 0")
|
collection.ListRule = types.Pointer("@request.auth.id != '' && created > 0")
|
||||||
collection.ViewRule = types.Pointer(`id = "1"`)
|
collection.ViewRule = types.Pointer(`id = "1"`)
|
||||||
|
collection.Indexes = types.JsonArray{"create index test1 on test456 (f1_name)"}
|
||||||
collection.SetOptions(models.CollectionAuthOptions{
|
collection.SetOptions(models.CollectionAuthOptions{
|
||||||
ManageRule: types.Pointer("created > 0"),
|
ManageRule: types.Pointer("created > 0"),
|
||||||
MinPasswordLength: 20,
|
MinPasswordLength: 20,
|
||||||
|
@ -652,6 +681,9 @@ func init() {
|
||||||
collection.Type = models.CollectionTypeBase
|
collection.Type = models.CollectionTypeBase
|
||||||
collection.DeleteRule = types.Pointer(`updated > 0 && @request.auth.id != ''`)
|
collection.DeleteRule = types.Pointer(`updated > 0 && @request.auth.id != ''`)
|
||||||
collection.ListRule = nil
|
collection.ListRule = nil
|
||||||
|
collection.Indexes = types.JsonArray{
|
||||||
|
"create index test1 on test456_update (f1_name)",
|
||||||
|
}
|
||||||
collection.NormalizeOptions()
|
collection.NormalizeOptions()
|
||||||
collection.Schema.RemoveField("f3_id")
|
collection.Schema.RemoveField("f3_id")
|
||||||
collection.Schema.AddField(&schema.SchemaField{
|
collection.Schema.AddField(&schema.SchemaField{
|
||||||
|
|
|
@ -196,6 +196,20 @@ func (p *plugin) jsDiffTemplate(new *models.Collection, old *models.Collection)
|
||||||
downParts = append(downParts, fmt.Sprintf("%s.options = %s", varName, rawOldOptions))
|
downParts = append(downParts, fmt.Sprintf("%s.options = %s", varName, rawOldOptions))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Indexes
|
||||||
|
rawNewIndexes, err := marhshalWithoutEscape(new.Indexes, " ", " ")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
rawOldIndexes, err := marhshalWithoutEscape(old.Indexes, " ", " ")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if !bytes.Equal(rawNewIndexes, rawOldIndexes) {
|
||||||
|
upParts = append(upParts, fmt.Sprintf("%s.indexes = %s", varName, rawNewIndexes))
|
||||||
|
downParts = append(downParts, fmt.Sprintf("%s.indexes = %s", varName, rawOldIndexes))
|
||||||
|
}
|
||||||
|
|
||||||
// ensure new line between regular and collection fields
|
// ensure new line between regular and collection fields
|
||||||
if len(upParts) > 0 {
|
if len(upParts) > 0 {
|
||||||
upParts[len(upParts)-1] += "\n"
|
upParts[len(upParts)-1] += "\n"
|
||||||
|
@ -571,6 +585,21 @@ func (p *plugin) goDiffTemplate(new *models.Collection, old *models.Collection)
|
||||||
downParts = append(downParts, fmt.Sprintf("%s.SetOptions(options)\n", varName))
|
downParts = append(downParts, fmt.Sprintf("%s.SetOptions(options)\n", varName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Indexes
|
||||||
|
rawNewIndexes, err := marhshalWithoutEscape(new.Indexes, "\t\t", "\t")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
rawOldIndexes, err := marhshalWithoutEscape(old.Indexes, "\t\t", "\t")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if !bytes.Equal(rawNewIndexes, rawOldIndexes) {
|
||||||
|
upParts = append(upParts, fmt.Sprintf("json.Unmarshal([]byte(`%s`), &%s.Indexes)\n", escapeBacktick(string(rawNewIndexes)), varName))
|
||||||
|
// ---
|
||||||
|
downParts = append(downParts, fmt.Sprintf("json.Unmarshal([]byte(`%s`), &%s.Indexes)\n", escapeBacktick(string(rawOldIndexes)), varName))
|
||||||
|
}
|
||||||
|
|
||||||
// Schema
|
// Schema
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// deleted fields
|
// deleted fields
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue