import 'package:sqflite/sqflite.dart'; class SqfliteLocalMediaDbSchema { static const entryTable = 'entry'; static const dateTakenTable = 'dateTaken'; static const metadataTable = 'metadata'; static const addressTable = 'address'; static const favouriteTable = 'favourites'; static const coverTable = 'covers'; static const dynamicAlbumTable = 'dynamicAlbums'; static const vaultTable = 'vaults'; static const trashTable = 'trash'; static const videoPlaybackTable = 'videoPlayback'; static const allTables = [ entryTable, dateTakenTable, metadataTable, addressTable, favouriteTable, coverTable, dynamicAlbumTable, vaultTable, trashTable, videoPlaybackTable, ]; static Future createLatestVersion(Database db) async { await Future.forEach(allTables, (table) => createTable(db, table)); } // Resa async per poter eseguire più statement per tabella (es. indici). static Future createTable(Database db, String table) async { switch (table) { case entryTable: // Tabella 'entry' con i nuovi campi per la sorgente remota await db.execute( 'CREATE TABLE $entryTable(' 'id INTEGER PRIMARY KEY' ', contentId INTEGER' ', uri TEXT' ', path TEXT' ', sourceMimeType TEXT' ', width INTEGER' ', height INTEGER' ', sourceRotationDegrees INTEGER' ', sizeBytes INTEGER' ', title TEXT' ', dateAddedSecs INTEGER DEFAULT (strftime(\'%s\',\'now\'))' ', dateModifiedMillis INTEGER' ', sourceDateTakenMillis INTEGER' ', durationMillis INTEGER' ', trashed INTEGER DEFAULT 0' ', origin INTEGER DEFAULT 0' // --- campi per la sorgente remota --- ', provider TEXT' // es. "json@patachina" ', remoteId TEXT' // es. sha256 del path relativo o id server ', remotePath TEXT' // es. "photos/original/.../file.jpg" ', remoteThumb1 TEXT' // es. "photos/thumbs/..._min.jpg" ', remoteThumb2 TEXT' // es. "photos/thumbs/..._avg.jpg" ')', ); // Indici utili per query e merge locale+remoto await db.execute('CREATE INDEX IF NOT EXISTS idx_entry_origin ON $entryTable(origin);'); await db.execute('CREATE INDEX IF NOT EXISTS idx_entry_remoteId ON $entryTable(remoteId);'); return; case dateTakenTable: await db.execute( 'CREATE TABLE $dateTakenTable(' 'id INTEGER PRIMARY KEY' ', dateMillis INTEGER' ')', ); return; case metadataTable: await db.execute( 'CREATE TABLE $metadataTable(' 'id INTEGER PRIMARY KEY' ', mimeType TEXT' ', dateMillis INTEGER' ', flags INTEGER' ', rotationDegrees INTEGER' ', xmpSubjects TEXT' ', xmpTitle TEXT' ', latitude REAL' ', longitude REAL' ', rating INTEGER' ')', ); return; case addressTable: await db.execute( 'CREATE TABLE $addressTable(' 'id INTEGER PRIMARY KEY' ', addressLine TEXT' ', countryCode TEXT' ', countryName TEXT' ', adminArea TEXT' ', locality TEXT' ')', ); return; case favouriteTable: await db.execute( 'CREATE TABLE $favouriteTable(' 'id INTEGER PRIMARY KEY' ')', ); return; case coverTable: await db.execute( 'CREATE TABLE $coverTable(' 'filter TEXT PRIMARY KEY' ', entryId INTEGER' ', packageName TEXT' ', color TEXT' ')', ); return; case dynamicAlbumTable: await db.execute( 'CREATE TABLE $dynamicAlbumTable(' 'name TEXT PRIMARY KEY' ', filter TEXT' ')', ); return; case vaultTable: await db.execute( 'CREATE TABLE $vaultTable(' 'name TEXT PRIMARY KEY' ', autoLock INTEGER' ', useBin INTEGER' ', lockType TEXT' ')', ); return; case trashTable: await db.execute( 'CREATE TABLE $trashTable(' 'id INTEGER PRIMARY KEY' ', path TEXT' ', dateMillis INTEGER' ')', ); return; case videoPlaybackTable: await db.execute( 'CREATE TABLE $videoPlaybackTable(' 'id INTEGER PRIMARY KEY' ', resumeTimeMillis INTEGER' ')', ); return; default: throw Exception('unknown table=$table'); } } }