Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(server): t3 doctor reclaims database space #19436

Mergedjuliusmarmingemerged 3 commits intot3/db-compaction-1-background fromrefs/pull/19436/headmerged by juliusmarminge View on GitHub

Showing 11 changed files with 174 additions and 0 deletions (loading 8).

x
0 of 11 viewed, 11 left
52 additions and 0 deletionsapps/server/src/cli/doctor.test.tsAdded
View file
@@ -0,0 +1,52 @@
+import * as NodeServices from "@effect/platform-node/NodeServices";
+import { assert, it } from "@effect/vitest";
+import * as Effect from "effect/Effect";
+import * as Layer from "effect/Layer";
+​
+import * as BootService from "../cloud/bootService.ts";
+import { runDoctor } from "./doctor.ts";
+import { DatabaseMaintenance } from "../persistence/DatabaseMaintenance.ts";
+​
+it.effect("--fix reclaims space with the service paused, and --dry-run changes nothing", () =>
+ Effect.gen(function* () {
+ const calls: string[] = [];
+ const doctor = (dryRun: boolean) =>
+ runDoctor("/test/statev2.sqlite", { fix: true, dryRun, interactive: false }).pipe(
+ Effect.provide(
+ Layer.mergeAll(
+ NodeServices.layer,
+ Layer.mock(BootService.BootService)({
+ withStopped: (operation) =>
+ Effect.sync(() => calls.push("pause")).pipe(
+ Effect.andThen(operation),
+ Effect.ensuring(Effect.sync(() => calls.push("resume"))),
+ ),
+ }),
+ Layer.succeed(DatabaseMaintenance, {
+ // An unconverted database: reclaiming space is recommended.
+ inspect: () =>
+ Effect.succeed({
+ databaseBytes: 2000,
+ reclaimableBytes: 1000,