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:
parent
c9c859fbf3
commit
e9378f2176
|
|
@ -64,6 +64,9 @@ class DatabaseManager:
|
|||
conn.executescript(schema)
|
||||
conn.commit()
|
||||
|
||||
# Run migrations for existing databases
|
||||
self._run_migrations()
|
||||
|
||||
logger.info("Database schema initialized successfully")
|
||||
return True
|
||||
|
||||
|
|
@ -71,6 +74,23 @@ class DatabaseManager:
|
|||
logger.error(f"Failed to initialize database: {e}")
|
||||
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:
|
||||
"""
|
||||
Get or create database connection.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ PRAGMA foreign_keys = ON;
|
|||
CREATE TABLE IF NOT EXISTS projects (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue