1818
1919logger = logging .getLogger (__name__ )
2020
21- SCHEMA_VERSION = 1
21+ SCHEMA_VERSION = 2
2222
23- _SCHEMA_V1 = """\
23+ _FRESH_SCHEMA = """\
2424 CREATE TABLE IF NOT EXISTS manifest (
2525 asset_id TEXT NOT NULL,
2626 zone_id TEXT NOT NULL DEFAULT '',
4747 gps_latitude REAL,
4848 gps_longitude REAL,
4949 gps_altitude REAL,
50+ gps_speed REAL,
51+ gps_timestamp TEXT,
52+ timezone_offset INTEGER,
53+ asset_subtype INTEGER,
54+ hdr_type INTEGER,
55+ burst_flags INTEGER,
56+ burst_flags_ext INTEGER,
57+ burst_id TEXT,
58+ original_orientation INTEGER,
59+ raw_fields TEXT,
5060 PRIMARY KEY (asset_id, zone_id, local_path)
5161);
5262CREATE INDEX IF NOT EXISTS idx_manifest_path ON manifest(local_path);
5565# Columns added between schema versions, for migration from older DBs.
5666# Each entry: (version_introduced, ALTER TABLE statement)
5767_MIGRATIONS : list [tuple [int , str ]] = [
58- # Future migrations go here, e.g.:
59- # (2, "ALTER TABLE manifest ADD COLUMN new_field TEXT DEFAULT NULL"),
68+ (2 , "ALTER TABLE manifest ADD COLUMN gps_speed REAL" ),
69+ (2 , "ALTER TABLE manifest ADD COLUMN gps_timestamp TEXT" ),
70+ (2 , "ALTER TABLE manifest ADD COLUMN timezone_offset INTEGER" ),
71+ (2 , "ALTER TABLE manifest ADD COLUMN asset_subtype INTEGER" ),
72+ (2 , "ALTER TABLE manifest ADD COLUMN hdr_type INTEGER" ),
73+ (2 , "ALTER TABLE manifest ADD COLUMN burst_flags INTEGER" ),
74+ (2 , "ALTER TABLE manifest ADD COLUMN burst_flags_ext INTEGER" ),
75+ (2 , "ALTER TABLE manifest ADD COLUMN burst_id TEXT" ),
76+ (2 , "ALTER TABLE manifest ADD COLUMN original_orientation INTEGER" ),
77+ (2 , "ALTER TABLE manifest ADD COLUMN raw_fields TEXT" ),
6078]
6179
6280
@@ -89,14 +107,26 @@ class ManifestRow:
89107 gps_latitude : float | None
90108 gps_longitude : float | None
91109 gps_altitude : float | None
110+ gps_speed : float | None
111+ gps_timestamp : str | None
112+ timezone_offset : int | None
113+ asset_subtype : int | None
114+ hdr_type : int | None
115+ burst_flags : int | None
116+ burst_flags_ext : int | None
117+ burst_id : str | None
118+ original_orientation : int | None
119+ raw_fields : str | None
92120
93121
94122_ALL_COLUMNS = (
95123 "asset_id, zone_id, local_path, version_size, version_checksum, "
96124 "change_tag, downloaded_at, last_updated_at, item_type, filename, "
97125 "asset_date, added_date, is_favorite, is_hidden, is_deleted, "
98126 "original_width, original_height, duration, orientation, "
99- "title, description, keywords, gps_latitude, gps_longitude, gps_altitude"
127+ "title, description, keywords, gps_latitude, gps_longitude, gps_altitude, "
128+ "gps_speed, gps_timestamp, timezone_offset, asset_subtype, hdr_type, "
129+ "burst_flags, burst_flags_ext, burst_id, original_orientation, raw_fields"
100130)
101131
102132
@@ -133,7 +163,7 @@ def open(self) -> None:
133163 ).fetchone ()
134164 if tables is None :
135165 # Brand new DB
136- self ._conn .executescript (_SCHEMA_V1 )
166+ self ._conn .executescript (_FRESH_SCHEMA )
137167 else :
138168 # Pre-versioned DB (has table but no user_version) — migrate
139169 self ._migrate_from_v0 ()
@@ -167,6 +197,16 @@ def _migrate_from_v0(self) -> None:
167197 ("gps_latitude" , "REAL" ),
168198 ("gps_longitude" , "REAL" ),
169199 ("gps_altitude" , "REAL" ),
200+ ("gps_speed" , "REAL" ),
201+ ("gps_timestamp" , "TEXT" ),
202+ ("timezone_offset" , "INTEGER" ),
203+ ("asset_subtype" , "INTEGER" ),
204+ ("hdr_type" , "INTEGER" ),
205+ ("burst_flags" , "INTEGER" ),
206+ ("burst_flags_ext" , "INTEGER" ),
207+ ("burst_id" , "TEXT" ),
208+ ("original_orientation" , "INTEGER" ),
209+ ("raw_fields" , "TEXT" ),
170210 ]
171211 for col_name , col_def in new_columns :
172212 if col_name not in existing :
@@ -256,13 +296,23 @@ def upsert(
256296 gps_latitude : float | None = None ,
257297 gps_longitude : float | None = None ,
258298 gps_altitude : float | None = None ,
299+ gps_speed : float | None = None ,
300+ gps_timestamp : str | None = None ,
301+ timezone_offset : int | None = None ,
302+ asset_subtype : int | None = None ,
303+ hdr_type : int | None = None ,
304+ burst_flags : int | None = None ,
305+ burst_flags_ext : int | None = None ,
306+ burst_id : str | None = None ,
307+ original_orientation : int | None = None ,
308+ raw_fields : str | None = None ,
259309 ) -> None :
260310 """Insert or update a manifest entry. Auto-flushes every 500 writes."""
261311 try :
262312 now = datetime .now (tz = timezone .utc ).isoformat ()
263313 self ._db .execute (
264314 f"INSERT INTO manifest ({ _ALL_COLUMNS } ) "
265- "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "
315+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ) "
266316 "ON CONFLICT(asset_id, zone_id, local_path) DO UPDATE SET "
267317 "version_size=excluded.version_size, "
268318 "version_checksum=excluded.version_checksum, "
@@ -284,13 +334,25 @@ def upsert(
284334 "keywords=excluded.keywords, "
285335 "gps_latitude=excluded.gps_latitude, "
286336 "gps_longitude=excluded.gps_longitude, "
287- "gps_altitude=excluded.gps_altitude" ,
337+ "gps_altitude=excluded.gps_altitude, "
338+ "gps_speed=excluded.gps_speed, "
339+ "gps_timestamp=excluded.gps_timestamp, "
340+ "timezone_offset=excluded.timezone_offset, "
341+ "asset_subtype=excluded.asset_subtype, "
342+ "hdr_type=excluded.hdr_type, "
343+ "burst_flags=excluded.burst_flags, "
344+ "burst_flags_ext=excluded.burst_flags_ext, "
345+ "burst_id=excluded.burst_id, "
346+ "original_orientation=excluded.original_orientation, "
347+ "raw_fields=excluded.raw_fields" ,
288348 (
289349 asset_id , zone_id , local_path , version_size , version_checksum ,
290350 change_tag , now , now , item_type , filename ,
291351 asset_date , added_date , is_favorite , is_hidden , is_deleted ,
292352 original_width , original_height , duration , orientation ,
293353 title , description , keywords , gps_latitude , gps_longitude , gps_altitude ,
354+ gps_speed , gps_timestamp , timezone_offset , asset_subtype , hdr_type ,
355+ burst_flags , burst_flags_ext , burst_id , original_orientation , raw_fields ,
294356 ),
295357 )
296358 self ._dirty = True
0 commit comments