feat: implement micro-learning system with content delivery components, completion tracking hooks, and database schema migrations
This commit is contained in:
183
pb_migrations/1780800000_created_micro_learnings.js
Normal file
183
pb_migrations/1780800000_created_micro_learnings.js
Normal file
@@ -0,0 +1,183 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
// Create micro_learnings collection
|
||||
const microLearnings = new Collection({
|
||||
"id": "pbc_micro_learnings_0",
|
||||
"name": "micro_learnings",
|
||||
"type": "base",
|
||||
"system": false,
|
||||
"schema": [
|
||||
{
|
||||
"system": false,
|
||||
"id": "rel_topic_id",
|
||||
"name": "topic_id",
|
||||
"type": "relation",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {
|
||||
"collectionId": "pbc_2800040823", // the ID for topics from snapshot (we will use topic name later if possible, but let's just use collectionName: "topics")
|
||||
"cascadeDelete": true,
|
||||
"minSelect": null,
|
||||
"maxSelect": 1,
|
||||
"displayFields": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"system": false,
|
||||
"id": "sel_type",
|
||||
"name": "type",
|
||||
"type": "select",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {
|
||||
"maxSelect": 1,
|
||||
"values": [
|
||||
"concept_explainer",
|
||||
"scenario_quiz",
|
||||
"flashcard_set",
|
||||
"reflection_prompt"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"system": false,
|
||||
"id": "json_content",
|
||||
"name": "content",
|
||||
"type": "json",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"system": false,
|
||||
"id": "sel_status",
|
||||
"name": "status",
|
||||
"type": "select",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {
|
||||
"maxSelect": 1,
|
||||
"values": [
|
||||
"draft",
|
||||
"published"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"indexes": [],
|
||||
"listRule": "status = 'published'",
|
||||
"viewRule": "status = 'published'",
|
||||
"createRule": null,
|
||||
"updateRule": null,
|
||||
"deleteRule": null
|
||||
});
|
||||
|
||||
// Since we don't know the exact ID of topics collection safely across instances without looking it up,
|
||||
// we can look it up first.
|
||||
const topicsCollection = app.findCollectionByNameOrId("topics");
|
||||
microLearnings.schema.getFieldByName("topic_id").options.collectionId = topicsCollection.id;
|
||||
|
||||
app.save(microLearnings);
|
||||
|
||||
// Create micro_learning_completions collection
|
||||
const completions = new Collection({
|
||||
"id": "pbc_ml_completions_0",
|
||||
"name": "micro_learning_completions",
|
||||
"type": "base",
|
||||
"system": false,
|
||||
"schema": [
|
||||
{
|
||||
"system": false,
|
||||
"id": "rel_team_member_id",
|
||||
"name": "team_member_id",
|
||||
"type": "relation",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {
|
||||
"collectionId": "team_members_placeholder",
|
||||
"cascadeDelete": true,
|
||||
"minSelect": null,
|
||||
"maxSelect": 1,
|
||||
"displayFields": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"system": false,
|
||||
"id": "rel_micro_learning_id",
|
||||
"name": "micro_learning_id",
|
||||
"type": "relation",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {
|
||||
"collectionId": microLearnings.id,
|
||||
"cascadeDelete": true,
|
||||
"minSelect": null,
|
||||
"maxSelect": 1,
|
||||
"displayFields": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"system": false,
|
||||
"id": "rel_comp_topic_id",
|
||||
"name": "topic_id",
|
||||
"type": "relation",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {
|
||||
"collectionId": topicsCollection.id,
|
||||
"cascadeDelete": true,
|
||||
"minSelect": null,
|
||||
"maxSelect": 1,
|
||||
"displayFields": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"system": false,
|
||||
"id": "txt_comp_type",
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": null,
|
||||
"pattern": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"system": false,
|
||||
"id": "num_session_week",
|
||||
"name": "session_week",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": null,
|
||||
"noDecimal": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"indexes": [],
|
||||
"listRule": "@request.auth.id != '' && team_member_id.user_id = @request.auth.id",
|
||||
"viewRule": "@request.auth.id != '' && team_member_id.user_id = @request.auth.id",
|
||||
"createRule": "@request.auth.id != ''",
|
||||
"updateRule": null,
|
||||
"deleteRule": null
|
||||
});
|
||||
|
||||
const teamMembersCollection = app.findCollectionByNameOrId("team_members");
|
||||
completions.schema.getFieldByName("team_member_id").options.collectionId = teamMembersCollection.id;
|
||||
|
||||
app.save(completions);
|
||||
|
||||
}, (app) => {
|
||||
const completions = app.findCollectionByNameOrId("micro_learning_completions");
|
||||
if (completions) {
|
||||
app.delete(completions);
|
||||
}
|
||||
const microLearnings = app.findCollectionByNameOrId("micro_learnings");
|
||||
if (microLearnings) {
|
||||
app.delete(microLearnings);
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user