fix: add description column to projects table with migration

- Add description column to projects table in schema.sql
- Add _run_migrations() method to handle schema updates
- Migration automatically adds description column to existing databases
This commit is contained in:
LemonNexus 2026-02-11 10:35:36 +00:00
parent c9c859fbf3
commit e9378f2176
2 changed files with 21 additions and 0 deletions

View File

@ -64,6 +64,9 @@ class DatabaseManager:
conn.executescript(schema) conn.executescript(schema)
conn.commit() conn.commit()
# Run migrations for existing databases
self._run_migrations()
logger.info("Database schema initialized successfully") logger.info("Database schema initialized successfully")
return True return True
@ -71,6 +74,23 @@ class DatabaseManager:
logger.error(f"Failed to initialize database: {e}") logger.error(f"Failed to initialize database: {e}")
return False return False
def _run_migrations(self):
"""Run migrations to update existing databases."""
try:
conn = self.get_connection()
# Migration: Add description column to projects table
try:
conn.execute("ALTER TABLE projects ADD COLUMN description TEXT")
conn.commit()
logger.info("Migration: Added description column to projects table")
except sqlite3.OperationalError:
# Column already exists
pass
except Exception as e:
logger.error(f"Migration failed: {e}")
def get_connection(self) -> sqlite3.Connection: def get_connection(self) -> sqlite3.Connection:
""" """
Get or create database connection. Get or create database connection.

View File

@ -14,6 +14,7 @@ PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS projects ( CREATE TABLE IF NOT EXISTS projects (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL, name TEXT NOT NULL,
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 TIMESTAMP DEFAULT CURRENT_TIMESTAMP,