2022-07-05 22:20:24 +02:00
|
|
|
import 'package:drift/drift.dart';
|
|
|
|
|
|
|
|
class Servers extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
TextColumn get address => text().unique()();
|
|
|
|
}
|
|
|
|
|
|
|
|
class Accounts extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
IntColumn get server =>
|
|
|
|
integer().references(Servers, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
TextColumn get userId => text()();
|
|
|
|
|
|
|
|
@override
|
|
|
|
get uniqueKeys => [
|
|
|
|
{server, userId},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A file located on a server
|
|
|
|
class Files extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
IntColumn get server =>
|
|
|
|
integer().references(Servers, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
IntColumn get fileId => integer()();
|
|
|
|
IntColumn get contentLength => integer().nullable()();
|
|
|
|
TextColumn get contentType => text().nullable()();
|
|
|
|
TextColumn get etag => text().nullable()();
|
|
|
|
DateTimeColumn get lastModified =>
|
2023-02-20 15:21:35 +01:00
|
|
|
dateTime().map(const SqliteDateTimeConverter()).nullable()();
|
2022-07-05 22:20:24 +02:00
|
|
|
BoolColumn get isCollection => boolean().nullable()();
|
|
|
|
IntColumn get usedBytes => integer().nullable()();
|
|
|
|
BoolColumn get hasPreview => boolean().nullable()();
|
|
|
|
TextColumn get ownerId => text().nullable()();
|
2022-07-11 21:45:20 +02:00
|
|
|
TextColumn get ownerDisplayName => text().nullable()();
|
2022-07-05 22:20:24 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
get uniqueKeys => [
|
|
|
|
{server, fileId},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Account specific properties associated with a file
|
|
|
|
///
|
|
|
|
/// A file on a Nextcloud server can have more than 1 path when it's shared
|
|
|
|
class AccountFiles extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
IntColumn get account =>
|
|
|
|
integer().references(Accounts, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
IntColumn get file =>
|
|
|
|
integer().references(Files, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
TextColumn get relativePath => text()();
|
|
|
|
BoolColumn get isFavorite => boolean().nullable()();
|
|
|
|
BoolColumn get isArchived => boolean().nullable()();
|
|
|
|
DateTimeColumn get overrideDateTime =>
|
2023-02-20 15:21:35 +01:00
|
|
|
dateTime().map(const SqliteDateTimeConverter()).nullable()();
|
2022-07-13 22:23:41 +02:00
|
|
|
DateTimeColumn get bestDateTime =>
|
2023-02-20 15:21:35 +01:00
|
|
|
dateTime().map(const SqliteDateTimeConverter())();
|
2022-07-05 22:20:24 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
get uniqueKeys => [
|
|
|
|
{account, file},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// An image file
|
|
|
|
class Images extends Table {
|
|
|
|
// image data technically is identical between accounts, but the way it's
|
|
|
|
// stored in the server is account specific so we follow the server here
|
|
|
|
IntColumn get accountFile =>
|
|
|
|
integer().references(AccountFiles, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
DateTimeColumn get lastUpdated =>
|
2023-02-20 15:21:35 +01:00
|
|
|
dateTime().map(const SqliteDateTimeConverter())();
|
2022-07-05 22:20:24 +02:00
|
|
|
TextColumn get fileEtag => text().nullable()();
|
|
|
|
IntColumn get width => integer().nullable()();
|
|
|
|
IntColumn get height => integer().nullable()();
|
|
|
|
TextColumn get exifRaw => text().nullable()();
|
|
|
|
|
|
|
|
// exif columns
|
|
|
|
DateTimeColumn get dateTimeOriginal =>
|
2023-02-20 15:21:35 +01:00
|
|
|
dateTime().map(const SqliteDateTimeConverter()).nullable()();
|
2022-07-05 22:20:24 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
get primaryKey => {accountFile};
|
|
|
|
}
|
|
|
|
|
2022-08-27 17:31:58 +02:00
|
|
|
/// Estimated locations for images
|
|
|
|
class ImageLocations extends Table {
|
|
|
|
IntColumn get accountFile =>
|
|
|
|
integer().references(AccountFiles, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
IntColumn get version => integer()();
|
|
|
|
TextColumn get name => text().nullable()();
|
|
|
|
RealColumn get latitude => real().nullable()();
|
|
|
|
RealColumn get longitude => real().nullable()();
|
|
|
|
TextColumn get countryCode => text().nullable()();
|
|
|
|
TextColumn get admin1 => text().nullable()();
|
|
|
|
TextColumn get admin2 => text().nullable()();
|
|
|
|
|
|
|
|
@override
|
|
|
|
get primaryKey => {accountFile};
|
|
|
|
}
|
|
|
|
|
2022-07-05 22:20:24 +02:00
|
|
|
/// A file inside trashbin
|
|
|
|
@DataClassName("Trash")
|
|
|
|
class Trashes extends Table {
|
|
|
|
IntColumn get file =>
|
|
|
|
integer().references(Files, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
TextColumn get filename => text()();
|
|
|
|
TextColumn get originalLocation => text()();
|
|
|
|
DateTimeColumn get deletionTime =>
|
2023-02-20 15:21:35 +01:00
|
|
|
dateTime().map(const SqliteDateTimeConverter())();
|
2022-07-05 22:20:24 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
get primaryKey => {file};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A file located under another dir (dir is also a file)
|
|
|
|
class DirFiles extends Table {
|
|
|
|
IntColumn get dir =>
|
|
|
|
integer().references(Files, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
IntColumn get child =>
|
|
|
|
integer().references(Files, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
|
|
|
|
@override
|
|
|
|
get primaryKey => {dir, child};
|
|
|
|
}
|
|
|
|
|
2023-04-13 17:32:31 +02:00
|
|
|
class NcAlbums extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
IntColumn get account =>
|
|
|
|
integer().references(Accounts, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
TextColumn get relativePath => text()();
|
|
|
|
IntColumn get lastPhoto => integer().nullable()();
|
|
|
|
IntColumn get nbItems => integer()();
|
|
|
|
TextColumn get location => text().nullable()();
|
|
|
|
DateTimeColumn get dateStart =>
|
|
|
|
dateTime().map(const SqliteDateTimeConverter()).nullable()();
|
|
|
|
DateTimeColumn get dateEnd =>
|
|
|
|
dateTime().map(const SqliteDateTimeConverter()).nullable()();
|
2023-05-06 19:44:35 +02:00
|
|
|
TextColumn get collaborators => text()();
|
2023-04-13 17:32:31 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<Set<Column>>? get uniqueKeys => [
|
|
|
|
{account, relativePath},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
class NcAlbumItems extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
IntColumn get parent =>
|
|
|
|
integer().references(NcAlbums, #rowId, onDelete: KeyAction.cascade)();
|
2023-05-06 19:44:35 +02:00
|
|
|
TextColumn get relativePath => text()();
|
2023-04-13 17:32:31 +02:00
|
|
|
IntColumn get fileId => integer()();
|
2023-05-06 19:44:35 +02:00
|
|
|
IntColumn get contentLength => integer().nullable()();
|
|
|
|
TextColumn get contentType => text().nullable()();
|
|
|
|
TextColumn get etag => text().nullable()();
|
|
|
|
DateTimeColumn get lastModified =>
|
|
|
|
dateTime().map(const SqliteDateTimeConverter()).nullable()();
|
|
|
|
BoolColumn get hasPreview => boolean().nullable()();
|
|
|
|
BoolColumn get isFavorite => boolean().nullable()();
|
|
|
|
IntColumn get fileMetadataWidth => integer().nullable()();
|
|
|
|
IntColumn get fileMetadataHeight => integer().nullable()();
|
2023-04-13 17:32:31 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<Set<Column>>? get uniqueKeys => [
|
|
|
|
{parent, fileId},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-07-05 22:20:24 +02:00
|
|
|
class Albums extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
IntColumn get file => integer()
|
|
|
|
.references(Files, #rowId, onDelete: KeyAction.cascade)
|
|
|
|
.unique()();
|
2022-08-31 16:19:31 +02:00
|
|
|
// store the etag of the file when the album is cached in the db
|
|
|
|
TextColumn get fileEtag => text().nullable()();
|
2022-07-05 22:20:24 +02:00
|
|
|
IntColumn get version => integer()();
|
|
|
|
DateTimeColumn get lastUpdated =>
|
2023-02-20 15:21:35 +01:00
|
|
|
dateTime().map(const SqliteDateTimeConverter())();
|
2022-07-05 22:20:24 +02:00
|
|
|
TextColumn get name => text()();
|
|
|
|
|
|
|
|
// provider
|
|
|
|
TextColumn get providerType => text()();
|
|
|
|
TextColumn get providerContent => text()();
|
|
|
|
|
|
|
|
// cover provider
|
|
|
|
TextColumn get coverProviderType => text()();
|
|
|
|
TextColumn get coverProviderContent => text()();
|
|
|
|
|
|
|
|
// sort provider
|
|
|
|
TextColumn get sortProviderType => text()();
|
|
|
|
TextColumn get sortProviderContent => text()();
|
|
|
|
}
|
|
|
|
|
|
|
|
class AlbumShares extends Table {
|
|
|
|
IntColumn get album =>
|
|
|
|
integer().references(Albums, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
TextColumn get userId => text()();
|
|
|
|
TextColumn get displayName => text().nullable()();
|
2023-02-20 15:21:35 +01:00
|
|
|
DateTimeColumn get sharedAt =>
|
|
|
|
dateTime().map(const SqliteDateTimeConverter())();
|
2022-07-05 22:20:24 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
get primaryKey => {album, userId};
|
|
|
|
}
|
|
|
|
|
2022-08-05 11:28:28 +02:00
|
|
|
class Tags extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
IntColumn get server =>
|
|
|
|
integer().references(Servers, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
IntColumn get tagId => integer()();
|
|
|
|
TextColumn get displayName => text()();
|
|
|
|
BoolColumn get userVisible => boolean().nullable()();
|
|
|
|
BoolColumn get userAssignable => boolean().nullable()();
|
|
|
|
|
|
|
|
@override
|
|
|
|
get uniqueKeys => [
|
|
|
|
{server, tagId},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-08-05 11:39:49 +02:00
|
|
|
class Persons extends Table {
|
|
|
|
IntColumn get rowId => integer().autoIncrement()();
|
|
|
|
IntColumn get account =>
|
|
|
|
integer().references(Accounts, #rowId, onDelete: KeyAction.cascade)();
|
|
|
|
TextColumn get name => text()();
|
|
|
|
IntColumn get thumbFaceId => integer()();
|
|
|
|
IntColumn get count => integer()();
|
|
|
|
|
|
|
|
@override
|
|
|
|
get uniqueKeys => [
|
|
|
|
{account, name},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-02-20 15:21:35 +01:00
|
|
|
class SqliteDateTimeConverter extends TypeConverter<DateTime, DateTime> {
|
|
|
|
const SqliteDateTimeConverter();
|
2022-07-05 22:20:24 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
DateTime? mapToDart(DateTime? fromDb) => fromDb?.toUtc();
|
|
|
|
|
|
|
|
@override
|
|
|
|
DateTime? mapToSql(DateTime? value) => value?.toUtc();
|
|
|
|
}
|