update pocketbase seeding,
This commit is contained in:
3
002_source/pocketbase/pb_hooks/.vscode/settings.json
vendored
Normal file
3
002_source/pocketbase/pb_hooks/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"editor.formatOnSave": false
|
||||
}
|
BIN
002_source/pocketbase/pb_hooks/assets/people1.png
Normal file
BIN
002_source/pocketbase/pb_hooks/assets/people1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 160 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/people2.png
Normal file
BIN
002_source/pocketbase/pb_hooks/assets/people2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 119 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/people3.png
Normal file
BIN
002_source/pocketbase/pb_hooks/assets/people3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 205 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/people4.png
Normal file
BIN
002_source/pocketbase/pb_hooks/assets/people4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 184 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/people5.png
Normal file
BIN
002_source/pocketbase/pb_hooks/assets/people5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 261 KiB |
@@ -22,6 +22,11 @@ $app.rootCmd.addCommand(
|
||||
//
|
||||
require(`${__hooks}/seed/020_QuizLPCategories.js`)($app);
|
||||
require(`${__hooks}/seed/021_QuizLPQuestions.js`)($app);
|
||||
//
|
||||
require(`${__hooks}/seed/030_QuizMFCategories.js`)($app);
|
||||
require(`${__hooks}/seed/031_QuizMFQuestions.js`)($app);
|
||||
//
|
||||
require(`${__hooks}/seed/040_QuizCRCategories.js`)($app);
|
||||
|
||||
$app.reloadCachedCollections();
|
||||
$app.reloadSettings();
|
||||
|
14
002_source/pocketbase/pb_hooks/seed/004_clean_users.js
Normal file
14
002_source/pocketbase/pb_hooks/seed/004_clean_users.js
Normal file
@@ -0,0 +1,14 @@
|
||||
module.exports = ($app) => {
|
||||
console.log("004 clean user table start");
|
||||
|
||||
dirtyTruncateTable("Users");
|
||||
dirtyTruncateTable("UserMetas");
|
||||
|
||||
console.log("004 clean user table 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();
|
||||
};
|
81
002_source/pocketbase/pb_hooks/seed/005_Users_teacher.js
Normal file
81
002_source/pocketbase/pb_hooks/seed/005_Users_teacher.js
Normal file
@@ -0,0 +1,81 @@
|
||||
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
|
||||
|
||||
let row_array = [
|
||||
["11".padStart(15, 0), "teacher1@123.com", "teacher1@123.com", "teacher1@123.com", true, true, "test_user_1"],
|
||||
["12".padStart(15, 0), "teacher2@123.com", "teacher2@123.com", "teacher2@123.com", true, true, "test_user_2"],
|
||||
["13".padStart(15, 0), "teacher3@123.com", "teacher3@123.com", "teacher3@123.com", true, true, "test_user_3"],
|
||||
];
|
||||
|
||||
let um_row_array = [
|
||||
[
|
||||
"11".padStart(15, 0),
|
||||
"teacher1@123.com",
|
||||
"active",
|
||||
"11".padStart(15, 0),
|
||||
JSON.stringify({}),
|
||||
getAsset("people1.png"),
|
||||
"teacher",
|
||||
//
|
||||
],
|
||||
[
|
||||
"12".padStart(15, 0),
|
||||
"teacher2@123.com",
|
||||
"active",
|
||||
"12".padStart(15, 0),
|
||||
JSON.stringify({}),
|
||||
getAsset("people2.png"),
|
||||
"teacher",
|
||||
//
|
||||
],
|
||||
[
|
||||
"13".padStart(15, 0),
|
||||
"teacher3@123.com",
|
||||
"active",
|
||||
"13".padStart(15, 0),
|
||||
JSON.stringify({}),
|
||||
getAsset("people3.png"),
|
||||
"teacher",
|
||||
//
|
||||
],
|
||||
];
|
||||
|
||||
let users_collection = $app.findCollectionByNameOrId("users");
|
||||
let user_metas_collection = $app.findCollectionByNameOrId("UserMetas");
|
||||
|
||||
for (let i = 0; i < row_array.length; i++) {
|
||||
let user = row_array[i];
|
||||
let um = um_row_array[i];
|
||||
|
||||
let record = new Record(users_collection);
|
||||
record.set("id", user[0]);
|
||||
record.set("password", user[1]);
|
||||
record.set("passwordConfirm", user[2]);
|
||||
record.set("email", user[3]);
|
||||
record.set("emailVisibility", user[4]);
|
||||
record.set("verified", user[5]);
|
||||
record.set("name", user[6]);
|
||||
$app.save(record);
|
||||
|
||||
let um_record = new Record(user_metas_collection);
|
||||
um_record.set("id", um[0]);
|
||||
um_record.set("helloworld", um[1]);
|
||||
um_record.set("state", um[2]);
|
||||
um_record.set("user_id", um[3]);
|
||||
um_record.set("meta", um[4]);
|
||||
um_record.set("avatar", um[5]);
|
||||
um_record.set("role", um[6]);
|
||||
$app.save(um_record);
|
||||
}
|
||||
|
||||
console.log("005 add teacher user 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();
|
||||
};
|
58
002_source/pocketbase/pb_hooks/seed/006_Users_student.js
Normal file
58
002_source/pocketbase/pb_hooks/seed/006_Users_student.js
Normal file
@@ -0,0 +1,58 @@
|
||||
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
|
||||
|
||||
let row_array = [
|
||||
["1".padStart(15, 0), "user1@123.com", "user1@123.com", "user1@123.com", true, true, "test_user_1"],
|
||||
["2".padStart(15, 0), "user2@123.com", "user2@123.com", "user2@123.com", true, true, "test_user_2"],
|
||||
["3".padStart(15, 0), "user3@123.com", "user3@123.com", "user3@123.com", true, true, "test_user_3"],
|
||||
["4".padStart(15, 0), "user4@123.com", "user4@123.com", "user4@123.com", true, true, "test_user_4"],
|
||||
["5".padStart(15, 0), "user5@123.com", "user5@123.com", "user5@123.com", true, true, "test_user_5"],
|
||||
];
|
||||
|
||||
let um_row_array = [
|
||||
["1".padStart(15, 0), "user1@123.com", "active", "1".padStart(15, 0), JSON.stringify({}), getAsset("people1.png"), "student"],
|
||||
["2".padStart(15, 0), "user2@123.com", "active", "2".padStart(15, 0), JSON.stringify({}), getAsset("people2.png"), "student"],
|
||||
["3".padStart(15, 0), "user3@123.com", "active", "3".padStart(15, 0), JSON.stringify({}), getAsset("people3.png"), "student"],
|
||||
["4".padStart(15, 0), "user4@123.com", "active", "4".padStart(15, 0), JSON.stringify({}), getAsset("people4.png"), "student"],
|
||||
["5".padStart(15, 0), "user5@123.com", "active", "5".padStart(15, 0), JSON.stringify({}), getAsset("people5.png"), "student"],
|
||||
];
|
||||
|
||||
let users_collection = $app.findCollectionByNameOrId("users");
|
||||
let user_metas_collection = $app.findCollectionByNameOrId("UserMetas");
|
||||
|
||||
for (let i = 0; i < row_array.length; i++) {
|
||||
let user = row_array[i];
|
||||
let um = um_row_array[i];
|
||||
|
||||
let record = new Record(users_collection);
|
||||
record.set("id", user[0]);
|
||||
record.set("password", user[1]);
|
||||
record.set("passwordConfirm", user[2]);
|
||||
record.set("email", user[3]);
|
||||
record.set("emailVisibility", user[4]);
|
||||
record.set("verified", user[5]);
|
||||
record.set("name", user[6]);
|
||||
$app.save(record);
|
||||
|
||||
let um_record = new Record(user_metas_collection);
|
||||
um_record.set("id", um[0]);
|
||||
um_record.set("helloworld", um[1]);
|
||||
um_record.set("state", um[2]);
|
||||
um_record.set("user_id", um[3]);
|
||||
um_record.set("meta", um[4]);
|
||||
um_record.set("avatar", um[5]);
|
||||
um_record.set("role", um[6]);
|
||||
$app.save(um_record);
|
||||
}
|
||||
|
||||
console.log("006 add student user 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();
|
||||
};
|
43
002_source/pocketbase/pb_hooks/seed/020_QuizLPCategories.js
Normal file
43
002_source/pocketbase/pb_hooks/seed/020_QuizLPCategories.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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 getId = (id) => id.padStart(15, 0);
|
||||
let row_array = [
|
||||
[getId("1"), "news (listening)", getAsset("ci_news.jpg"), 1, {}, "visible"],
|
||||
[getId("2"), "sports (listening)", getAsset("ci_sports.jpg"), 2, {}, "visible"],
|
||||
[getId("3"), "technology (listening)", getAsset("ci_technology.jpg"), 3, {}, "visible"],
|
||||
[getId("4"), "art (listening)", getAsset("ci_art.jpg"), 4, {}, "visible"],
|
||||
[getId("5"), "basic (listening)", getAsset("ci_basic.jpg"), 5, {}, "visible"],
|
||||
[getId("6"), "nature (listening)", getAsset("ci_nature.jpg"), 6, {}, "visible"],
|
||||
[getId("7"), "workplace (listening)", getAsset("ci_workplace.jpg"), 7, {}, "visible"],
|
||||
[getId("8"), "workplace (listening)", getAsset("ci_workplace.jpg"), 8, {}, "visible"],
|
||||
[getId("99"), "test hidden (listening)", getAsset("ci_workplace.jpg"), 9, {}, "hidden"],
|
||||
];
|
||||
dirtyTruncateTable("QuizLPCategories");
|
||||
|
||||
let lt_collection = $app.findCollectionByNameOrId("QuizLPCategories");
|
||||
|
||||
for (let i = 0; i < row_array.length; i++) {
|
||||
let lesson_type = row_array[i];
|
||||
|
||||
let record = new Record(lt_collection);
|
||||
record.set("id", lesson_type[0]);
|
||||
record.set("cat_name", lesson_type[1]);
|
||||
record.set("cat_image", lesson_type[2]);
|
||||
record.set("pos", lesson_type[3]);
|
||||
record.set("init_answer", lesson_type[4]);
|
||||
record.set("visible", lesson_type[5]);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
|
||||
console.log(`020_QuizLPCategories 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();
|
||||
};
|
47
002_source/pocketbase/pb_hooks/seed/021_QuizLPQuestions.js
Normal file
47
002_source/pocketbase/pb_hooks/seed/021_QuizLPQuestions.js
Normal file
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
let row_array = [
|
||||
[getId("1") ,"news (LP)" ,getAsset("ci_news.jpg") ,1 ,{} ,"visible" ,"news" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("2") ,"sports (LP)" ,getAsset("ci_sports.jpg") ,2 ,{} ,"visible" ,"sports" ,getAsset("mouse.mp3") ,cat_id_technology] ,
|
||||
[getId("3") ,"technology (LP)" ,getAsset("ci_technology.jpg") ,3 ,{} ,"visible" ,"technology" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("4") ,"art (LP)" ,getAsset("ci_art.jpg") ,4 ,{} ,"visible" ,"art" ,getAsset("mouse.mp3") ,cat_id_technology] ,
|
||||
[getId("5") ,"basic (LP)" ,getAsset("ci_basic.jpg") ,5 ,{} ,"visible" ,"basic" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("6") ,"nature (LP)" ,getAsset("ci_nature.jpg") ,6 ,{} ,"visible" ,"nature" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("7") ,"workplace (LP)" ,getAsset("ci_workplace.jpg") ,7 ,{} ,"visible" ,"workplace" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("8") ,"workplace (LP)" ,getAsset("ci_workplace.jpg") ,8 ,{} ,"visible" ,"workplace" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
[getId("99") ,"test hidden (LP)" ,getAsset("ci_workplace.jpg") ,9 ,{} ,"hidden" ,"test" ,getAsset("keyboard.mp3") ,cat_id_technology] ,
|
||||
];
|
||||
dirtyTruncateTable("QuizLPQuestions");
|
||||
|
||||
let lt_collection = $app.findCollectionByNameOrId("QuizLPQuestions");
|
||||
|
||||
for (let i = 0; i < row_array.length; i++) {
|
||||
let lesson_type = row_array[i];
|
||||
|
||||
let record = new Record(lt_collection);
|
||||
record.set("id", lesson_type[0]);
|
||||
record.set("cat_name", lesson_type[1]);
|
||||
record.set("cat_image", lesson_type[2]);
|
||||
record.set("pos", lesson_type[3]);
|
||||
record.set("init_answer", lesson_type[4]);
|
||||
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]);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
|
||||
console.log(`021_QuizLPQuestions 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();
|
||||
};
|
@@ -0,0 +1,35 @@
|
||||
module.exports = ($app) => {
|
||||
const ASSETS_DIR = "/pb_hooks/assets";
|
||||
const getAsset = (name) => $filesystem.fileFromPath(ASSETS_DIR + "/" + name);
|
||||
const getId = (id) => id.padStart(15, 0);
|
||||
const id_v = getId("1"); //id_vocabulary
|
||||
const id_c = getId("2"); //id_connectives
|
||||
|
||||
let row_array = [
|
||||
[getId("1"), "keyboard", getAsset("keyboard.jpg"), getId("1")],
|
||||
[getId("2"), "mouse", getAsset("mouse.jpg"), getId("1")],
|
||||
];
|
||||
dirtyTruncateTable("QuizLPQuestions");
|
||||
|
||||
let lt_collection = $app.findCollectionByNameOrId("QuizLPQuestions");
|
||||
|
||||
for (let i = 0; i < row_array.length; i++) {
|
||||
let lesson_type = row_array[i];
|
||||
|
||||
let record = new Record(lt_collection);
|
||||
record.set("id", lesson_type[0]);
|
||||
record.set("word", lesson_type[1]);
|
||||
record.set("sound", lesson_type[2]);
|
||||
record.set("cat_id", lesson_type[3]);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
|
||||
console.log(`021 QuizLPQuestions 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();
|
||||
};
|
43
002_source/pocketbase/pb_hooks/seed/030_QuizMFCategories.js
Normal file
43
002_source/pocketbase/pb_hooks/seed/030_QuizMFCategories.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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 getId = (id) => id.padStart(15, 0);
|
||||
let row_array = [
|
||||
[getId("1"), "news (matching)", getAsset("ci_news.jpg"), 1, {}, "visible"],
|
||||
[getId("2"), "sports (matching)", getAsset("ci_sports.jpg"), 2, {}, "visible"],
|
||||
[getId("3"), "technology (matching)", getAsset("ci_technology.jpg"), 3, {}, "visible"],
|
||||
[getId("4"), "art (matching)", getAsset("ci_art.jpg"), 4, {}, "visible"],
|
||||
[getId("5"), "basic (matching)", getAsset("ci_basic.jpg"), 5, {}, "visible"],
|
||||
[getId("6"), "nature (matching)", getAsset("ci_nature.jpg"), 6, {}, "visible"],
|
||||
[getId("7"), "workplace (matching)", getAsset("ci_workplace.jpg"), 7, {}, "visible"],
|
||||
[getId("8"), "workplace (matching)", getAsset("ci_workplace.jpg"), 8, {}, "visible"],
|
||||
[getId("99"), "test hidden (matching)", getAsset("ci_workplace.jpg"), 9, {}, "hidden"],
|
||||
];
|
||||
dirtyTruncateTable("QuizMFCategories");
|
||||
|
||||
let lt_collection = $app.findCollectionByNameOrId("QuizMFCategories");
|
||||
|
||||
for (let i = 0; i < row_array.length; i++) {
|
||||
let lesson_type = row_array[i];
|
||||
|
||||
let record = new Record(lt_collection);
|
||||
record.set("id", lesson_type[0]);
|
||||
record.set("cat_name", lesson_type[1]);
|
||||
record.set("cat_image", lesson_type[2]);
|
||||
record.set("pos", lesson_type[3]);
|
||||
record.set("init_answer", lesson_type[4]);
|
||||
record.set("visible", lesson_type[5]);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
|
||||
console.log(`030_QuizMFCategories 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();
|
||||
};
|
43
002_source/pocketbase/pb_hooks/seed/031_QuizMFQuestions.js
Normal file
43
002_source/pocketbase/pb_hooks/seed/031_QuizMFQuestions.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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 getId = (id) => id.padStart(15, 0);
|
||||
let row_array = [
|
||||
[getId("1"), "news (MF)", getAsset("ci_news.jpg"), 1, {}, "visible"],
|
||||
[getId("2"), "sports (MF)", getAsset("ci_sports.jpg"), 2, {}, "visible"],
|
||||
[getId("3"), "technology (MF)", getAsset("ci_technology.jpg"), 3, {}, "visible"],
|
||||
[getId("4"), "art (MF)", getAsset("ci_art.jpg"), 4, {}, "visible"],
|
||||
[getId("5"), "basic (MF)", getAsset("ci_basic.jpg"), 5, {}, "visible"],
|
||||
[getId("6"), "nature (MF)", getAsset("ci_nature.jpg"), 6, {}, "visible"],
|
||||
[getId("7"), "workplace (MF)", getAsset("ci_workplace.jpg"), 7, {}, "visible"],
|
||||
[getId("8"), "workplace (MF)", getAsset("ci_workplace.jpg"), 8, {}, "visible"],
|
||||
[getId("99"), "test hidden (MF)", getAsset("ci_workplace.jpg"), 9, {}, "hidden"],
|
||||
];
|
||||
dirtyTruncateTable("QuizMFQuestions");
|
||||
|
||||
let lt_collection = $app.findCollectionByNameOrId("QuizMFQuestions");
|
||||
|
||||
for (let i = 0; i < row_array.length; i++) {
|
||||
let lesson_type = row_array[i];
|
||||
|
||||
let record = new Record(lt_collection);
|
||||
record.set("id", lesson_type[0]);
|
||||
record.set("cat_name", lesson_type[1]);
|
||||
record.set("cat_image", lesson_type[2]);
|
||||
record.set("pos", lesson_type[3]);
|
||||
record.set("init_answer", lesson_type[4]);
|
||||
record.set("visible", lesson_type[5]);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
|
||||
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();
|
||||
};
|
43
002_source/pocketbase/pb_hooks/seed/040_QuizCRCategories.js
Normal file
43
002_source/pocketbase/pb_hooks/seed/040_QuizCRCategories.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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 getId = (id) => id.padStart(15, 0);
|
||||
let row_array = [
|
||||
[getId("1"), "news (connect)", getAsset("ci_news.jpg"), 1, {}, "visible"],
|
||||
[getId("2"), "sports (connect)", getAsset("ci_sports.jpg"), 2, {}, "visible"],
|
||||
[getId("3"), "technology (connect)", getAsset("ci_technology.jpg"), 3, {}, "visible"],
|
||||
[getId("4"), "art (connect)", getAsset("ci_art.jpg"), 4, {}, "visible"],
|
||||
[getId("5"), "basic (connect)", getAsset("ci_basic.jpg"), 5, {}, "visible"],
|
||||
[getId("6"), "nature (connect)", getAsset("ci_nature.jpg"), 6, {}, "visible"],
|
||||
[getId("7"), "workplace (connect)", getAsset("ci_workplace.jpg"), 7, {}, "visible"],
|
||||
[getId("8"), "workplace (connect)", getAsset("ci_workplace.jpg"), 8, {}, "visible"],
|
||||
[getId("99"), "test hidden (connect)", getAsset("ci_workplace.jpg"), 9, {}, "hidden"],
|
||||
];
|
||||
dirtyTruncateTable("QuizMFCategories");
|
||||
|
||||
let lt_collection = $app.findCollectionByNameOrId("QuizMFCategories");
|
||||
|
||||
for (let i = 0; i < row_array.length; i++) {
|
||||
let lesson_type = row_array[i];
|
||||
|
||||
let record = new Record(lt_collection);
|
||||
record.set("id", lesson_type[0]);
|
||||
record.set("cat_name", lesson_type[1]);
|
||||
record.set("cat_image", lesson_type[2]);
|
||||
record.set("pos", lesson_type[3]);
|
||||
record.set("init_answer", lesson_type[4]);
|
||||
record.set("visible", lesson_type[5]);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
|
||||
console.log(`030_QuizMFCategories 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();
|
||||
};
|
@@ -1356,6 +1356,20 @@
|
||||
"presentable": false,
|
||||
"system": false,
|
||||
"type": "autodate"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2058414169",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "visible",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"indexes": [],
|
||||
|
@@ -0,0 +1,29 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_1305841361")
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(7, new Field({
|
||||
"hidden": false,
|
||||
"id": "file376926767",
|
||||
"maxSelect": 1,
|
||||
"maxSize": 0,
|
||||
"mimeTypes": [],
|
||||
"name": "avatar",
|
||||
"presentable": false,
|
||||
"protected": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"thumbs": [],
|
||||
"type": "file"
|
||||
}))
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_1305841361")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("file376926767")
|
||||
|
||||
return app.save(collection)
|
||||
})
|
@@ -0,0 +1,29 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_1305841361")
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(8, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text1466534506",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "role",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_1305841361")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text1466534506")
|
||||
|
||||
return app.save(collection)
|
||||
})
|
@@ -0,0 +1,29 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_3639453778")
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(5, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2058414169",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "visible",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_3639453778")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text2058414169")
|
||||
|
||||
return app.save(collection)
|
||||
})
|
@@ -0,0 +1,29 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_3639453778")
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(8, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2560465762",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "slug",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_3639453778")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text2560465762")
|
||||
|
||||
return app.save(collection)
|
||||
})
|
@@ -0,0 +1,28 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_1305841361")
|
||||
|
||||
// update collection data
|
||||
unmarshal({
|
||||
"createRule": "",
|
||||
"deleteRule": "",
|
||||
"listRule": "",
|
||||
"updateRule": "",
|
||||
"viewRule": ""
|
||||
}, collection)
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_1305841361")
|
||||
|
||||
// update collection data
|
||||
unmarshal({
|
||||
"createRule": null,
|
||||
"deleteRule": null,
|
||||
"listRule": null,
|
||||
"updateRule": null,
|
||||
"viewRule": null
|
||||
}, collection)
|
||||
|
||||
return app.save(collection)
|
||||
})
|
@@ -0,0 +1,45 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_3639453778")
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(9, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text1156222427",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "remarks",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(10, new Field({
|
||||
"convertURLs": false,
|
||||
"hidden": false,
|
||||
"id": "editor1843675174",
|
||||
"maxSize": 0,
|
||||
"name": "description",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "editor"
|
||||
}))
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_3639453778")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text1156222427")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("editor1843675174")
|
||||
|
||||
return app.save(collection)
|
||||
})
|
@@ -0,0 +1,29 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_84667061")
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(5, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2058414169",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "visible",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_84667061")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text2058414169")
|
||||
|
||||
return app.save(collection)
|
||||
})
|
@@ -0,0 +1,153 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_742947356")
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(4, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text1125157303",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "cat_name",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(5, new Field({
|
||||
"hidden": false,
|
||||
"id": "file2034676914",
|
||||
"maxSelect": 1,
|
||||
"maxSize": 0,
|
||||
"mimeTypes": [],
|
||||
"name": "cat_image",
|
||||
"presentable": false,
|
||||
"protected": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"thumbs": [],
|
||||
"type": "file"
|
||||
}))
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(6, new Field({
|
||||
"hidden": false,
|
||||
"id": "number2161764012",
|
||||
"max": null,
|
||||
"min": null,
|
||||
"name": "pos",
|
||||
"onlyInt": false,
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "number"
|
||||
}))
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(7, new Field({
|
||||
"hidden": false,
|
||||
"id": "json3915970527",
|
||||
"maxSize": 0,
|
||||
"name": "init_answer",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "json"
|
||||
}))
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(8, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2058414169",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "visible",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(9, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2560465762",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "slug",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(10, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text1156222427",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "remarks",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}))
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(11, new Field({
|
||||
"convertURLs": false,
|
||||
"hidden": false,
|
||||
"id": "editor1843675174",
|
||||
"maxSize": 0,
|
||||
"name": "description",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "editor"
|
||||
}))
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_742947356")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text1125157303")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("file2034676914")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("number2161764012")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("json3915970527")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text2058414169")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text2560465762")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("text1156222427")
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById("editor1843675174")
|
||||
|
||||
return app.save(collection)
|
||||
})
|
@@ -0,0 +1,28 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_1305841361")
|
||||
|
||||
// update collection data
|
||||
unmarshal({
|
||||
"createRule": "",
|
||||
"deleteRule": "",
|
||||
"listRule": "",
|
||||
"updateRule": "",
|
||||
"viewRule": ""
|
||||
}, collection)
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId("pbc_1305841361")
|
||||
|
||||
// update collection data
|
||||
unmarshal({
|
||||
"createRule": null,
|
||||
"deleteRule": null,
|
||||
"listRule": null,
|
||||
"updateRule": null,
|
||||
"viewRule": null
|
||||
}, collection)
|
||||
|
||||
return app.save(collection)
|
||||
})
|
Reference in New Issue
Block a user