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
This commit is contained in:
parent
381c0e2b50
commit
b06b98e6cc
|
|
@ -110,7 +110,7 @@ class DatabaseManager:
|
||||||
if self._connection is None:
|
if self._connection is None:
|
||||||
self._connection = sqlite3.connect(
|
self._connection = sqlite3.connect(
|
||||||
self.db_path,
|
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
|
self._connection.row_factory = sqlite3.Row
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ CREATE TABLE IF NOT EXISTS projects (
|
||||||
description TEXT,
|
description TEXT,
|
||||||
type TEXT NOT NULL CHECK (type IN ('hunt', 'mine', 'craft', 'inventory')),
|
type TEXT NOT NULL CHECK (type IN ('hunt', 'mine', 'craft', 'inventory')),
|
||||||
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'paused', 'completed', 'archived')),
|
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'paused', 'completed', 'archived')),
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TEXT, -- ISO format datetime (TEXT to avoid auto-conversion issues)
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TEXT,
|
||||||
archived_at TIMESTAMP,
|
archived_at TEXT,
|
||||||
metadata TEXT -- JSON blob for extensible project data
|
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 (
|
CREATE TABLE IF NOT EXISTS sessions (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
project_id INTEGER NOT NULL,
|
project_id INTEGER NOT NULL,
|
||||||
started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
started_at TEXT, -- ISO format datetime
|
||||||
ended_at TIMESTAMP,
|
ended_at TEXT,
|
||||||
status TEXT DEFAULT 'running' CHECK (status IN ('running', 'paused', 'completed', 'stopped')),
|
status TEXT DEFAULT 'running' CHECK (status IN ('running', 'paused', 'completed', 'stopped')),
|
||||||
duration_seconds INTEGER DEFAULT 0,
|
duration_seconds INTEGER DEFAULT 0,
|
||||||
total_spent_ped REAL DEFAULT 0.0, -- Decimal stored as REAL, handled in code
|
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,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
name TEXT NOT NULL UNIQUE,
|
name TEXT NOT NULL UNIQUE,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TEXT, -- ISO format datetime
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
updated_at TEXT,
|
||||||
|
|
||||||
-- Weapon
|
-- Weapon
|
||||||
weapon_name TEXT,
|
weapon_name TEXT,
|
||||||
|
|
@ -121,8 +121,8 @@ CREATE TABLE IF NOT EXISTS hunting_sessions (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
session_id INTEGER NOT NULL UNIQUE,
|
session_id INTEGER NOT NULL UNIQUE,
|
||||||
loadout_id INTEGER, -- Links to loadouts table
|
loadout_id INTEGER, -- Links to loadouts table
|
||||||
started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
started_at TEXT, -- ISO format datetime
|
||||||
ended_at TIMESTAMP,
|
ended_at TEXT,
|
||||||
|
|
||||||
-- Loot breakdown
|
-- Loot breakdown
|
||||||
total_loot_ped REAL DEFAULT 0.0,
|
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 (
|
CREATE TABLE IF NOT EXISTS hunting_globals (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
hunting_session_id INTEGER NOT NULL,
|
hunting_session_id INTEGER NOT NULL,
|
||||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
timestamp TEXT, -- ISO format datetime
|
||||||
creature_name TEXT,
|
creature_name TEXT,
|
||||||
value_ped REAL NOT NULL,
|
value_ped REAL NOT NULL,
|
||||||
is_hof BOOLEAN DEFAULT 0,
|
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 (
|
CREATE TABLE IF NOT EXISTS loot_events (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
session_id INTEGER NOT NULL,
|
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')),
|
event_type TEXT NOT NULL CHECK (event_type IN ('global', 'hof', 'regular', 'skill')),
|
||||||
|
|
||||||
-- Loot data
|
-- 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 (
|
CREATE TABLE IF NOT EXISTS combat_events (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
session_id INTEGER NOT NULL,
|
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')),
|
event_type TEXT NOT NULL CHECK (event_type IN ('damage_dealt', 'damage_taken', 'heal', 'evade', 'kill', 'critical_hit')),
|
||||||
|
|
||||||
damage_amount REAL,
|
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 (
|
CREATE TABLE IF NOT EXISTS skill_gains (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
session_id INTEGER NOT NULL,
|
session_id INTEGER NOT NULL,
|
||||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
timestamp TEXT, -- ISO format datetime
|
||||||
skill_name TEXT NOT NULL,
|
skill_name TEXT NOT NULL,
|
||||||
gained_amount REAL DEFAULT 0.0,
|
gained_amount REAL DEFAULT 0.0,
|
||||||
new_total REAL,
|
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 (
|
CREATE TABLE IF NOT EXISTS decay_events (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
session_id INTEGER NOT NULL,
|
session_id INTEGER NOT NULL,
|
||||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
timestamp TEXT, -- ISO format datetime
|
||||||
item_name TEXT NOT NULL,
|
item_name TEXT NOT NULL,
|
||||||
decay_amount_ped REAL DEFAULT 0.0,
|
decay_amount_ped REAL DEFAULT 0.0,
|
||||||
decay_amount_pec 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 (
|
CREATE TABLE IF NOT EXISTS screenshots (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
session_id INTEGER NOT NULL,
|
session_id INTEGER NOT NULL,
|
||||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
timestamp TEXT, -- ISO format datetime
|
||||||
file_path TEXT NOT NULL,
|
file_path TEXT NOT NULL,
|
||||||
trigger_event TEXT, -- What triggered the screenshot
|
trigger_event TEXT, -- What triggered the screenshot
|
||||||
trigger_value_ped REAL,
|
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 (
|
CREATE TABLE IF NOT EXISTS app_state (
|
||||||
key TEXT PRIMARY KEY,
|
key TEXT PRIMARY KEY,
|
||||||
value TEXT,
|
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 (
|
CREATE TABLE IF NOT EXISTS schema_version (
|
||||||
version INTEGER PRIMARY KEY,
|
version INTEGER PRIMARY KEY,
|
||||||
applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
applied_at TEXT, -- ISO format datetime
|
||||||
description TEXT
|
description TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue