jettypod 4.2.5 → 4.2.6
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/lib/database.js +24 -5
- package/package.json +1 -1
package/lib/database.js
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
const sqlite3 = require('sqlite3').verbose();
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const { getGitRoot } = require('./git-root');
|
|
4
5
|
|
|
5
6
|
// Singleton database connection
|
|
6
7
|
let db = null;
|
|
7
8
|
let cachedJettypodDir = null;
|
|
8
9
|
let cachedDbPath = null;
|
|
10
|
+
let cachedGitRoot = null;
|
|
9
11
|
let isClosing = false;
|
|
10
12
|
let migrationPromise = null;
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Get the root directory for jettypod operations
|
|
16
|
+
* Always returns the main repo, even when called from a worktree
|
|
17
|
+
*/
|
|
18
|
+
function getRepoRoot() {
|
|
19
|
+
if (!cachedGitRoot) {
|
|
20
|
+
try {
|
|
21
|
+
cachedGitRoot = getGitRoot();
|
|
22
|
+
} catch (err) {
|
|
23
|
+
// Fall back to cwd if not in a git repo (e.g., during init)
|
|
24
|
+
cachedGitRoot = process.cwd();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return cachedGitRoot;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Dynamic getters for paths (always use main repo, not worktree)
|
|
13
31
|
function getJettypodDir() {
|
|
14
|
-
const
|
|
15
|
-
if (!cachedJettypodDir ||
|
|
16
|
-
cachedJettypodDir = path.join(
|
|
32
|
+
const root = getRepoRoot();
|
|
33
|
+
if (!cachedJettypodDir || cachedJettypodDir !== path.join(root, '.jettypod')) {
|
|
34
|
+
cachedJettypodDir = path.join(root, '.jettypod');
|
|
17
35
|
// Use separate database for tests
|
|
18
36
|
const dbFileName = process.env.NODE_ENV === 'test' ? 'test-work.db' : 'work.db';
|
|
19
37
|
cachedDbPath = path.join(cachedJettypodDir, dbFileName);
|
|
@@ -59,7 +77,7 @@ function ensureJettyPodDir() {
|
|
|
59
77
|
function getDb() {
|
|
60
78
|
// Check if directory changed - if so, reset connection
|
|
61
79
|
const dbFileName = process.env.NODE_ENV === 'test' ? 'test-work.db' : 'work.db';
|
|
62
|
-
const currentPath = path.join(
|
|
80
|
+
const currentPath = path.join(getRepoRoot(), '.jettypod', dbFileName);
|
|
63
81
|
if (db && cachedDbPath && cachedDbPath !== currentPath) {
|
|
64
82
|
// Directory changed - abandon old connection without closing
|
|
65
83
|
// Attempting to close with active prepared statements causes FATAL errors
|
|
@@ -252,6 +270,7 @@ function resetDb() {
|
|
|
252
270
|
db = null;
|
|
253
271
|
cachedJettypodDir = null;
|
|
254
272
|
cachedDbPath = null;
|
|
273
|
+
cachedGitRoot = null;
|
|
255
274
|
isClosing = false;
|
|
256
275
|
migrationPromise = null;
|
|
257
276
|
}
|