mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
core: fix migrate to sqlite progress reporting
This commit is contained in:
@@ -336,10 +336,10 @@ export type SQLiteOptions = {
|
||||
};
|
||||
export async function createDatabase(name: string, options: SQLiteOptions) {
|
||||
const db = new Kysely<RawDatabaseSchema>({
|
||||
log: (event) => {
|
||||
if (event.queryDurationMillis > 5)
|
||||
console.warn(event.query.sql, event.queryDurationMillis);
|
||||
},
|
||||
// log: (event) => {
|
||||
// if (event.queryDurationMillis > 5)
|
||||
// console.warn(event.query.sql, event.queryDurationMillis);
|
||||
// },
|
||||
dialect: options.dialect(name, async () => {
|
||||
await db.connection().execute(async (db) => {
|
||||
await setupDatabase(db, options);
|
||||
|
||||
@@ -99,14 +99,20 @@ class Migrator {
|
||||
|
||||
await indexedCollection.init();
|
||||
await table.init();
|
||||
let count = 0;
|
||||
for await (const entries of indexedCollection.iterate(100)) {
|
||||
await this.migrateToSQLite(
|
||||
db,
|
||||
table,
|
||||
collection.name,
|
||||
entries.map((i) => i[1]),
|
||||
version
|
||||
);
|
||||
sendMigrationProgressEvent(
|
||||
db.eventManager,
|
||||
collection.name,
|
||||
indexedCollection.indexer.indices.length,
|
||||
(count += 100)
|
||||
);
|
||||
}
|
||||
await indexedCollection.clear();
|
||||
}
|
||||
@@ -123,7 +129,6 @@ class Migrator {
|
||||
private async migrateToSQLite(
|
||||
db: Database,
|
||||
table: SQLCollection<keyof DatabaseSchema>,
|
||||
type: keyof Collections,
|
||||
items: (RawItem | undefined)[],
|
||||
version: number
|
||||
) {
|
||||
@@ -168,12 +173,6 @@ class Migrator {
|
||||
|
||||
if (toAdd.length > 0) {
|
||||
await table.put(toAdd as any);
|
||||
sendMigrationProgressEvent(
|
||||
db.eventManager,
|
||||
type,
|
||||
toAdd.length,
|
||||
toAdd.length
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user