Remove CharacterComponent and CharacterDetail components
- Deleted `CharacterComponent` and `CharacterDetail` files from the project. - Refactored related logic to improve code maintainability and reduce redundancy.
This commit is contained in:
@@ -19,7 +19,205 @@ const schemaVersion = 3;
|
||||
* DEV ONLY - S'exécute à chaque refresh, pas besoin de version
|
||||
* Mets ta query, test, efface après
|
||||
*/
|
||||
const devQueries: string[] = [];
|
||||
const devQueries: string[] = [
|
||||
// V3 Migration: Series tables and series_*_id columns
|
||||
|
||||
// Book Series
|
||||
`CREATE TABLE IF NOT EXISTS book_series (
|
||||
series_id TEXT PRIMARY KEY,
|
||||
user_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
hashed_name TEXT NOT NULL,
|
||||
description TEXT,
|
||||
cover_image TEXT,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (user_id) REFERENCES erit_users(user_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_book_series_user ON book_series(user_id)`,
|
||||
|
||||
// Series Books
|
||||
`CREATE TABLE IF NOT EXISTS series_books (
|
||||
series_id TEXT NOT NULL,
|
||||
book_id TEXT NOT NULL,
|
||||
book_order INTEGER NOT NULL DEFAULT 1,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (series_id, book_id),
|
||||
FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (book_id) REFERENCES erit_books(book_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_books_book ON series_books(book_id)`,
|
||||
|
||||
// Series Characters
|
||||
`CREATE TABLE IF NOT EXISTS series_characters (
|
||||
character_id TEXT PRIMARY KEY,
|
||||
series_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT,
|
||||
nickname TEXT,
|
||||
age TEXT,
|
||||
gender TEXT,
|
||||
species TEXT,
|
||||
nationality TEXT,
|
||||
status TEXT,
|
||||
category TEXT NOT NULL,
|
||||
title TEXT,
|
||||
image TEXT,
|
||||
role TEXT,
|
||||
biography TEXT,
|
||||
history TEXT,
|
||||
speech_pattern TEXT,
|
||||
catchphrase TEXT,
|
||||
residence TEXT,
|
||||
notes TEXT,
|
||||
color TEXT,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_characters_series ON series_characters(series_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_characters_user ON series_characters(user_id)`,
|
||||
|
||||
// Series Characters Attributes
|
||||
`CREATE TABLE IF NOT EXISTS series_characters_attributes (
|
||||
attr_id TEXT PRIMARY KEY,
|
||||
character_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
attribute_name TEXT NOT NULL,
|
||||
attribute_value TEXT NOT NULL,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (character_id) REFERENCES series_characters(character_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_char_attrs_character ON series_characters_attributes(character_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_char_attrs_user ON series_characters_attributes(user_id)`,
|
||||
|
||||
// Series Worlds
|
||||
`CREATE TABLE IF NOT EXISTS series_worlds (
|
||||
world_id TEXT PRIMARY KEY,
|
||||
series_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
hashed_name TEXT NOT NULL,
|
||||
history TEXT,
|
||||
politics TEXT,
|
||||
economy TEXT,
|
||||
religion TEXT,
|
||||
languages TEXT,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_worlds_series ON series_worlds(series_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_worlds_user ON series_worlds(user_id)`,
|
||||
|
||||
// Series World Elements
|
||||
`CREATE TABLE IF NOT EXISTS series_world_elements (
|
||||
element_id TEXT PRIMARY KEY,
|
||||
world_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
element_type INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
original_name TEXT NOT NULL,
|
||||
description TEXT,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (world_id) REFERENCES series_worlds(world_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_world_elements_world ON series_world_elements(world_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_world_elements_user ON series_world_elements(user_id)`,
|
||||
|
||||
// Series Locations
|
||||
`CREATE TABLE IF NOT EXISTS series_locations (
|
||||
loc_id TEXT PRIMARY KEY,
|
||||
series_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
loc_name TEXT NOT NULL,
|
||||
loc_original_name TEXT NOT NULL,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_locations_series ON series_locations(series_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_locations_user ON series_locations(user_id)`,
|
||||
|
||||
// Series Location Elements
|
||||
`CREATE TABLE IF NOT EXISTS series_location_elements (
|
||||
element_id TEXT PRIMARY KEY,
|
||||
location_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
element_name TEXT NOT NULL,
|
||||
original_name TEXT NOT NULL,
|
||||
element_description TEXT,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (location_id) REFERENCES series_locations(loc_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_loc_elements_location ON series_location_elements(location_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_loc_elements_user ON series_location_elements(user_id)`,
|
||||
|
||||
// Series Location Sub Elements
|
||||
`CREATE TABLE IF NOT EXISTS series_location_sub_elements (
|
||||
sub_element_id TEXT PRIMARY KEY,
|
||||
element_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
sub_elem_name TEXT NOT NULL,
|
||||
original_name TEXT NOT NULL,
|
||||
sub_elem_description TEXT,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (element_id) REFERENCES series_location_elements(element_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_loc_sub_elements_element ON series_location_sub_elements(element_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_loc_sub_elements_user ON series_location_sub_elements(user_id)`,
|
||||
|
||||
// Series Spells
|
||||
`CREATE TABLE IF NOT EXISTS series_spells (
|
||||
spell_id TEXT PRIMARY KEY,
|
||||
series_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
name_hash TEXT NOT NULL,
|
||||
description TEXT,
|
||||
appearance TEXT,
|
||||
tags TEXT,
|
||||
power_level TEXT,
|
||||
components TEXT,
|
||||
limitations TEXT,
|
||||
notes TEXT,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_spells_series ON series_spells(series_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_spells_user ON series_spells(user_id)`,
|
||||
|
||||
// Series Spell Tags
|
||||
`CREATE TABLE IF NOT EXISTS series_spell_tags (
|
||||
tag_id TEXT PRIMARY KEY,
|
||||
series_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
hashed_name TEXT NOT NULL,
|
||||
color TEXT,
|
||||
last_update INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_spell_tags_series ON series_spell_tags(series_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_series_spell_tags_user ON series_spell_tags(user_id)`,
|
||||
|
||||
// Add series_*_id columns to existing book tables (will fail silently if already exists)
|
||||
`ALTER TABLE book_characters ADD COLUMN series_character_id TEXT DEFAULT NULL`,
|
||||
`ALTER TABLE book_world ADD COLUMN series_world_id TEXT DEFAULT NULL`,
|
||||
`ALTER TABLE book_location ADD COLUMN series_location_id TEXT DEFAULT NULL`,
|
||||
`ALTER TABLE book_spells ADD COLUMN series_spell_id TEXT DEFAULT NULL`,
|
||||
|
||||
// Removed Items (sync deletion tracking)
|
||||
`CREATE TABLE IF NOT EXISTS removed_items (
|
||||
removal_id TEXT PRIMARY KEY,
|
||||
table_name TEXT NOT NULL,
|
||||
entity_id TEXT NOT NULL,
|
||||
book_id TEXT,
|
||||
user_id TEXT NOT NULL,
|
||||
deleted_at INTEGER NOT NULL
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_removed_items_user ON removed_items(user_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_removed_items_book ON removed_items(book_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_removed_items_deleted_at ON removed_items(deleted_at)`,
|
||||
`CREATE UNIQUE INDEX IF NOT EXISTS idx_removed_items_entity ON removed_items(table_name, entity_id)`,
|
||||
];
|
||||
|
||||
const isDev:boolean = !app.isPackaged;
|
||||
|
||||
@@ -123,9 +321,9 @@ function migrateFromOldSystem(db: Database): void {
|
||||
user_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
name_hash TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
appearance TEXT NOT NULL,
|
||||
tags TEXT NOT NULL,
|
||||
description TEXT,
|
||||
appearance TEXT,
|
||||
tags TEXT,
|
||||
power_level TEXT,
|
||||
components TEXT,
|
||||
limitations TEXT,
|
||||
@@ -172,7 +370,7 @@ function migrateFromOldSystem(db: Database): void {
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_loc_sub_elements_element ON series_location_sub_elements(element_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_loc_sub_elements_user ON series_location_sub_elements(user_id)`);
|
||||
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS series_spells (spell_id TEXT PRIMARY KEY, series_id TEXT NOT NULL, user_id TEXT NOT NULL, name TEXT NOT NULL, name_hash TEXT NOT NULL, description TEXT NOT NULL, appearance TEXT NOT NULL, tags TEXT, power_level TEXT, components TEXT, limitations TEXT, notes TEXT, last_update INTEGER DEFAULT 0, FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE);`);
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS series_spells (spell_id TEXT PRIMARY KEY, series_id TEXT NOT NULL, user_id TEXT NOT NULL, name TEXT NOT NULL, name_hash TEXT NOT NULL, description TEXT, appearance TEXT, tags TEXT, power_level TEXT, components TEXT, limitations TEXT, notes TEXT, last_update INTEGER DEFAULT 0, FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE);`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_spells_series ON series_spells(series_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_spells_user ON series_spells(user_id)`);
|
||||
|
||||
@@ -186,6 +384,23 @@ function migrateFromOldSystem(db: Database): void {
|
||||
addColumn(db, 'book_location', 'series_location_id', 'TEXT DEFAULT NULL');
|
||||
addColumn(db, 'book_spells', 'series_spell_id', 'TEXT DEFAULT NULL');
|
||||
|
||||
// Removed Items (sync deletion tracking)
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS removed_items (
|
||||
removal_id TEXT PRIMARY KEY,
|
||||
table_name TEXT NOT NULL,
|
||||
entity_id TEXT NOT NULL,
|
||||
book_id TEXT,
|
||||
user_id TEXT NOT NULL,
|
||||
deleted_at INTEGER NOT NULL,
|
||||
removed_time INTEGER NOT NULL DEFAULT 0
|
||||
)
|
||||
`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_user ON removed_items(user_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_book ON removed_items(book_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_deleted_at ON removed_items(deleted_at)`);
|
||||
db.exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_removed_items_entity ON removed_items(table_name, entity_id)`);
|
||||
|
||||
// Drop old schema version table
|
||||
db.exec('DROP TABLE IF EXISTS _schema_version');
|
||||
}
|
||||
@@ -255,9 +470,9 @@ export function runMigrations(db: Database): void {
|
||||
user_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
name_hash TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
appearance TEXT NOT NULL,
|
||||
tags TEXT NOT NULL,
|
||||
description TEXT,
|
||||
appearance TEXT,
|
||||
tags TEXT,
|
||||
power_level TEXT,
|
||||
components TEXT,
|
||||
limitations TEXT,
|
||||
@@ -333,7 +548,7 @@ export function runMigrations(db: Database): void {
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_loc_sub_elements_user ON series_location_sub_elements(user_id)`);
|
||||
|
||||
// Series Spells
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS series_spells (spell_id TEXT PRIMARY KEY, series_id TEXT NOT NULL, user_id TEXT NOT NULL, name TEXT NOT NULL, name_hash TEXT NOT NULL, description TEXT NOT NULL, appearance TEXT NOT NULL, tags TEXT, power_level TEXT, components TEXT, limitations TEXT, notes TEXT, last_update INTEGER DEFAULT 0, FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE);`);
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS series_spells (spell_id TEXT PRIMARY KEY, series_id TEXT NOT NULL, user_id TEXT NOT NULL, name TEXT NOT NULL, name_hash TEXT NOT NULL, description TEXT, appearance TEXT, tags TEXT, power_level TEXT, components TEXT, limitations TEXT, notes TEXT, last_update INTEGER DEFAULT 0, FOREIGN KEY (series_id) REFERENCES book_series(series_id) ON DELETE CASCADE);`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_spells_series ON series_spells(series_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_spells_user ON series_spells(user_id)`);
|
||||
|
||||
@@ -347,6 +562,23 @@ export function runMigrations(db: Database): void {
|
||||
addColumn(db, 'book_world', 'series_world_id', 'TEXT DEFAULT NULL');
|
||||
addColumn(db, 'book_location', 'series_location_id', 'TEXT DEFAULT NULL');
|
||||
addColumn(db, 'book_spells', 'series_spell_id', 'TEXT DEFAULT NULL');
|
||||
|
||||
// Removed Items (sync deletion tracking)
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS removed_items (
|
||||
removal_id TEXT PRIMARY KEY,
|
||||
table_name TEXT NOT NULL,
|
||||
entity_id TEXT NOT NULL,
|
||||
book_id TEXT,
|
||||
user_id TEXT NOT NULL,
|
||||
deleted_at INTEGER NOT NULL,
|
||||
removed_time INTEGER NOT NULL DEFAULT 0
|
||||
)
|
||||
`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_user ON removed_items(user_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_book ON removed_items(book_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_deleted_at ON removed_items(deleted_at)`);
|
||||
db.exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_removed_items_entity ON removed_items(table_name, entity_id)`);
|
||||
}
|
||||
|
||||
setDbVersion(db, schemaVersion);
|
||||
@@ -808,9 +1040,9 @@ export function initializeSchema(db: Database): void {
|
||||
user_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
name_hash TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
appearance TEXT NOT NULL,
|
||||
tags TEXT NOT NULL,
|
||||
description TEXT,
|
||||
appearance TEXT,
|
||||
tags TEXT,
|
||||
power_level TEXT,
|
||||
components TEXT,
|
||||
limitations TEXT,
|
||||
@@ -978,8 +1210,8 @@ export function initializeSchema(db: Database): void {
|
||||
user_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
name_hash TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
appearance TEXT NOT NULL,
|
||||
description TEXT,
|
||||
appearance TEXT,
|
||||
tags TEXT,
|
||||
power_level TEXT,
|
||||
components TEXT,
|
||||
@@ -1004,6 +1236,19 @@ export function initializeSchema(db: Database): void {
|
||||
);
|
||||
`);
|
||||
|
||||
// Removed Items (sync deletion tracking)
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS removed_items (
|
||||
removal_id TEXT PRIMARY KEY,
|
||||
table_name TEXT NOT NULL,
|
||||
entity_id TEXT NOT NULL,
|
||||
book_id TEXT,
|
||||
user_id TEXT NOT NULL,
|
||||
deleted_at INTEGER NOT NULL,
|
||||
removed_time INTEGER NOT NULL DEFAULT 0
|
||||
)
|
||||
`);
|
||||
|
||||
// Create indexes for better performance
|
||||
createIndexes(db);
|
||||
}
|
||||
@@ -1049,6 +1294,11 @@ function createIndexes(db: Database): void {
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_spells_user ON series_spells(user_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_spell_tags_series ON series_spell_tags(series_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_series_spell_tags_user ON series_spell_tags(user_id)`);
|
||||
// Removed items indexes
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_user ON removed_items(user_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_book ON removed_items(book_id)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_removed_items_deleted_at ON removed_items(deleted_at)`);
|
||||
db.exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_removed_items_entity ON removed_items(table_name, entity_id)`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user