@fudrouter/fsrouter 0.6.100 → 0.6.102
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 +25 -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,8 @@ 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
|
-
if (db0 && typeof db0.close === "function") {
|
|
96
|
-
try {
|
|
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.
|
|
102
95
|
await importDb(body.database);
|
|
103
96
|
progress(40, "Flush WAL ke file database utama (checkpoint)...");
|
|
104
97
|
const db = await getAdapter();
|
|
@@ -116,6 +109,26 @@ export async function POST_handler(req, res) {
|
|
|
116
109
|
}
|
|
117
110
|
catch { /* ignore */ }
|
|
118
111
|
}
|
|
112
|
+
progress(50, "Menutup koneksi DB agar file WAL/SHM tidak terkunci...");
|
|
113
|
+
// Switch journal mode to DELETE so SQLite folds the WAL back into the
|
|
114
|
+
// main db file and deletes -wal/-shm itself — avoids leaving a locked
|
|
115
|
+
// WAL that Windows can't unlink (which previously dropped restored rows).
|
|
116
|
+
if (db && typeof db.exec === "function") {
|
|
117
|
+
try {
|
|
118
|
+
db.exec("PRAGMA journal_mode=DELETE");
|
|
119
|
+
}
|
|
120
|
+
catch { /* ignore */ }
|
|
121
|
+
}
|
|
122
|
+
// Close the connection so Windows releases the -wal/-shm file locks.
|
|
123
|
+
// Logical data is already flushed to the main DB via the checkpoint above.
|
|
124
|
+
if (db && typeof db.close === "function") {
|
|
125
|
+
try {
|
|
126
|
+
db.close();
|
|
127
|
+
}
|
|
128
|
+
catch { /* ignore */ }
|
|
129
|
+
}
|
|
130
|
+
// Clear the cached instance so getAdapter() re-opens fresh on next boot.
|
|
131
|
+
resetAdapter();
|
|
119
132
|
}
|
|
120
133
|
else {
|
|
121
134
|
progress(15, "Menutup koneksi database aktif (raw restore)...");
|
|
@@ -126,6 +139,8 @@ export async function POST_handler(req, res) {
|
|
|
126
139
|
}
|
|
127
140
|
catch { /* ignore */ }
|
|
128
141
|
}
|
|
142
|
+
// Reset cached instance so the next getAdapter() re-opens a fresh connection.
|
|
143
|
+
resetAdapter();
|
|
129
144
|
}
|
|
130
145
|
// 2. Remove active -wal and -shm files to prevent corruption/mismatch.
|
|
131
146
|
progress(50, "Membersihkan file WAL/SHM lock...");
|