11"use strict" ;
22
3- import jsDiff from "diff" ;
3+ import * as jsDiff from "diff" ;
44import * as sqlite from "sqlite" ;
55import * as sqlite3 from "sqlite3" ;
66import sql from "./sql.js" ;
77
88import "colors" ;
9+ import path from "path" ;
910
1011function 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
6970async 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" ) ;
0 commit comments