enchance data

This commit is contained in:
2026-04-20 12:24:51 +03:00
parent 5d564de336
commit bb7d7392a8
5 changed files with 129 additions and 30 deletions

18
db.py
View File

@@ -35,11 +35,29 @@ def init_db():
town_id TEXT PRIMARY KEY,
town_name TEXT,
player TEXT,
player_id TEXT,
alliance_id TEXT,
world_id TEXT,
x REAL,
y REAL,
sea INTEGER,
data TEXT NOT NULL, -- full JSON snapshot
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
)
''')
# Migration: add new columns if upgrading an existing database
for _col in [
'ALTER TABLE town_state ADD COLUMN player_id TEXT',
'ALTER TABLE town_state ADD COLUMN alliance_id TEXT',
'ALTER TABLE town_state ADD COLUMN x REAL',
'ALTER TABLE town_state ADD COLUMN y REAL',
'ALTER TABLE town_state ADD COLUMN sea INTEGER',
]:
try:
c.execute(_col)
except Exception:
pass # column already exists
conn.commit()
conn.close()