"add admin user seed script and refactor common seed utilities"
This commit is contained in:
@@ -1,46 +1,21 @@
|
||||
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 { CR_cat_id_news, CR_cat_id_technology } = config;
|
||||
const { getId, getAsset } = utils;
|
||||
|
||||
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"],
|
||||
[getId("11"), "teacher1@123.com", "teacher1@123.com", "teacher1@123.com", true, true, "test_teacher_1"],
|
||||
[getId("12"), "teacher2@123.com", "teacher2@123.com", "teacher2@123.com", true, true, "test_teacher_2"],
|
||||
[getId("13"), "teacher3@123.com", "teacher3@123.com", "teacher3@123.com", true, true, "test_teacher_3"],
|
||||
];
|
||||
|
||||
// um = user_meta
|
||||
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",
|
||||
//
|
||||
],
|
||||
[getId("11"), "teacher1@123.com", "active", getId("11"), JSON.stringify({}), getAsset("people1.png"), "teacher", "teacher_1"],
|
||||
[getId("12"), "teacher2@123.com", "pending", getId("12"), JSON.stringify({}), getAsset("people2.png"), "teacher", "teacher_2"],
|
||||
[getId("13"), "teacher3@123.com", "blocked", getId("13"), JSON.stringify({}), getAsset("people3.png"), "teacher", "teacher_3"],
|
||||
];
|
||||
|
||||
let users_collection = $app.findCollectionByNameOrId("users");
|
||||
@@ -63,19 +38,29 @@ module.exports = ($app) => {
|
||||
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("status", um[2]);
|
||||
um_record.set("user_id", um[3]);
|
||||
um_record.set("meta", um[4]);
|
||||
|
||||
// NOTE: obslete "avatar" and use "avatar_file"
|
||||
um_record.set("avatar", um[5]);
|
||||
um_record.set("avatar_file", um[5]);
|
||||
//
|
||||
|
||||
um_record.set("role", um[6]);
|
||||
um_record.set("name", um[7]);
|
||||
um_record.set("email", user[3]);
|
||||
um_record.set("phone", "9123456" + i.toString());
|
||||
|
||||
$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();
|
||||
};
|
||||
// TODO: delete this ?
|
||||
// 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