Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions apps/db-compare/README.md
Original file line number Diff line number Diff line change
@@ -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"
```
2 changes: 1 addition & 1 deletion apps/db-compare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
38 changes: 29 additions & 9 deletions apps/db-compare/src/compare.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -67,11 +68,30 @@ function compareRows(table: string, rsLeft: Record<string, any>, 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);
Expand All @@ -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");
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion apps/dump-db/src/inc/sql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Database, { Database as DatabaseType } from "better-sqlite3";
import Database, { type Database as DatabaseType } from "better-sqlite3";

let dbConnection: DatabaseType;

Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading