kahu-signalk 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -203,6 +203,21 @@ If you see *“kahu-signalk requires Node.js 22.5.0 or later”*, switch the Nod
203
203
 
204
204
  You may see an **ExperimentalWarning** about SQLite from Node; that is expected until the API is stabilized.
205
205
 
206
+ ## Route Cache Migration Fallback
207
+
208
+ The plugin now auto-checks route cache schema compatibility at startup and will recreate an incompatible cache database automatically when needed.
209
+
210
+ If you still see SQLite errors like:
211
+ - `foreign key mismatch - "target_position" referencing "target"`
212
+
213
+ you can manually reset the plugin cache and restart Signal K:
214
+
215
+ ```bash
216
+ rm ~/.signalk/plugin-config-data/radarhub/routecache.sqlite3
217
+ ```
218
+
219
+ This only clears the local cache used for upload buffering; it does not remove plugin code or configuration.
220
+
206
221
  ### Command typo
207
222
 
208
223
  Use `--config-dir` (with an **n**), not `--confic-dir`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kahu-signalk",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Contribute AIS and ARPA targets from your vessel to crowdsourcing for marine safety!",
5
5
  "keywords": [
6
6
  "signalk-node-server-plugin",
@@ -48,6 +48,7 @@ class Routecache {
48
48
  await this.openDB();
49
49
  await this.createEmpty();
50
50
  await this.migrate();
51
+ await this.ensureCompatibleSchemaOrRebuild();
51
52
  return;
52
53
  } catch (e) {
53
54
  console.error(e, ". Deleting route cache.");
@@ -62,6 +63,45 @@ class Routecache {
62
63
  }
63
64
  }
64
65
 
66
+ async ensureCompatibleSchemaOrRebuild() {
67
+ const hasTargetTable = this.doesTableExist("target");
68
+ const hasTargetPositionTable = this.doesTableExist("target_position");
69
+ if (!hasTargetTable || !hasTargetPositionTable) return;
70
+
71
+ const fkRows = this._all("PRAGMA foreign_key_list(target_position)");
72
+ const hasExpectedFk = fkRows.some(
73
+ (row) =>
74
+ row.from === "target_id" &&
75
+ row.table === "target" &&
76
+ row.to === "target_id"
77
+ );
78
+
79
+ if (hasExpectedFk) return;
80
+
81
+ console.warn(
82
+ "Detected incompatible route cache schema (target_position FK mismatch). Rebuilding route cache database."
83
+ );
84
+
85
+ await this.closeDB();
86
+ await fs.unlink(this.db_name);
87
+ await this.openDB();
88
+ await this.createEmpty();
89
+ await this.migrate();
90
+
91
+ const rebuiltFkRows = this._all("PRAGMA foreign_key_list(target_position)");
92
+ const rebuiltHasExpectedFk = rebuiltFkRows.some(
93
+ (row) =>
94
+ row.from === "target_id" &&
95
+ row.table === "target" &&
96
+ row.to === "target_id"
97
+ );
98
+ if (!rebuiltHasExpectedFk) {
99
+ throw new Error(
100
+ "Route cache rebuild completed, but target_position foreign key is still incompatible."
101
+ );
102
+ }
103
+ }
104
+
65
105
  doesTableExist(tableName) {
66
106
  const row = this.db
67
107
  .prepare("SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name=?")