Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): migrated databases can return freed space to disk #30066

Mergedadvaitpaliwal(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/30066/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 31 additions and 12 deletions.

x
0 of 2 viewed, 2 left
3 additions and 1 deletionapps/server/src/persistence/initializeV2Database.test.tsModified
View file
@@ -132,7 +132,7 @@
const source = new NodeSqlite.DatabaseSync(sourcePath);
try {
source.exec(
- "PRAGMA journal_mode=WAL; CREATE TABLE messages(text TEXT); INSERT INTO messages VALUES ('committed'); BEGIN; INSERT INTO messages VALUES ('uncommitted');",
+ "PRAGMA journal_mode=WAL; CREATE TABLE messages(text TEXT); INSERT INTO messages VALUES ('committed'); CREATE TABLE dropped(blob BLOB); INSERT INTO dropped VALUES (randomblob(65536)); DROP TABLE dropped; BEGIN; INSERT INTO messages VALUES ('uncommitted');",
yield* initializeV2Database(destinationPath);
const copy = new NodeSqlite.DatabaseSync(destinationPath, { readOnly: true });
@@ -144,6 +144,8 @@
.map((row) => row.text),
["committed"],
+ assert.deepEqual(copy.prepare("PRAGMA auto_vacuum").get(), { auto_vacuum: 2 });
+ assert.deepEqual(copy.prepare("PRAGMA freelist_count").get(), { freelist_count: 0 });
} finally {
copy.close();
28 additions and 11 deletionsapps/server/src/persistence/initializeV2Database.tsModified
View file
@@ -1,4 +1,4 @@
-import * as NodeSqlite from "node:sqlite";
+import * as NodeWorkerThreads from "node:worker_threads";
​
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
@@ -26,6 +26,20 @@