Skip to content

armgit / ente

Public Imported from GitHub
0

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

Make contacts and log database migrations incremental

laurenspriemb8a154565358
diff --git a/mobile/packages/contacts/lib/src/db/contacts_database.dart b/mobile/packages/contacts/lib/src/db/contacts_database.dart
index 9aceb8053d..1b3f1c1906 100644
--- a/mobile/packages/contacts/lib/src/db/contacts_database.dart
+++ b/mobile/packages/contacts/lib/src/db/contacts_database.dart
@@ -251,42 +251,44 @@ class ContactsDatabase {
);
}
- await tx.execute('''
- CREATE TABLE $_contactsTable (
- id TEXT PRIMARY KEY,
- contact_user_id INTEGER NOT NULL,
- email TEXT,
- data_json TEXT,
- profile_picture_attachment_id TEXT,
- is_deleted INTEGER NOT NULL DEFAULT 0,
- created_at INTEGER NOT NULL,
- updated_at INTEGER NOT NULL
- )
- ''');
- await tx.execute(
- 'CREATE UNIQUE INDEX idx_contacts_contact_user_id '
- 'ON $_contactsTable(contact_user_id)',
- );
- await tx.execute(
- 'CREATE INDEX idx_contacts_updated_at '
- 'ON $_contactsTable(updated_at)',
- );
- await tx.execute('''
- CREATE TABLE $_attachmentsTable (
- attachment_id TEXT PRIMARY KEY,
- bytes BLOB NOT NULL,
- cached_at INTEGER NOT NULL
- )
- ''');
- await tx.execute('''
- CREATE TABLE $_stateTable (
- id INTEGER PRIMARY KEY CHECK (id = 1),
- last_synced_updated_at INTEGER NOT NULL DEFAULT 0
- )
- ''');
- await tx.execute(
- 'INSERT INTO $_stateTable (id, last_synced_updated_at) VALUES (1, 0)',
- );
+ if (currentVersion < 1) {
+ await tx.execute('''
+ CREATE TABLE $_contactsTable (
+ id TEXT PRIMARY KEY,
+ contact_user_id INTEGER NOT NULL,
+ email TEXT,
+ data_json TEXT,
+ profile_picture_attachment_id TEXT,
+ is_deleted INTEGER NOT NULL DEFAULT 0,
+ created_at INTEGER NOT NULL,
+ updated_at INTEGER NOT NULL
+ )
+ ''');
+ await tx.execute(
+ 'CREATE UNIQUE INDEX idx_contacts_contact_user_id '
+ 'ON $_contactsTable(contact_user_id)',
+ );
+ await tx.execute(
+ 'CREATE INDEX idx_contacts_updated_at '
+ 'ON $_contactsTable(updated_at)',
+ );
+ await tx.execute('''
+ CREATE TABLE $_attachmentsTable (
+ attachment_id TEXT PRIMARY KEY,
+ bytes BLOB NOT NULL,
+ cached_at INTEGER NOT NULL
+ )
+ ''');
+ await tx.execute('''
+ CREATE TABLE $_stateTable (
+ id INTEGER PRIMARY KEY CHECK (id = 1),
+ last_synced_updated_at INTEGER NOT NULL DEFAULT 0
+ )
+ ''');
+ await tx.execute(
+ 'INSERT INTO $_stateTable (id, last_synced_updated_at) VALUES (1, 0)',
+ );
+ }
await tx.execute('PRAGMA user_version = $_databaseVersion');
return true;
});
diff --git a/mobile/packages/log_viewer/lib/src/core/log_database.dart b/mobile/packages/log_viewer/lib/src/core/log_database.dart
index 25e340f7a4..736455d9da 100644
--- a/mobile/packages/log_viewer/lib/src/core/log_database.dart
+++ b/mobile/packages/log_viewer/lib/src/core/log_database.dart
@@ -49,21 +49,23 @@ class LogDatabase {
);
}
- await tx.execute('''
- CREATE TABLE $_tableName(
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- message TEXT NOT NULL,
- level TEXT NOT NULL,
- timestamp INTEGER NOT NULL,
- logger_name TEXT NOT NULL,
- error TEXT,
- stack_trace TEXT,
- process_prefix TEXT NOT NULL DEFAULT ''
- )
- ''');
- await tx.execute(
- 'CREATE INDEX idx_timestamp ON $_tableName(timestamp DESC)',
- );
+ if (currentVersion < 1) {
+ await tx.execute('''
+ CREATE TABLE $_tableName(
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ message TEXT NOT NULL,
+ level TEXT NOT NULL,
+ timestamp INTEGER NOT NULL,
+ logger_name TEXT NOT NULL,
+ error TEXT,
+ stack_trace TEXT,
+ process_prefix TEXT NOT NULL DEFAULT ''
+ )
+ ''');
+ await tx.execute(
+ 'CREATE INDEX idx_timestamp ON $_tableName(timestamp DESC)',
+ );
+ }
await tx.execute('PRAGMA user_version = $_databaseVersion');
return true;
});