diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index cadd88e7d..6497ebb96 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -39,7 +39,7 @@ jobs: - uses: nrwl/nx-set-shas@v4 - name: Check affected - run: pnpm nx affected -t rebuild-deps + run: pnpm nx affected -t build rebuild-deps report-electron-size: name: Report Electron size diff --git a/apps/db-compare/README.md b/apps/db-compare/README.md new file mode 100644 index 000000000..4cc13218a --- /dev/null +++ b/apps/db-compare/README.md @@ -0,0 +1,17 @@ +# Database compare tool + +> [!IMPORTANT] +> The original implementation was signficantly out of date. While we have made the effort of updating dependencies and getting it to run, currently it only compares the old database structure (v214). + +To build and run manually: + +```sh +nx build db-compare +node ./apps/db-compare/dist/compare.js +``` + +To serve development build with arguments: + +```sh +nx serve db-compare --args "apps/server/spec/db/document_v214.db" --args "apps/server/spec/db/document_v214_migrated.db" +``` \ No newline at end of file diff --git a/apps/db-compare/package.json b/apps/db-compare/package.json index 113afc662..d69e7a451 100644 --- a/apps/db-compare/package.json +++ b/apps/db-compare/package.json @@ -6,7 +6,7 @@ "dependencies": { "colors": "1.4.0", "diff": "5.0.0", - "sqlite": "4.0.23", + "sqlite": "5.1.1", "sqlite3": "5.1.5" }, "nx": { diff --git a/apps/db-compare/src/compare.ts b/apps/db-compare/src/compare.ts index 42e8d9ecf..64410cafe 100644 --- a/apps/db-compare/src/compare.ts +++ b/apps/db-compare/src/compare.ts @@ -1,11 +1,12 @@ "use strict"; -import jsDiff from "diff"; +import * as jsDiff from "diff"; import * as sqlite from "sqlite"; import * as sqlite3 from "sqlite3"; import sql from "./sql.js"; import "colors"; +import path from "path"; function printDiff(one: string, two: string) { const diff = jsDiff.diffChars(one, two); @@ -67,11 +68,30 @@ function compareRows(table: string, rsLeft: Record, rsRight: Record } async function main() { - const dbLeftPath = process.argv[2]; - const dbRightPath = process.argv[3]; + const dbLeftPath = process.argv.at(-2); + const dbRightPath = process.argv.at(-1); - const dbLeft = await sqlite.open({filename: dbLeftPath, driver: sqlite3.Database}); - const dbRight = await sqlite.open({filename: dbRightPath, driver: sqlite3.Database}); + if (process.argv.length < 4 || !dbLeftPath || !dbRightPath) { + console.log(`Usage: ${process.argv[0]} ${process.argv[1]} path/to/first.db path/to/second.db`); + process.exit(1); + } + + let dbLeft: sqlite.Database; + let dbRight: sqlite.Database; + + try { + dbLeft = await sqlite.open({filename: dbLeftPath, driver: sqlite3.Database}); + } catch (e: any) { + console.error(`Could not load first database at ${path.resolve(dbRightPath)} due to: ${e.message}`); + process.exit(2); + } + + try { + dbRight = await sqlite.open({filename: dbRightPath, driver: sqlite3.Database}); + } catch (e: any) { + console.error(`Could not load second database at ${path.resolve(dbRightPath)} due to: ${e.message}`); + process.exit(3); + } async function compare(table: string, column: string, query: string) { const rsLeft = await sql.getIndexed(dbLeft, column, query); @@ -81,7 +101,7 @@ async function main() { } await compare("branches", "branchId", - "SELECT branchId, noteId, parentNoteId, notePosition, utcDateCreated, isDeleted, prefix FROM branches"); + "SELECT branchId, noteId, parentNoteId, notePosition, utcDateModified, isDeleted, prefix FROM branches"); await compare("notes", "noteId", "SELECT noteId, title, dateCreated, utcDateCreated, isProtected, isDeleted FROM notes WHERE isDeleted = 0"); @@ -96,13 +116,13 @@ async function main() { "SELECT noteRevisionId, content FROM note_revision_contents"); await compare("options", "name", - `SELECT name, value, utcDateCreated FROM options WHERE isSynced = 1`); + `SELECT name, value, utcDateModified FROM options WHERE isSynced = 1`); await compare("attributes", "attributeId", "SELECT attributeId, noteId, type, name, value FROM attributes"); - await compare("api_tokens", "apiTokenId", - "SELECT apiTokenId, token, utcDateCreated, isDeleted FROM api_tokens"); + await compare("etapi_tokens", "etapiTokenId", + "SELECT etapiTokenId, name, tokenHash, utcDateCreated, utcDateModified, isDeleted FROM etapi_tokens"); await compare("entity_changes", "uniqueId", "SELECT entityName || '-' || entityId AS uniqueId, hash, isErased, utcDateChanged FROM entity_changes WHERE isSynced = 1"); diff --git a/apps/dump-db/src/inc/sql.ts b/apps/dump-db/src/inc/sql.ts index c0f6ebc50..481d95427 100644 --- a/apps/dump-db/src/inc/sql.ts +++ b/apps/dump-db/src/inc/sql.ts @@ -1,4 +1,4 @@ -import Database, { Database as DatabaseType } from "better-sqlite3"; +import Database, { type Database as DatabaseType } from "better-sqlite3"; let dbConnection: DatabaseType; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a3597bc2..f760f9807 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -293,8 +293,8 @@ importers: specifier: 5.0.0 version: 5.0.0 sqlite: - specifier: 4.0.23 - version: 4.0.23 + specifier: 5.1.1 + version: 5.1.1 sqlite3: specifier: 5.1.5 version: 5.1.5(encoding@0.1.13) @@ -9421,8 +9421,8 @@ packages: sqlite3@5.1.5: resolution: {integrity: sha512-7sP16i4wI+yKnGOO2q2ijze7EjQ9US+Vw7DYYwxfFtqNZDGgBcEw0oeDaDvUTq66uJOzVd/z6MkIg+c9erSJKg==} - sqlite@4.0.23: - resolution: {integrity: sha512-dSdmSkrdIhUL7xP/fiEMfFuAo4dxb0afag3rK8T4Y9lYxE3g3fXT0J8H9qSFvmcKxnM0zEA8yvLbpdWQ8mom3g==} + sqlite@5.1.1: + resolution: {integrity: sha512-oBkezXa2hnkfuJwUo44Hl9hS3er+YFtueifoajrgidvqsJRQFpc5fKoAkAor1O5ZnLoa28GBScfHXs8j0K358Q==} ssri@12.0.0: resolution: {integrity: sha512-S7iGNosepx9RadX82oimUkvr0Ct7IjJbEbs4mJcTxst8um95J3sDYU1RBEOvdu6oL1Wek2ODI5i4MAw+dZ6cAQ==} @@ -21484,7 +21484,7 @@ snapshots: - encoding - supports-color - sqlite@4.0.23: {} + sqlite@5.1.1: {} ssri@12.0.0: dependencies: