Upgrade database schema to version 2 and remove unused meta_* columns
- Increment `SCHEMA_VERSION` to 2 in `schema.ts`. - Remove all `meta_*` columns from database tables. - Add migration logic to handle schema upgrades and clean up unused columns. - Modify database models and repository methods to exclude `meta_*` fields for stricter typings and improved structure. - Refactor and optimize query statements across repositories to align with new schema changes.
This commit is contained in:
@@ -11,14 +11,12 @@ export interface CharacterResult extends Record<string, SQLiteValue> {
|
||||
role: string;
|
||||
biography: string;
|
||||
history: string;
|
||||
char_meta: string;
|
||||
}
|
||||
|
||||
export interface AttributeResult extends Record<string, SQLiteValue> {
|
||||
attr_id: string;
|
||||
attribute_name: string;
|
||||
attribute_value: string;
|
||||
attr_meta: string;
|
||||
}
|
||||
|
||||
export interface CompleteCharacterResult extends Record<string, SQLiteValue> {
|
||||
@@ -30,10 +28,8 @@ export interface CompleteCharacterResult extends Record<string, SQLiteValue> {
|
||||
role: string;
|
||||
biography: string;
|
||||
history: string;
|
||||
char_meta: string;
|
||||
attribute_name: string;
|
||||
attribute_value: string;
|
||||
attr_meta: string;
|
||||
}
|
||||
|
||||
export default class CharacterRepo {
|
||||
@@ -41,7 +37,7 @@ export default class CharacterRepo {
|
||||
let result: CharacterResult[];
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
result = db.all('SELECT character_id,`first_name`,`last_name`,`title`,`category`,`image`,`role`,`biography`,`history`,`char_meta` FROM `book_characters` WHERE `book_id`=? AND user_id=?', [bookId, userId]) as CharacterResult[];
|
||||
result = db.all('SELECT character_id, first_name, last_name, title, category, image, role, biography, history FROM book_characters WHERE book_id=? AND user_id=?', [bookId, userId]) as CharacterResult[];
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
@@ -132,7 +128,7 @@ export default class CharacterRepo {
|
||||
let result: AttributeResult[];
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
result = db.all('SELECT attr_id, attribute_name, attribute_value, attr_meta FROM `book_characters_attributes` WHERE `character_id`=? AND `user_id`=?', [characterId, userId]) as AttributeResult[];
|
||||
result = db.all('SELECT attr_id, attribute_name, attribute_value FROM book_characters_attributes WHERE character_id=? AND user_id=?', [characterId, userId]) as AttributeResult[];
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
console.error(`DB Error: ${e.message}`);
|
||||
@@ -149,7 +145,7 @@ export default class CharacterRepo {
|
||||
let result: CompleteCharacterResult[];
|
||||
try {
|
||||
const db: Database = System.getDb();
|
||||
let query: string = 'SELECT charac.`character_id`,`first_name`,`last_name`,`category`,`title`,`role`,`biography`,`history`,`char_meta`,`attribute_name`,`attribute_value`,attr_meta FROM book_characters AS charac LEFT JOIN book_characters_attributes AS attr ON charac.character_id=attr.character_id WHERE charac.user_id=? AND charac.book_id=?';
|
||||
let query: string = 'SELECT charac.character_id, first_name, last_name, category, title, role, biography, history, attribute_name, attribute_value FROM book_characters AS charac LEFT JOIN book_characters_attributes AS attr ON charac.character_id=attr.character_id WHERE charac.user_id=? AND charac.book_id=?';
|
||||
let values: any[] = [userId, bookId];
|
||||
if (tags && tags.length > 0) {
|
||||
const placeholders: string = tags.map((): string => '?').join(',');
|
||||
|
||||
Reference in New Issue
Block a user