update pocketbase schema,
BIN
002_source/pocketbase/pb_hooks/assets/1.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/ci_art.jpg
Normal file
After Width: | Height: | Size: 963 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/ci_basic.jpg
Normal file
After Width: | Height: | Size: 355 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/ci_nature.jpg
Normal file
After Width: | Height: | Size: 386 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/ci_news.jpg
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/ci_sports.jpg
Normal file
After Width: | Height: | Size: 423 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/ci_technology.jpg
Normal file
After Width: | Height: | Size: 355 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/ci_workplace.jpg
Normal file
After Width: | Height: | Size: 355 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/keyboard.jpg
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/keyboard.mp3
Normal file
BIN
002_source/pocketbase/pb_hooks/assets/mouse.jpg
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
002_source/pocketbase/pb_hooks/assets/mouse.mp3
Normal file
6
002_source/pocketbase/pb_hooks/onBootstrap.pb.js
Normal file
@@ -0,0 +1,6 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
onBootstrap((e) => {
|
||||
e.next();
|
||||
console.log("App initialized!");
|
||||
});
|
24
002_source/pocketbase/pb_hooks/seed.pb.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
$app.rootCmd.addCommand(
|
||||
new Command({
|
||||
use: "seed",
|
||||
run: (cmd, args) => {
|
||||
$app.importCollections(require(`${__hooks}/seed/schema.json`));
|
||||
|
||||
$app.reloadCachedCollections();
|
||||
$app.reloadSettings();
|
||||
console.log("reload table done");
|
||||
|
||||
console.log("start seeding data");
|
||||
require(`${__hooks}/seed/000_seed_t1.js`)($app);
|
||||
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/010_Vocabularies.js`)($app);
|
||||
|
||||
$app.reloadCachedCollections();
|
||||
$app.reloadSettings();
|
||||
},
|
||||
})
|
||||
);
|
15
002_source/pocketbase/pb_hooks/seed/000_seed_t1.js
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = $app => {
|
||||
const ASSETS_DIR = '/pb_hooks/assets';
|
||||
const getAsset = name => $filesystem.fileFromPath(ASSETS_DIR + '/' + name);
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let t1_collection = $app.findCollectionByNameOrId('t1');
|
||||
|
||||
let record = new Record(t1_collection);
|
||||
record.set('hello', 'world');
|
||||
let test_png = getAsset('1.png');
|
||||
record.set('test_file', test_png);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
};
|
34
002_source/pocketbase/pb_hooks/seed/001_seed_LessonsTypes.js
Normal file
@@ -0,0 +1,34 @@
|
||||
module.exports = $app => {
|
||||
let draft_lesson_types = [
|
||||
['1'.padStart(15, 0), 'Vocabulary', 'vocabulary', 0, 'visible'],
|
||||
['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'],
|
||||
['5'.padStart(15, 0), 'lesson type 5', 'testing', 3, 'hidden'],
|
||||
['6'.padStart(15, 0), '中文 6', 'testing', 3, 'hidden'],
|
||||
['7'.padStart(15, 0), 'レッスン7 レッスン7 レッスン7', 'testing', 3, 'hidden'],
|
||||
];
|
||||
dirtyTruncateTable('LessonsTypes');
|
||||
|
||||
let lt_collection = $app.findCollectionByNameOrId('LessonsTypes');
|
||||
|
||||
for (let i = 0; i < draft_lesson_types.length; i++) {
|
||||
let lesson_type = draft_lesson_types[i];
|
||||
|
||||
let record = new Record(lt_collection);
|
||||
record.set('id', lesson_type[0]);
|
||||
record.set('name', lesson_type[1]);
|
||||
record.set('type', lesson_type[2]);
|
||||
record.set('pos', lesson_type[3]);
|
||||
record.set('visible', lesson_type[4]);
|
||||
|
||||
$app.save(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();
|
||||
};
|
132
002_source/pocketbase/pb_hooks/seed/002_LessonsCategories.js
Normal file
@@ -0,0 +1,132 @@
|
||||
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",
|
||||
],
|
||||
// ["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("LessonsCategories");
|
||||
|
||||
let lt_collection = $app.findCollectionByNameOrId("LessonsCategories");
|
||||
|
||||
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]);
|
||||
|
||||
$app.save(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();
|
||||
};
|
48
002_source/pocketbase/pb_hooks/seed/003_Categories.js
Normal file
@@ -0,0 +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
|
||||
|
||||
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'],
|
||||
// ["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');
|
||||
|
||||
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]);
|
||||
|
||||
$app.save(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();
|
||||
};
|
40
002_source/pocketbase/pb_hooks/seed/010_Vocabularies.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const config = require('/pb_hooks/seed/config.js');
|
||||
const utils = require('/pb_hooks/seed/utils.js');
|
||||
|
||||
module.exports = $app => {
|
||||
const { getAsset } = utils;
|
||||
const { id_v, id_c, cat_id_tech } = config;
|
||||
|
||||
let row_datas = [
|
||||
['1'.padStart(15, 0), getAsset('keyboard.jpg'), getAsset('keyboard.mp3'), 'keyboard', '鍵盤', 'sample_e', 'sample_c', cat_id_tech, '', id_v],
|
||||
['2'.padStart(15, 0), getAsset('mouse.jpg'), getAsset('mouse.mp3'), 'mouse', '滑鼠', 'sample_e mouse', 'sample_c mouse', cat_id_tech, '', id_v],
|
||||
];
|
||||
|
||||
dirtyTruncateTable('Vocabularies');
|
||||
|
||||
for (let i = 0; i < row_datas.length; i++) {
|
||||
let vocabularies_collection = $app.findCollectionByNameOrId('Vocabularies');
|
||||
let data = row_datas[i];
|
||||
|
||||
let record = new Record(vocabularies_collection);
|
||||
record.set('id', data[0]);
|
||||
record.set('image', data[1]);
|
||||
record.set('sound', data[2]);
|
||||
record.set('word', data[3]);
|
||||
record.set('word_c', data[4]);
|
||||
record.set('sample_e', data[5]);
|
||||
record.set('sample_c', data[6]);
|
||||
record.set('cat_id', data[7]);
|
||||
record.set('category', data[8]);
|
||||
record.set('lesson_type_id', data[9]);
|
||||
|
||||
$app.save(record);
|
||||
}
|
||||
console.log('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();
|
||||
};
|
6
002_source/pocketbase/pb_hooks/seed/config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
ASSETS_DIR: '/pb_hooks/assets',
|
||||
id_v: '1'.padStart(15, 0), //id_vocabulary
|
||||
id_c: '2'.padStart(15, 0), //id_connectives
|
||||
cat_id_tech: '3'.padStart(15, 0), // category id of technology
|
||||
};
|
2584
002_source/pocketbase/pb_hooks/seed/schema copy.json
Normal file
2584
002_source/pocketbase/pb_hooks/seed/schema.json
Normal file
12
002_source/pocketbase/pb_hooks/seed/utils.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const config = require('/pb_hooks/seed/config.js');
|
||||
|
||||
module.exports = {
|
||||
getAsset: name => {
|
||||
const file_full_path = config.ASSETS_DIR + '/' + name;
|
||||
try {
|
||||
return $filesystem.fileFromPath(file_full_path);
|
||||
} catch (error) {
|
||||
console.log('file not found: ' + file_full_path, +'please check if file exist');
|
||||
}
|
||||
},
|
||||
};
|