mirror of
https://github.com/grassrootseconomics/farmstar-survey-backend.git
synced 2025-05-22 09:36:46 +02:00
127 lines
2.5 KiB
Go
127 lines
2.5 KiB
Go
package migrations
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/pocketbase/dbx"
|
|
"github.com/pocketbase/pocketbase/daos"
|
|
m "github.com/pocketbase/pocketbase/migrations"
|
|
"github.com/pocketbase/pocketbase/models"
|
|
)
|
|
|
|
func init() {
|
|
m.Register(func(db dbx.Builder) error {
|
|
jsonData := `[
|
|
{
|
|
"id": "no89qd9ku8qo11e",
|
|
"created": "2023-12-18 09:15:06.545Z",
|
|
"updated": "2023-12-18 09:15:06.545Z",
|
|
"name": "users",
|
|
"type": "base",
|
|
"system": false,
|
|
"schema": [
|
|
{
|
|
"system": false,
|
|
"id": "rbi2ukrm",
|
|
"name": "name",
|
|
"type": "text",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"min": 2,
|
|
"max": 150,
|
|
"pattern": ""
|
|
}
|
|
},
|
|
{
|
|
"system": false,
|
|
"id": "4l7bnhvh",
|
|
"name": "phone",
|
|
"type": "text",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"min": 10,
|
|
"max": 10,
|
|
"pattern": "^(07|01)(\\d){8}$"
|
|
}
|
|
},
|
|
{
|
|
"system": false,
|
|
"id": "tvicnnyp",
|
|
"name": "gender",
|
|
"type": "select",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"maxSelect": 1,
|
|
"values": [
|
|
"female",
|
|
"male",
|
|
"transgender",
|
|
"other",
|
|
"no_response"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"system": false,
|
|
"id": "otfoqjhn",
|
|
"name": "age_group",
|
|
"type": "select",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"maxSelect": 1,
|
|
"values": [
|
|
"20-29",
|
|
"30-39",
|
|
"40-49-50-59",
|
|
"60-69"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"system": false,
|
|
"id": "mf34mr31",
|
|
"name": "participant_type",
|
|
"type": "select",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"maxSelect": 1,
|
|
"values": [
|
|
"farmer",
|
|
"distributor"
|
|
]
|
|
}
|
|
}
|
|
],
|
|
"indexes": [
|
|
"CREATE INDEX ` + "`" + `idx_ljmcgDQ` + "`" + ` ON ` + "`" + `users` + "`" + ` (` + "`" + `phone` + "`" + `)"
|
|
],
|
|
"listRule": null,
|
|
"viewRule": null,
|
|
"createRule": null,
|
|
"updateRule": null,
|
|
"deleteRule": null,
|
|
"options": {}
|
|
}
|
|
]`
|
|
|
|
collections := []*models.Collection{}
|
|
if err := json.Unmarshal([]byte(jsonData), &collections); err != nil {
|
|
return err
|
|
}
|
|
|
|
return daos.New(db).ImportCollections(collections, true, nil)
|
|
}, func(db dbx.Builder) error {
|
|
return nil
|
|
})
|
|
}
|