generated from Grigo/AndroidTemplate
Initial commit: LoraTester Android + server
This commit is contained in:
+41
-1
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
|
||||
SCHEMA_VERSION = 3
|
||||
SCHEMA_VERSION = 4
|
||||
|
||||
|
||||
def table_exists(conn: sqlite3.Connection, name: str) -> bool:
|
||||
@@ -121,6 +121,44 @@ def apply_migrations(conn: sqlite3.Connection) -> list[str]:
|
||||
)
|
||||
log.append("CREATE track_points")
|
||||
|
||||
if not table_exists(conn, "device_commands"):
|
||||
conn.executescript(
|
||||
"""
|
||||
CREATE TABLE device_commands (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
from_device_id TEXT NOT NULL,
|
||||
to_device_id TEXT NOT NULL,
|
||||
kind TEXT NOT NULL,
|
||||
payload TEXT,
|
||||
created_at REAL NOT NULL,
|
||||
delivered_at REAL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_commands_to_pending
|
||||
ON device_commands(to_device_id, delivered_at, created_at);
|
||||
"""
|
||||
)
|
||||
log.append("CREATE device_commands")
|
||||
|
||||
if not table_exists(conn, "paired_track_sessions"):
|
||||
conn.executescript(
|
||||
"""
|
||||
CREATE TABLE paired_track_sessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
device_a TEXT NOT NULL,
|
||||
device_b TEXT NOT NULL,
|
||||
initiator TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
start_at REAL NOT NULL,
|
||||
track_id_a INTEGER,
|
||||
track_id_b INTEGER,
|
||||
created_at REAL NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_paired_status
|
||||
ON paired_track_sessions(status, created_at DESC);
|
||||
"""
|
||||
)
|
||||
log.append("CREATE paired_track_sessions")
|
||||
|
||||
set_schema_version(conn, SCHEMA_VERSION)
|
||||
log.append(f"schema_version={SCHEMA_VERSION}")
|
||||
return log
|
||||
@@ -132,6 +170,8 @@ def check_db_ok(conn: sqlite3.Connection) -> bool:
|
||||
("telemetry", "meta"),
|
||||
("tracks", None),
|
||||
("track_points", "elevation_m"),
|
||||
("device_commands", None),
|
||||
("paired_track_sessions", None),
|
||||
]
|
||||
for table, col in required:
|
||||
if not table_exists(conn, table):
|
||||
|
||||
Reference in New Issue
Block a user