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": "2024-01-31 11:54:55.087Z", "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", "70+" ] } }, { "system": false, "id": "mf34mr31", "name": "participant_type", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "farmer", "distributor" ] } }, { "system": false, "id": "to7xfaj9", "name": "activated", "type": "bool", "required": false, "presentable": false, "unique": false, "options": {} } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_ljmcgDQ` + "`" + ` ON ` + "`" + `users` + "`" + ` (` + "`" + `phone` + "`" + `)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "uutt9wj7d5ejmhz", "created": "2024-01-02 09:20:31.919Z", "updated": "2024-01-31 11:54:55.132Z", "name": "farmer_farm", "type": "base", "system": false, "schema": [ { "system": false, "id": "z2puetdy", "name": "user", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "murxdavm", "name": "county", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "kirinyaga", "muranga", "nakuru", "meru", "uasin_gishu", "kajiado" ] } }, { "system": false, "id": "zj3ufuxl", "name": "sub_county", "type": "text", "required": true, "presentable": false, "unique": false, "options": { "min": null, "max": 48, "pattern": "" } }, { "system": false, "id": "8kouirkv", "name": "farming_area_acres", "type": "number", "required": true, "presentable": false, "unique": false, "options": { "min": 1, "max": null, "noDecimal": false } }, { "system": false, "id": "p4n5v8yf", "name": "planned_crops", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 12, "values": [ "rice", "coffee", "tea", "sugarcane", "miraa", "avocados", "maize", "potatoes", "sorghum", "other_fruits", "other_vegetables", "other_grains" ] } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_AFv2Mj9` + "`" + ` ON ` + "`" + `farmer_farm` + "`" + ` (` + "`" + `user` + "`" + `)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "5pbnsptw25ip6b1", "created": "2024-01-02 10:05:21.762Z", "updated": "2024-01-31 11:54:55.133Z", "name": "farmer_past_harvest", "type": "base", "system": false, "schema": [ { "system": false, "id": "xhv4eaig", "name": "user", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "gt06xc9v", "name": "crop", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "rice", "coffee", "tea", "sugarcane", "miraa", "avocados", "maize", "potatoes", "sorghum", "other_fruits", "other_vegetables", "other_grains" ] } }, { "system": false, "id": "1d5brrhe", "name": "average_harvest", "type": "number", "required": true, "presentable": false, "unique": false, "options": { "min": 1, "max": null, "noDecimal": false } }, { "system": false, "id": "ppm9bhbp", "name": "average_earning", "type": "number", "required": true, "presentable": false, "unique": false, "options": { "min": 1, "max": null, "noDecimal": false } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_YIwO9th` + "`" + ` ON ` + "`" + `farmer_past_harvest` + "`" + ` (\n ` + "`" + `user` + "`" + `,\n ` + "`" + `crop` + "`" + `\n)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "5ntmsa3wexlrqvb", "created": "2024-01-02 10:37:18.392Z", "updated": "2024-01-31 11:54:55.134Z", "name": "farmer_expenditure_base", "type": "base", "system": false, "schema": [ { "system": false, "id": "v4mgvwjl", "name": "user", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "epub5bri", "name": "total_expenditure", "type": "number", "required": true, "presentable": false, "unique": false, "options": { "min": 1, "max": null, "noDecimal": false } }, { "system": false, "id": "zxysfvfy", "name": "seeds_expenditure_percentage", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 100, "noDecimal": true } }, { "system": false, "id": "fgplvyyp", "name": "fertilizer_expenditure_percentage", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 100, "noDecimal": true } }, { "system": false, "id": "twefdlqh", "name": "crops_protection_expenditure_percentage", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 100, "noDecimal": true } }, { "system": false, "id": "vwuti9fs", "name": "synthetic_fertilizers_expenditure_percentage", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 100, "noDecimal": true } }, { "system": false, "id": "jeumwxyx", "name": "natural_fertilizers_expenditure_percentage", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 100, "noDecimal": true } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_pEBpN7N` + "`" + ` ON ` + "`" + `farmer_expenditure_base` + "`" + ` (` + "`" + `user` + "`" + `)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "vlcx36spbdrxxe2", "created": "2024-01-02 15:21:44.736Z", "updated": "2024-01-31 11:54:55.126Z", "name": "farmer_expenditure_increased", "type": "base", "system": false, "schema": [ { "system": false, "id": "b1hhoaxw", "name": "user", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "yrvfoc0e", "name": "expense", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "seeds", "fertilizers", "crop_protection" ] } }, { "system": false, "id": "pe41jgz8", "name": "actions", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 5, "values": [ "no_change", "cheap_alternative", "less_quantity", "more_quantity", "other" ] } }, { "system": false, "id": "16wscle0", "name": "overall_effect", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "increased_yields", "no_change_yields", "decreased_yields", "other" ] } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_wwcFC9l` + "`" + ` ON ` + "`" + `farmer_expenditure_increased` + "`" + ` (\n ` + "`" + `user` + "`" + `,\n ` + "`" + `expense` + "`" + `\n)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "4f0a5b2wec6okxi", "created": "2024-01-02 15:40:45.994Z", "updated": "2024-01-31 11:54:55.138Z", "name": "farmer_evergrow", "type": "base", "system": false, "schema": [ { "system": false, "id": "r7hegvf3", "name": "user", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "ymkvcxmw", "name": "evergrow_past", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "yes", "no" ] } }, { "system": false, "id": "maxzlwxk", "name": "evergrow_first", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": 2018, "max": null, "noDecimal": true } }, { "system": false, "id": "silbtgao", "name": "evergrow_application", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": 1, "max": null, "noDecimal": false } }, { "system": false, "id": "5kxslfpx", "name": "evergrow_crops", "type": "select", "required": false, "presentable": false, "unique": false, "options": { "maxSelect": 12, "values": [ "rice", "coffee", "tea", "sugarcane", "miraa", "avocados", "maize", "potatoes", "sorghum", "other_fruits", "other_vegetables", "other_grains" ] } }, { "system": false, "id": "yvcfbmgq", "name": "evergrow_yield", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": 0, "max": 100, "noDecimal": false } }, { "system": false, "id": "kfjmtcd8", "name": "other_fertilizers", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "yes", "no", "not_sure" ] } }, { "system": false, "id": "fl4s3aca", "name": "purchase_channels", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 5, "values": [ "manufacturers", "distributors", "resellers", "farmers", "other" ] } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_q5i3j4r` + "`" + ` ON ` + "`" + `farmer_evergrow` + "`" + ` (` + "`" + `user` + "`" + `)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "o7i7dkfc0x2bw22", "created": "2024-01-02 16:07:23.643Z", "updated": "2024-01-31 11:54:55.137Z", "name": "farmer_other_fertilizers", "type": "base", "system": false, "schema": [ { "system": false, "id": "vxiny0jx", "name": "user", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "xswrk51v", "name": "fertilizer_type", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "synthetic", "commercial_organic", "self_made" ] } }, { "system": false, "id": "njshkmtb", "name": "fertilizer_application", "type": "number", "required": true, "presentable": false, "unique": false, "options": { "min": 1, "max": null, "noDecimal": false } }, { "system": false, "id": "ltb2rowr", "name": "crops", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 12, "values": [ "rice", "coffee", "tea", "sugarcane", "miraa", "avocados", "maize", "potatoes", "sorghum", "other_fruits", "other_vegetables", "other_grains" ] } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_yRpihp0` + "`" + ` ON ` + "`" + `farmer_other_fertilizers` + "`" + ` (\n ` + "`" + `user` + "`" + `,\n ` + "`" + `fertilizer_type` + "`" + `\n)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "w7vsnhq55laqara", "created": "2024-01-05 08:01:27.594Z", "updated": "2024-01-31 15:28:56.809Z", "name": "transactions", "type": "base", "system": false, "schema": [ { "system": false, "id": "s54vsu9e", "name": "initiator", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "novr3jwr", "name": "tx_type", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "buy", "sell" ] } }, { "system": false, "id": "rhzeviz3", "name": "tx_date", "type": "date", "required": true, "presentable": false, "unique": false, "options": { "min": "", "max": "" } }, { "system": false, "id": "fhrpguaa", "name": "feedback", "type": "text", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": null, "pattern": "" } }, { "system": false, "id": "mp9n48r0", "name": "evergrow_quantity", "type": "number", "required": true, "presentable": false, "unique": false, "options": { "min": null, "max": null, "noDecimal": false } }, { "system": false, "id": "ssxqbyea", "name": "counterparty", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "rjvhxlwa", "name": "distributor_name", "type": "select", "required": false, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "maraba_investments", "farmers_center", "farmers_world", "farmers_desk", "mazao_na_afya" ] } }, { "system": false, "id": "kwzoawdf", "name": "completed", "type": "bool", "required": false, "presentable": false, "unique": false, "options": {} } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_tf57wcj` + "`" + ` ON ` + "`" + `transactions` + "`" + ` (\n ` + "`" + `initiator` + "`" + `,\n ` + "`" + `tx_type` + "`" + `,\n ` + "`" + `tx_date` + "`" + `,\n ` + "`" + `evergrow_quantity` + "`" + `,\n ` + "`" + `counterparty` + "`" + `,\n ` + "`" + `distributor_name` + "`" + `,\n ` + "`" + `completed` + "`" + `\n)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "hcgj54gqdujejom", "created": "2024-01-07 08:46:55.596Z", "updated": "2024-01-31 11:54:55.139Z", "name": "distributor_base", "type": "base", "system": false, "schema": [ { "system": false, "id": "hni6qzrl", "name": "user", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "zadtcvlf", "name": "distributor_name", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "maraba_investments", "farmers_center", "farmers_world", "farmers_desk", "mazao_na_afya" ] } }, { "system": false, "id": "sbchpt8f", "name": "fertilizer_type", "type": "select", "required": true, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "synthetic", "organic", "both" ] } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_HM1joZe` + "`" + ` ON ` + "`" + `distributor_base` + "`" + ` (` + "`" + `user` + "`" + `)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "7c6woqfe2ds77z7", "created": "2024-01-07 08:53:59.056Z", "updated": "2024-01-31 11:54:55.145Z", "name": "distributor_both_fertilizers", "type": "base", "system": false, "schema": [ { "system": false, "id": "4lfninvo", "name": "user", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": true, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "1jqo9v3q", "name": "synthetic_percentage", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": 0, "max": 100, "noDecimal": false } }, { "system": false, "id": "st7q1h1q", "name": "organic_percentage", "type": "number", "required": false, "presentable": false, "unique": false, "options": { "min": 0, "max": 100, "noDecimal": false } }, { "system": false, "id": "j2lja34g", "name": "synthetic_factors", "type": "select", "required": false, "presentable": false, "unique": false, "options": { "maxSelect": 7, "values": [ "increased_crop_yield", "cost_effective", "ease_of_application", "availability", "marketing", "govt_incentives", "other" ] } }, { "system": false, "id": "hizudbmp", "name": "organic_factors", "type": "select", "required": false, "presentable": false, "unique": false, "options": { "maxSelect": 10, "values": [ "increased_crop_yield", "cost_effective", "ease_of_application", "availability", "marketing", "govt_incentives", "other", "environmental_concerns", "soil_health", "consumer_demand" ] } }, { "system": false, "id": "dwlhi6wp", "name": "trends", "type": "text", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 250, "pattern": "" } }, { "system": false, "id": "wddxsdtk", "name": "obstacles", "type": "text", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 250, "pattern": "" } }, { "system": false, "id": "q5flyusx", "name": "need_education", "type": "select", "required": false, "presentable": false, "unique": false, "options": { "maxSelect": 1, "values": [ "yes", "no" ] } }, { "system": false, "id": "j32zm5eo", "name": "organic_strategies", "type": "text", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 250, "pattern": "" } }, { "system": false, "id": "joxlvz5k", "name": "farmstar_strategies", "type": "text", "required": false, "presentable": false, "unique": false, "options": { "min": null, "max": 500, "pattern": "" } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_xLt1fh6` + "`" + ` ON ` + "`" + `distributor_both_fertilizers` + "`" + ` (` + "`" + `user` + "`" + `)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "x7rkbev8ny0nte4", "created": "2024-02-01 10:43:44.058Z", "updated": "2024-02-01 10:50:27.630Z", "name": "rewards", "type": "base", "system": false, "schema": [ { "system": false, "id": "zuszdgix", "name": "receiver", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": false, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "dmrczxxp", "name": "ge_tracking_id", "type": "text", "required": true, "presentable": false, "unique": false, "options": { "min": null, "max": null, "pattern": "" } }, { "system": false, "id": "obhsiosq", "name": "value", "type": "number", "required": true, "presentable": false, "unique": false, "options": { "min": null, "max": null, "noDecimal": true } } ], "indexes": [ "CREATE UNIQUE INDEX ` + "`" + `idx_mG3rro1` + "`" + ` ON ` + "`" + `rewards` + "`" + ` (` + "`" + `ge_tracking_id` + "`" + `)" ], "listRule": null, "viewRule": null, "createRule": null, "updateRule": null, "deleteRule": null, "options": {} }, { "id": "ukijuvvvum7pkuz", "created": "2024-02-01 14:14:28.912Z", "updated": "2024-02-01 14:14:28.912Z", "name": "redemption", "type": "base", "system": false, "schema": [ { "system": false, "id": "nnqddcbc", "name": "distributor_initiator", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": false, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "96bbrwxz", "name": "distributor", "type": "text", "required": true, "presentable": false, "unique": false, "options": { "min": null, "max": null, "pattern": "" } }, { "system": false, "id": "rr1lvsdt", "name": "farmer", "type": "relation", "required": true, "presentable": false, "unique": false, "options": { "collectionId": "no89qd9ku8qo11e", "cascadeDelete": false, "minSelect": null, "maxSelect": 1, "displayFields": null } }, { "system": false, "id": "nk1xzoo6", "name": "fsp_redemption_request", "type": "number", "required": true, "presentable": false, "unique": false, "options": { "min": null, "max": null, "noDecimal": true } } ], "indexes": [], "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 }) }