Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 4ce9678

Browse files
authored
Merge pull request #1845 from TriliumNext/renovate/sqlite-5.x
fix(deps): update dependency sqlite to v5
2 parents cc24fe1 + c1e5ab2 commit 4ce9678

6 files changed

Lines changed: 54 additions & 17 deletions

File tree

.github/workflows/dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939

4040
- uses: nrwl/nx-set-shas@v4
4141
- name: Check affected
42-
run: pnpm nx affected -t rebuild-deps
42+
run: pnpm nx affected -t build rebuild-deps
4343

4444
report-electron-size:
4545
name: Report Electron size

apps/db-compare/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Database compare tool
2+
3+
> [!IMPORTANT]
4+
> 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).
5+
6+
To build and run manually:
7+
8+
```sh
9+
nx build db-compare
10+
node ./apps/db-compare/dist/compare.js
11+
```
12+
13+
To serve development build with arguments:
14+
15+
```sh
16+
nx serve db-compare --args "apps/server/spec/db/document_v214.db" --args "apps/server/spec/db/document_v214_migrated.db"
17+
```

apps/db-compare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dependencies": {
77
"colors": "1.4.0",
88
"diff": "5.0.0",
9-
"sqlite": "4.0.23",
9+
"sqlite": "5.1.1",
1010
"sqlite3": "5.1.5"
1111
},
1212
"nx": {

apps/db-compare/src/compare.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"use strict";
22

3-
import jsDiff from "diff";
3+
import * as jsDiff from "diff";
44
import * as sqlite from "sqlite";
55
import * as sqlite3 from "sqlite3";
66
import sql from "./sql.js";
77

88
import "colors";
9+
import path from "path";
910

1011
function printDiff(one: string, two: string) {
1112
const diff = jsDiff.diffChars(one, two);
@@ -67,11 +68,30 @@ function compareRows(table: string, rsLeft: Record<string, any>, rsRight: Record
6768
}
6869

6970
async function main() {
70-
const dbLeftPath = process.argv[2];
71-
const dbRightPath = process.argv[3];
71+
const dbLeftPath = process.argv.at(-2);
72+
const dbRightPath = process.argv.at(-1);
7273

73-
const dbLeft = await sqlite.open({filename: dbLeftPath, driver: sqlite3.Database});
74-
const dbRight = await sqlite.open({filename: dbRightPath, driver: sqlite3.Database});
74+
if (process.argv.length < 4 || !dbLeftPath || !dbRightPath) {
75+
console.log(`Usage: ${process.argv[0]} ${process.argv[1]} path/to/first.db path/to/second.db`);
76+
process.exit(1);
77+
}
78+
79+
let dbLeft: sqlite.Database;
80+
let dbRight: sqlite.Database;
81+
82+
try {
83+
dbLeft = await sqlite.open({filename: dbLeftPath, driver: sqlite3.Database});
84+
} catch (e: any) {
85+
console.error(`Could not load first database at ${path.resolve(dbRightPath)} due to: ${e.message}`);
86+
process.exit(2);
87+
}
88+
89+
try {
90+
dbRight = await sqlite.open({filename: dbRightPath, driver: sqlite3.Database});
91+
} catch (e: any) {
92+
console.error(`Could not load second database at ${path.resolve(dbRightPath)} due to: ${e.message}`);
93+
process.exit(3);
94+
}
7595

7696
async function compare(table: string, column: string, query: string) {
7797
const rsLeft = await sql.getIndexed(dbLeft, column, query);
@@ -81,7 +101,7 @@ async function main() {
81101
}
82102

83103
await compare("branches", "branchId",
84-
"SELECT branchId, noteId, parentNoteId, notePosition, utcDateCreated, isDeleted, prefix FROM branches");
104+
"SELECT branchId, noteId, parentNoteId, notePosition, utcDateModified, isDeleted, prefix FROM branches");
85105

86106
await compare("notes", "noteId",
87107
"SELECT noteId, title, dateCreated, utcDateCreated, isProtected, isDeleted FROM notes WHERE isDeleted = 0");
@@ -96,13 +116,13 @@ async function main() {
96116
"SELECT noteRevisionId, content FROM note_revision_contents");
97117

98118
await compare("options", "name",
99-
`SELECT name, value, utcDateCreated FROM options WHERE isSynced = 1`);
119+
`SELECT name, value, utcDateModified FROM options WHERE isSynced = 1`);
100120

101121
await compare("attributes", "attributeId",
102122
"SELECT attributeId, noteId, type, name, value FROM attributes");
103123

104-
await compare("api_tokens", "apiTokenId",
105-
"SELECT apiTokenId, token, utcDateCreated, isDeleted FROM api_tokens");
124+
await compare("etapi_tokens", "etapiTokenId",
125+
"SELECT etapiTokenId, name, tokenHash, utcDateCreated, utcDateModified, isDeleted FROM etapi_tokens");
106126

107127
await compare("entity_changes", "uniqueId",
108128
"SELECT entityName || '-' || entityId AS uniqueId, hash, isErased, utcDateChanged FROM entity_changes WHERE isSynced = 1");

apps/dump-db/src/inc/sql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Database, { Database as DatabaseType } from "better-sqlite3";
1+
import Database, { type Database as DatabaseType } from "better-sqlite3";
22

33
let dbConnection: DatabaseType;
44

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)