update pocketbase schema,

This commit is contained in:
louiscklaw
2025-04-16 12:43:54 +08:00
parent 08e5677c0b
commit 8bc4a37e8e
23 changed files with 5485 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 963 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

View File

@@ -0,0 +1,6 @@
/// <reference path="../pb_data/types.d.ts" />
onBootstrap((e) => {
e.next();
console.log("App initialized!");
});

View 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();
},
})
);

View 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);
}
};

View 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();
};

View 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();
};

View 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();
};

View 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();
};

View 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
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View 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');
}
},
};