refactor: add name and color columns to mining_areas table and handle migration
This commit is contained in:
@@ -85,12 +85,28 @@ export function initializeDatabase() {
|
|||||||
max_x INTEGER NOT NULL,
|
max_x INTEGER NOT NULL,
|
||||||
max_y INTEGER NOT NULL,
|
max_y INTEGER NOT NULL,
|
||||||
max_z INTEGER NOT NULL,
|
max_z INTEGER NOT NULL,
|
||||||
|
name TEXT,
|
||||||
|
color TEXT DEFAULT '#4a8c2a',
|
||||||
status TEXT DEFAULT 'active',
|
status TEXT DEFAULT 'active',
|
||||||
created_at INTEGER NOT NULL,
|
created_at INTEGER NOT NULL,
|
||||||
updated_at INTEGER NOT NULL
|
updated_at INTEGER NOT NULL
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
// Migrate existing mining_areas table to add name/color columns if missing
|
||||||
|
try {
|
||||||
|
const tableInfo = db.prepare("PRAGMA table_info(mining_areas)").all();
|
||||||
|
const columns = tableInfo.map(c => c.name);
|
||||||
|
if (!columns.includes('name')) {
|
||||||
|
db.exec('ALTER TABLE mining_areas ADD COLUMN name TEXT');
|
||||||
|
}
|
||||||
|
if (!columns.includes('color')) {
|
||||||
|
db.exec("ALTER TABLE mining_areas ADD COLUMN color TEXT DEFAULT '#4a8c2a'");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore migration errors
|
||||||
|
}
|
||||||
|
|
||||||
// Mining statistics table
|
// Mining statistics table
|
||||||
db.exec(`
|
db.exec(`
|
||||||
CREATE TABLE IF NOT EXISTS mining_stats (
|
CREATE TABLE IF NOT EXISTS mining_stats (
|
||||||
|
|||||||
Reference in New Issue
Block a user