"add admin user seed script and refactor common seed utilities"
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
const config = require("/pb_hooks/seed/config.js");
|
||||
const utils = require("/pb_hooks/seed/utils.js");
|
||||
|
||||
module.exports = ($app) => {
|
||||
const ASSETS_DIR = "/pb_hooks/assets";
|
||||
const getAsset = (name) => $filesystem.fileFromPath(ASSETS_DIR + "/" + name);
|
||||
const id_v = "1".padStart(15, 0); //id_vocabulary
|
||||
const id_c = "2".padStart(15, 0); //id_connectives
|
||||
const cat_id_technology = "3".padStart(15, 0);
|
||||
const getId = (id) => id.padStart(15, 0);
|
||||
const { MF_cat_id_news, MF_cat_id_sports, MF_cat_id_technology } = config;
|
||||
const { getId, getAsset, dirtyTruncateTable } = utils;
|
||||
|
||||
let row_array = [
|
||||
[getId("1") ,"news (MF)" ,getAsset("ci_news.jpg") ,1 ,{} ,"visible" ,"news" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("2") ,"sports (MF)" ,getAsset("ci_sports.jpg") ,2 ,{} ,"visible" ,"sports" ,getAsset("mouse.mp3") ,cat_id_technology] ,
|
||||
[getId("3") ,"technology (MF)" ,getAsset("ci_technology.jpg") ,3 ,{} ,"visible" ,"technology" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("4") ,"art (MF)" ,getAsset("ci_art.jpg") ,4 ,{} ,"visible" ,"art" ,getAsset("mouse.mp3") ,cat_id_technology] ,
|
||||
[getId("5") ,"basic (MF)" ,getAsset("ci_basic.jpg") ,5 ,{} ,"visible" ,"basic" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("6") ,"nature (MF)" ,getAsset("ci_nature.jpg") ,6 ,{} ,"visible" ,"nature" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("7") ,"workplace (MF)" ,getAsset("ci_workplace.jpg") ,7 ,{} ,"visible" ,"workplace" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("8") ,"workplace (MF)" ,getAsset("ci_workplace.jpg") ,8 ,{} ,"visible" ,"workplace" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("99") ,"test hidden (MF)" ,getAsset("ci_workplace.jpg") ,9 ,{} ,"hidden" ,"test" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("1"), "news (MF)", getAsset("ci_news.jpg"), 1, ["A", "B", "C"], "visible", "chinese_1", getAsset("keyboard.mp3"), MF_cat_id_news, "中文1"],
|
||||
[getId("2"), "sports (MF)", getAsset("ci_sports.jpg"), 2, ["A", "B", "C"], "visible", "chinese_2", getAsset("mouse.mp3"), MF_cat_id_news, "中文2"],
|
||||
[getId("3"), "technology (MF)", getAsset("ci_technology.jpg"), 3, ["A", "B", "C"], "visible", "chinese_3", getAsset("keyboard.mp3"), MF_cat_id_news, "中文3"],
|
||||
[getId("4"), "art (MF)", getAsset("ci_art.jpg"), 4, ["A", "B", "C"], "visible", "chinese_1", getAsset("mouse.mp3"), MF_cat_id_sports, "中文1"],
|
||||
[getId("5"), "basic (MF)", getAsset("ci_basic.jpg"), 5, ["A", "B", "C"], "visible", "chinese_2", getAsset("keyboard.mp3"), MF_cat_id_sports, "中文2"],
|
||||
[getId("6"), "nature (MF)", getAsset("ci_nature.jpg"), 6, ["A", "B", "C"], "visible", "chinese_3", getAsset("keyboard.mp3"), MF_cat_id_sports, "中文3"],
|
||||
[getId("7"), "workplace (MF)", getAsset("ci_workplace.jpg"), 7, ["A", "B", "C"], "visible", "chinese_1", getAsset("keyboard.mp3"), MF_cat_id_technology, "中文1"],
|
||||
[getId("8"), "workplace (MF)", getAsset("ci_workplace.jpg"), 8, ["A", "B", "C"], "visible", "chinese_2", getAsset("keyboard.mp3"), MF_cat_id_technology, "中文2"],
|
||||
[getId("99"), "test hidden (MF)", getAsset("ci_workplace.jpg"), 9, ["A", "B", "C"], "hidden", "chinese_3", getAsset("keyboard.mp3"), MF_cat_id_technology, "中文3"],
|
||||
];
|
||||
dirtyTruncateTable("QuizMFQuestions");
|
||||
|
||||
@@ -32,7 +32,8 @@ module.exports = ($app) => {
|
||||
record.set("visible", lesson_type[5]);
|
||||
record.set("word", lesson_type[6]);
|
||||
record.set("sound", lesson_type[7]);
|
||||
record.set("cat_id", lesson_type[7]);
|
||||
record.set("cat_id", lesson_type[8]);
|
||||
record.set("word_c", lesson_type[9]);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
@@ -40,8 +41,9 @@ module.exports = ($app) => {
|
||||
console.log(`031_QuizMFQuestions done`);
|
||||
};
|
||||
|
||||
const dirtyTruncateTable = (COLLECTION_NAME) => {
|
||||
console.log(`perform dirty method to truncate table "${COLLECTION_NAME}"`);
|
||||
const cmd_to_exec = $os.cmd("sqlite3", "/pb_data/data.db", `DELETE from ${COLLECTION_NAME};`);
|
||||
cmd_to_exec.output();
|
||||
};
|
||||
// TODO: remove me
|
||||
// const dirtyTruncateTable = (COLLECTION_NAME) => {
|
||||
// console.log(`perform dirty method to truncate table "${COLLECTION_NAME}"`);
|
||||
// const cmd_to_exec = $os.cmd("sqlite3", "/pb_data/data.db", `DELETE from ${COLLECTION_NAME};`);
|
||||
// cmd_to_exec.output();
|
||||
// };
|
||||
|
Reference in New Issue
Block a user