Model & schema for local mapping
This commit is contained in:
@@ -85,11 +85,11 @@ class RemoteDB with SqlDbBase {
|
||||
}
|
||||
await Future.wait([
|
||||
_sqliteDB.executeBatch(
|
||||
'INSERT OR REPLACE INTO collection_files ($collectionFilesColumns) values(?, ?, ?, ?, ?, ?, ?)',
|
||||
'INSERT INTO collection_files ($collectionFilesColumns) values(?, ?, ?, ?, ?, ?) ON CONFLICT(file_id, collection_id) DO UPDATE SET $collectionFilesUpdateColumns',
|
||||
collectionFileValues,
|
||||
),
|
||||
_sqliteDB.executeBatch(
|
||||
'INSERT INTO files ($filesColumns) values(${getParams(17)}) ON CONFLICT(id) DO UPDATE SET $filesUpdateColumns',
|
||||
'INSERT INTO files ($filesColumns) values(${getParams(15)}) ON CONFLICT(id) DO UPDATE SET $filesUpdateColumns',
|
||||
fileValues,
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -11,10 +11,21 @@ final String updateCollectionColumns = collectionColumns
|
||||
.join(', ');
|
||||
|
||||
const collectionFilesColumns =
|
||||
'collection_id, file_id, enc_key, enc_key_nonce, created_at, updated_at, is_deleted';
|
||||
'collection_id, file_id, enc_key, enc_key_nonce, created_at, updated_at';
|
||||
|
||||
final String collectionFilesUpdateColumns = collectionFilesColumns
|
||||
.split(', ')
|
||||
.where(
|
||||
(column) =>
|
||||
column != 'collection_id' ||
|
||||
column != 'file_id' ||
|
||||
column != 'created_at',
|
||||
)
|
||||
.map((column) => '$column = excluded.$column') // Use excluded virtual table
|
||||
.join(', ');
|
||||
const filesColumns =
|
||||
'id, owner_id, file_header, thumb_header, creation_time, modification_time, title, size, hash, lat, lng, '
|
||||
'metadata, priv_metadata, pub_metadata, info, local_id, local_mapping_src';
|
||||
'metadata, priv_metadata, pub_metadata, info';
|
||||
|
||||
final String filesUpdateColumns = filesColumns
|
||||
.split(', ')
|
||||
@@ -83,9 +94,7 @@ class RemoteDBMigration {
|
||||
metadata TEXT NOT NULL,
|
||||
priv_metadata TEXT,
|
||||
pub_metadata TEXT,
|
||||
info TEXT,
|
||||
local_id TEXT DEFAULT NULL,
|
||||
local_mapping_src TEXT DEFAULT NULL
|
||||
info TEXT
|
||||
)
|
||||
''',
|
||||
'''
|
||||
@@ -107,6 +116,14 @@ class RemoteDBMigration {
|
||||
DELETE FROM files WHERE id = OLD.file_id;
|
||||
END;
|
||||
''',
|
||||
'''
|
||||
CREATE TABLE upload_mapping (
|
||||
file_id INTEGER PRIMARY KEY,
|
||||
local_id TEXT DEFAULT NOT NULL,
|
||||
-- icloud identifier if available
|
||||
local_clould_id TEXT,
|
||||
local_mapping_src TEXT DEFAULT NULL
|
||||
)'''
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
50
mobile/lib/services/remote/localMapper/upload_local_map.dart
Normal file
50
mobile/lib/services/remote/localMapper/upload_local_map.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
enum MappingType {
|
||||
remote,
|
||||
cloudIdMatched,
|
||||
deviceUpload,
|
||||
deviceHashMatched,
|
||||
}
|
||||
|
||||
extension MappingTypeExtension on MappingType {
|
||||
String get name {
|
||||
switch (this) {
|
||||
case MappingType.remote:
|
||||
return "remote";
|
||||
case MappingType.cloudIdMatched:
|
||||
return "cloudIdMatched";
|
||||
case MappingType.deviceUpload:
|
||||
return "deviceUpload";
|
||||
case MappingType.deviceHashMatched:
|
||||
return "deviceHashMatched";
|
||||
}
|
||||
}
|
||||
|
||||
MappingType fromName(String name) {
|
||||
switch (name) {
|
||||
case "remote":
|
||||
return MappingType.remote;
|
||||
case "cloudIdMatched":
|
||||
return MappingType.cloudIdMatched;
|
||||
case "deviceUpload":
|
||||
return MappingType.deviceUpload;
|
||||
case "deviceHashMatched":
|
||||
return MappingType.deviceHashMatched;
|
||||
default:
|
||||
throw Exception("Unknown mapping type: $name");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UploadLocalMapping {
|
||||
final int remoteUploadID;
|
||||
final String localID;
|
||||
final String? localCloudID;
|
||||
final MappingType mappingType;
|
||||
|
||||
UploadLocalMapping({
|
||||
required this.remoteUploadID,
|
||||
required this.localID,
|
||||
required this.localCloudID,
|
||||
required this.mappingType,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user