@@ -286,7 +286,25 @@ def initialize_db(self):
286286 cursor = conn .cursor ()
287287
288288 # Database-specific modifications
289- if self .db_type == 'mysql' :
289+ if self .db_type in ['mysql' , 'mariadb' ]:
290+ # Keep full VARCHAR storage but constrain indexed prefixes to stay
291+ # under InnoDB's key-length limit when using utf8mb4.
292+ if table_name == 'requests' :
293+ query = query .replace (
294+ "UNIQUE(media_type, tmdb_request_id, tmdb_source_id)," ,
295+ "UNIQUE KEY uniq_requests_identity (media_type(191), tmdb_request_id(191), tmdb_source_id(191)),"
296+ )
297+ elif table_name == 'metadata' :
298+ query = query .replace (
299+ "UNIQUE(media_id, media_type)" ,
300+ "UNIQUE KEY uniq_metadata_media_type (media_id(191), media_type(191))"
301+ )
302+ elif table_name == 'pending_requests' :
303+ query = query .replace (
304+ "UNIQUE(tmdb_id, media_type)" ,
305+ "UNIQUE KEY uniq_pending_tmdb_media_type (tmdb_id(191), media_type(191))"
306+ )
307+
290308 # Order matters: do specific replacements first
291309 query = query .replace ("INTEGER PRIMARY KEY AUTOINCREMENT" , "INT AUTO_INCREMENT PRIMARY KEY" )
292310 query = query .replace ("INTEGER" , "INT" )
0 commit comments