From b06b98e6ccf4b5910b5b895d588b41456140332d Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Wed, 11 Feb 2026 13:13:55 +0000 Subject: [PATCH] fix: change TIMESTAMP columns to TEXT to avoid SQLite auto-conversion errors SQLite's TIMESTAMP type causes auto-conversion issues when data is in ISO format - Changed all TIMESTAMP columns to TEXT in schema.sql - Disabled detect_types in database.py to prevent auto-conversion - This stores datetime as ISO strings without parsing issues --- core/database.py | 2 +- core/schema.sql | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/database.py b/core/database.py index 9a4e8a5..3365d6d 100644 --- a/core/database.py +++ b/core/database.py @@ -110,7 +110,7 @@ class DatabaseManager: if self._connection is None: self._connection = sqlite3.connect( self.db_path, - detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES + detect_types=0 # Disable auto type detection to avoid TIMESTAMP parsing issues ) self._connection.row_factory = sqlite3.Row diff --git a/core/schema.sql b/core/schema.sql index 557a63d..dd59bf3 100644 --- a/core/schema.sql +++ b/core/schema.sql @@ -17,9 +17,9 @@ CREATE TABLE IF NOT EXISTS projects ( description TEXT, type TEXT NOT NULL CHECK (type IN ('hunt', 'mine', 'craft', 'inventory')), status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'paused', 'completed', 'archived')), - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - archived_at TIMESTAMP, + created_at TEXT, -- ISO format datetime (TEXT to avoid auto-conversion issues) + updated_at TEXT, + archived_at TEXT, metadata TEXT -- JSON blob for extensible project data ); @@ -34,8 +34,8 @@ CREATE INDEX IF NOT EXISTS idx_projects_created ON projects(created_at); CREATE TABLE IF NOT EXISTS sessions ( id INTEGER PRIMARY KEY AUTOINCREMENT, project_id INTEGER NOT NULL, - started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - ended_at TIMESTAMP, + started_at TEXT, -- ISO format datetime + ended_at TEXT, status TEXT DEFAULT 'running' CHECK (status IN ('running', 'paused', 'completed', 'stopped')), duration_seconds INTEGER DEFAULT 0, total_spent_ped REAL DEFAULT 0.0, -- Decimal stored as REAL, handled in code @@ -56,8 +56,8 @@ CREATE TABLE IF NOT EXISTS loadouts ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, description TEXT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + created_at TEXT, -- ISO format datetime + updated_at TEXT, -- Weapon weapon_name TEXT, @@ -121,8 +121,8 @@ CREATE TABLE IF NOT EXISTS hunting_sessions ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id INTEGER NOT NULL UNIQUE, loadout_id INTEGER, -- Links to loadouts table - started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - ended_at TIMESTAMP, + started_at TEXT, -- ISO format datetime + ended_at TEXT, -- Loot breakdown total_loot_ped REAL DEFAULT 0.0, @@ -175,7 +175,7 @@ CREATE INDEX IF NOT EXISTS idx_hunting_sessions_weapon ON hunting_sessions(weapo CREATE TABLE IF NOT EXISTS hunting_globals ( id INTEGER PRIMARY KEY AUTOINCREMENT, hunting_session_id INTEGER NOT NULL, - timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + timestamp TEXT, -- ISO format datetime creature_name TEXT, value_ped REAL NOT NULL, is_hof BOOLEAN DEFAULT 0, @@ -193,7 +193,7 @@ CREATE INDEX IF NOT EXISTS idx_hunting_globals_value ON hunting_globals(value_pe CREATE TABLE IF NOT EXISTS loot_events ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id INTEGER NOT NULL, - timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + timestamp TEXT, -- ISO format datetime event_type TEXT NOT NULL CHECK (event_type IN ('global', 'hof', 'regular', 'skill')), -- Loot data @@ -228,7 +228,7 @@ CREATE INDEX IF NOT EXISTS idx_loot_value ON loot_events(value_ped); CREATE TABLE IF NOT EXISTS combat_events ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id INTEGER NOT NULL, - timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + timestamp TEXT, -- ISO format datetime event_type TEXT NOT NULL CHECK (event_type IN ('damage_dealt', 'damage_taken', 'heal', 'evade', 'kill', 'critical_hit')), damage_amount REAL, @@ -251,7 +251,7 @@ CREATE INDEX IF NOT EXISTS idx_combat_type ON combat_events(event_type); CREATE TABLE IF NOT EXISTS skill_gains ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id INTEGER NOT NULL, - timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + timestamp TEXT, -- ISO format datetime skill_name TEXT NOT NULL, gained_amount REAL DEFAULT 0.0, new_total REAL, @@ -269,7 +269,7 @@ CREATE INDEX IF NOT EXISTS idx_skill_name ON skill_gains(skill_name); CREATE TABLE IF NOT EXISTS decay_events ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id INTEGER NOT NULL, - timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + timestamp TEXT, -- ISO format datetime item_name TEXT NOT NULL, decay_amount_ped REAL DEFAULT 0.0, decay_amount_pec REAL DEFAULT 0.0, @@ -287,7 +287,7 @@ CREATE INDEX IF NOT EXISTS idx_decay_session ON decay_events(session_id); CREATE TABLE IF NOT EXISTS screenshots ( id INTEGER PRIMARY KEY AUTOINCREMENT, session_id INTEGER NOT NULL, - timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + timestamp TEXT, -- ISO format datetime file_path TEXT NOT NULL, trigger_event TEXT, -- What triggered the screenshot trigger_value_ped REAL, @@ -303,7 +303,7 @@ CREATE INDEX IF NOT EXISTS idx_screenshots_session ON screenshots(session_id); CREATE TABLE IF NOT EXISTS app_state ( key TEXT PRIMARY KEY, value TEXT, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + updated_at TEXT -- ISO format datetime ); -- ============================================================================ @@ -312,7 +312,7 @@ CREATE TABLE IF NOT EXISTS app_state ( CREATE TABLE IF NOT EXISTS schema_version ( version INTEGER PRIMARY KEY, - applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + applied_at TEXT, -- ISO format datetime description TEXT );