Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Enable foreign keys

vishnukvmd904a010abfb5
diff --git a/lib/db/files_db.dart b/lib/db/files_db.dart
index 52852e5c12..69d98f8d2b 100644
--- a/lib/db/files_db.dart
+++ b/lib/db/files_db.dart
@@ -73,7 +73,10 @@ class FilesDB {
// we need to write query based on that field
static const columnMMdVisibility = 'mmd_visibility';
- static final initializationScript = [...createTable(filesTable)];
+ static final initializationScript = [
+ enableForeignKeys(),
+ ...createTable(filesTable),
+ ];
static final migrationScripts = [
...alterDeviceFolderToAllowNULL(),
...alterTimestampColumnTypes(),
@@ -118,6 +121,10 @@ class FilesDB {
return await openDatabaseWithMigration(path, dbConfig);
}
+ static String enableForeignKeys() {
+ return "PRAGMA foreign_keys = ON;";
+ }
+
// SQL code to create the database table
static List<String> createTable(String tableName) {
return [
@@ -390,7 +397,8 @@ class FilesDB {
CREATE TABLE IF NOT EXISTS $embeddingsTable (
$columnGeneratedID INTEGER PRIMARY KEY,
$columnEmbedding TEXT NOT NULL,
- $columnUpdationTime INTEGER NOT NULL DEFAULT -1
+ $columnUpdationTime INTEGER NOT NULL DEFAULT -1,
+ FOREIGN KEY($columnGeneratedID) REFERENCES $filesTable($columnGeneratedID)
);
'''
];