@fudrouter/fsrouter 0.6.100 → 0.6.101
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/dist/lib/db/driver.js +8 -0
- package/dist/routes/db/route.js +7 -10
- package/package.json +1 -1
package/dist/lib/db/driver.js
CHANGED
|
@@ -79,6 +79,14 @@ export async function getAdapter() {
|
|
|
79
79
|
return state.initPromise;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
// Force re-open the underlying connection (used after an explicit close, e.g.
|
|
83
|
+
// during raw DB restore). Without this, getAdapter() would return the stale
|
|
84
|
+
// closed instance and every subsequent query throws "connection is not open".
|
|
85
|
+
export function resetAdapter() {
|
|
86
|
+
state.instance = null;
|
|
87
|
+
state.initPromise = null;
|
|
88
|
+
}
|
|
89
|
+
|
|
82
90
|
export function getAdapterSync() {
|
|
83
91
|
if (!state.instance) throw new Error("[DB] adapter not initialized — await getAdapter() first");
|
|
84
92
|
return state.instance;
|
package/dist/routes/db/route.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAdapter } from "../../lib/db/driver.js";
|
|
1
|
+
import { getAdapter, resetAdapter } from "../../lib/db/driver.js";
|
|
2
2
|
import { exportDb, importDb } from "../../lib/db/index.js";
|
|
3
3
|
import { DATA_DIR } from "../../lib/dataDir.js";
|
|
4
4
|
import path from "path";
|
|
@@ -90,15 +90,10 @@ export async function POST_handler(req, res) {
|
|
|
90
90
|
// state differs between machines. Keep raw-file restore below for old backups.
|
|
91
91
|
const hasLogical = !!body.database;
|
|
92
92
|
if (hasLogical) {
|
|
93
|
-
progress(15, "
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
db0.close();
|
|
98
|
-
}
|
|
99
|
-
catch { /* ignore */ }
|
|
100
|
-
}
|
|
101
|
-
progress(25, "Mengimpor data logical (provider, connections, proxy, api keys, combos)...");
|
|
93
|
+
progress(15, "Mengimpor data logical (provider, connections, proxy, api keys, combos)...");
|
|
94
|
+
// Import on the live connection — do NOT close it first, or getAdapter()
|
|
95
|
+
// would keep returning the stale closed instance and every query throws
|
|
96
|
+
// "The database connection is not open".
|
|
102
97
|
await importDb(body.database);
|
|
103
98
|
progress(40, "Flush WAL ke file database utama (checkpoint)...");
|
|
104
99
|
const db = await getAdapter();
|
|
@@ -126,6 +121,8 @@ export async function POST_handler(req, res) {
|
|
|
126
121
|
}
|
|
127
122
|
catch { /* ignore */ }
|
|
128
123
|
}
|
|
124
|
+
// Reset cached instance so the next getAdapter() re-opens a fresh connection.
|
|
125
|
+
resetAdapter();
|
|
129
126
|
}
|
|
130
127
|
// 2. Remove active -wal and -shm files to prevent corruption/mismatch.
|
|
131
128
|
progress(50, "Membersihkan file WAL/SHM lock...");
|