update seed,

This commit is contained in:
louiscklaw
2025-04-19 04:24:50 +08:00
parent 0d554e70ee
commit 2c20496a13
15 changed files with 105 additions and 6480 deletions

View File

@@ -15,8 +15,13 @@ $app.rootCmd.addCommand(
require(`${__hooks}/seed/001_seed_LessonsTypes.js`)($app);
require(`${__hooks}/seed/002_LessonsCategories.js`)($app);
require(`${__hooks}/seed/003_Categories.js`)($app);
require(`${__hooks}/seed/004_Users.js`)($app);
require(`${__hooks}/seed/004_clean_users.js`)($app);
require(`${__hooks}/seed/005_Users_teacher.js`)($app);
require(`${__hooks}/seed/006_Users_student.js`)($app);
require(`${__hooks}/seed/010_Vocabularies.js`)($app);
//
require(`${__hooks}/seed/020_QuizLPCategories.js`)($app);
require(`${__hooks}/seed/021_QuizLPQuestions.js`)($app);
$app.reloadCachedCollections();
$app.reloadSettings();

View File

@@ -26,7 +26,7 @@ module.exports = ($app) => {
$app.save(record);
}
console.log("seeding done");
console.log("001 lesson types seeding done");
};
const dirtyTruncateTable = (COLLECTION_NAME) => {

View File

@@ -39,7 +39,7 @@ module.exports = ($app) => {
$app.save(record);
}
console.log("seeding done");
console.log("002 lesson categories seeding done");
};
const dirtyTruncateTable = (COLLECTION_NAME) => {

View File

@@ -1,48 +1,48 @@
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
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), 'news', '', getAsset('ci_news.jpg'), 1, 'visible', id_v, 'desc', 'remarks'],
['2'.padStart(15, 0), 'sports', '', getAsset('ci_sports.jpg'), 1, 'visible', id_v, 'desc', 'remarks'],
['3'.padStart(15, 0), 'technology', '', getAsset('ci_technology.jpg'), 1, 'visible', id_v, 'desc', 'remarks'],
['4'.padStart(15, 0), 'art', '', getAsset('ci_art.jpg'), 1, 'visible', id_v, 'desc', 'remarks'],
['5'.padStart(15, 0), 'basic', '', getAsset('ci_basic.jpg'), 1, 'visible', id_v, 'desc', 'remarks'],
['6'.padStart(15, 0), 'nature', '', getAsset('ci_nature.jpg'), 1, 'visible', id_v, 'desc', 'remarks'],
['7'.padStart(15, 0), 'workplace', '', getAsset('ci_workplace.jpg'), 1, 'visible', id_v, 'desc', 'remarks'],
['99'.padStart(15, 0), 'connectives', '', getAsset('1.png'), 1, 'visible', id_c, 'desc', 'remarks'],
["1".padStart(15, 0), "news", "", getAsset("ci_news.jpg"), 1, "visible", id_v, "desc", "remarks"],
["2".padStart(15, 0), "sports", "", getAsset("ci_sports.jpg"), 1, "visible", id_v, "desc", "remarks"],
["3".padStart(15, 0), "technology", "", getAsset("ci_technology.jpg"), 1, "visible", id_v, "desc", "remarks"],
["4".padStart(15, 0), "art", "", getAsset("ci_art.jpg"), 1, "visible", id_v, "desc", "remarks"],
["5".padStart(15, 0), "basic", "", getAsset("ci_basic.jpg"), 1, "visible", id_v, "desc", "remarks"],
["6".padStart(15, 0), "nature", "", getAsset("ci_nature.jpg"), 1, "visible", id_v, "desc", "remarks"],
["7".padStart(15, 0), "workplace", "", getAsset("ci_workplace.jpg"), 1, "visible", id_v, "desc", "remarks"],
["99".padStart(15, 0), "connectives", "", getAsset("1.png"), 1, "visible", id_c, "desc", "remarks"],
// ["2".padStart(15, 0), "Connectives", "connectivse", 1, "visible"],
// ["3".padStart(15, 0), "Testing visible", "testing", 3, "visible"],
// ["4".padStart(15, 0), "Testing hidden", "testing", 3, "hidden"],
];
dirtyTruncateTable('Categories');
dirtyTruncateTable("Categories");
let lt_collection = $app.findCollectionByNameOrId('Categories');
let lt_collection = $app.findCollectionByNameOrId("Categories");
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_url', lesson_type[2]);
record.set('cat_image', lesson_type[3]);
record.set('pos', lesson_type[4]);
record.set('visible', lesson_type[5]);
record.set('lesson_id', lesson_type[6]);
record.set('description', lesson_type[7]);
record.set('remarks', lesson_type[8]);
record.set("id", lesson_type[0]);
record.set("cat_name", lesson_type[1]);
record.set("cat_image_url", lesson_type[2]);
record.set("cat_image", lesson_type[3]);
record.set("pos", lesson_type[4]);
record.set("visible", lesson_type[5]);
record.set("lesson_id", lesson_type[6]);
record.set("description", lesson_type[7]);
record.set("remarks", lesson_type[8]);
$app.save(record);
}
console.log('seeding done');
console.log("003 categories seeding done");
};
const dirtyTruncateTable = COLLECTION_NAME => {
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};`);
const cmd_to_exec = $os.cmd("sqlite3", "/pb_data/data.db", `DELETE from ${COLLECTION_NAME};`);
cmd_to_exec.output();
};

View File

@@ -1,58 +0,0 @@
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"],
];
dirtyTruncateTable("Users");
let um_row_array = [
["1".padStart(15, 0), "user1@123.com", "active", "1".padStart(15, 0), JSON.stringify({})],
["2".padStart(15, 0), "user2@123.com", "active", "2".padStart(15, 0), JSON.stringify({})],
["3".padStart(15, 0), "user3@123.com", "active", "3".padStart(15, 0), JSON.stringify({})],
["4".padStart(15, 0), "user4@123.com", "active", "4".padStart(15, 0), JSON.stringify({})],
["5".padStart(15, 0), "user5@123.com", "active", "5".padStart(15, 0), JSON.stringify({})],
];
dirtyTruncateTable("UserMetas");
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]);
$app.save(um_record);
}
console.log("seeding 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();
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -771,6 +771,17 @@
"presentable": false,
"system": false,
"type": "autodate"
},
{
"hidden": false,
"id": "date1542800728",
"max": "",
"min": "",
"name": "field",
"presentable": false,
"required": false,
"system": false,
"type": "date"
}
],
"indexes": [],
@@ -1884,6 +1895,48 @@
"presentable": false,
"system": false,
"type": "autodate"
},
{
"autogeneratePattern": "",
"hidden": false,
"id": "text2744374011",
"max": 0,
"min": 0,
"name": "state",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"hidden": false,
"id": "file376926767",
"maxSelect": 1,
"maxSize": 0,
"mimeTypes": [],
"name": "avatar",
"presentable": false,
"protected": false,
"required": false,
"system": false,
"thumbs": [],
"type": "file"
},
{
"autogeneratePattern": "",
"hidden": false,
"id": "text1466534506",
"max": 0,
"min": 0,
"name": "role",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
}
],
"indexes": [],
@@ -2576,9 +2629,23 @@
"presentable": false,
"system": false,
"type": "autodate"
},
{
"hidden": false,
"id": "file2313559263",
"maxSelect": 1,
"maxSize": 0,
"mimeTypes": [],
"name": "test_file",
"presentable": false,
"protected": false,
"required": false,
"system": false,
"thumbs": [],
"type": "file"
}
],
"indexes": [],
"system": false
}
]
]