@sdods/db 0.14.0 → 0.15.0
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/.tsbuildinfo +1 -1
- package/dist/driver.d.ts +2 -0
- package/dist/driver.js +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/migrations/0012_platform_settings.d.ts +10 -0
- package/dist/migrations/0012_platform_settings.js +16 -0
- package/dist/migrations/index.js +2 -0
- package/dist/repos/index.d.ts +2 -0
- package/dist/repos/index.js +2 -0
- package/dist/repos/retention.d.ts +49 -0
- package/dist/repos/retention.js +134 -0
- package/dist/repos/settings.d.ts +18 -0
- package/dist/repos/settings.js +43 -0
- package/dist/schema.d.ts +8 -0
- package/dist/schema.js +1 -0
- package/dist/storage.d.ts +23 -0
- package/dist/storage.js +76 -0
- package/dist/switch/backup.d.ts +42 -0
- package/dist/switch/backup.js +97 -0
- package/dist/switch/index.d.ts +1 -0
- package/dist/switch/index.js +1 -0
- package/dist/switch/prune.d.ts +15 -1
- package/dist/switch/prune.js +18 -21
- package/package.json +2 -2
package/dist/switch/prune.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { existsSync, rmSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
1
|
import { sql } from 'kysely';
|
|
4
|
-
import {
|
|
5
|
-
/**
|
|
2
|
+
import { deleteRuns } from '../repos/retention.js';
|
|
3
|
+
/**
|
|
4
|
+
* Delete old runs (and their artifact directories) beyond `keepRuns` per project or older than
|
|
5
|
+
* `keepDays`. Live runs are never deleted. Goes through {@link deleteRuns}, so it is
|
|
6
|
+
* transactional, audited and clears references to the deleted runs.
|
|
7
|
+
*/
|
|
6
8
|
export async function prune(adb, opts) {
|
|
7
9
|
const { db } = adb;
|
|
8
10
|
let q = db
|
|
@@ -12,8 +14,7 @@ export async function prune(adb, opts) {
|
|
|
12
14
|
'runs.id as id',
|
|
13
15
|
'projects.slug as slug',
|
|
14
16
|
'runs.created_at as created_at',
|
|
15
|
-
'runs.
|
|
16
|
-
'runs.artifacts_dir as artifacts_dir',
|
|
17
|
+
'runs.status as status',
|
|
17
18
|
])
|
|
18
19
|
.orderBy(sql `coalesce(runs.started_at, runs.created_at)`, 'desc');
|
|
19
20
|
if (opts.projectSlug)
|
|
@@ -28,23 +29,19 @@ export async function prune(adb, opts) {
|
|
|
28
29
|
const tooMany = opts.keepRuns !== undefined && n > opts.keepRuns;
|
|
29
30
|
const tooOld = cutoff !== null && new Date(String(r.created_at)).getTime() < cutoff;
|
|
30
31
|
if (tooMany || tooOld)
|
|
31
|
-
victims.push(r);
|
|
32
|
-
}
|
|
33
|
-
if (!opts.dryRun) {
|
|
34
|
-
for (const v of victims) {
|
|
35
|
-
await deleteRun(db, v.id);
|
|
36
|
-
const dir = v.artifacts_dir ?? (opts.artifactsRoot ? join(opts.artifactsRoot, v.id) : null);
|
|
37
|
-
if (dir && existsSync(dir))
|
|
38
|
-
rmSync(dir, { recursive: true, force: true });
|
|
39
|
-
}
|
|
32
|
+
victims.push(r.id);
|
|
40
33
|
}
|
|
34
|
+
const res = await deleteRuns(adb, victims, {
|
|
35
|
+
artifactsRoot: opts.artifactsRoot,
|
|
36
|
+
dryRun: opts.dryRun,
|
|
37
|
+
reason: opts.reason ?? 'prune',
|
|
38
|
+
actor: opts.actor,
|
|
39
|
+
});
|
|
41
40
|
return {
|
|
42
|
-
deleted:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})),
|
|
47
|
-
kept: rows.length - victims.length,
|
|
41
|
+
deleted: res.deleted.map(({ id, projectSlug, createdAt }) => ({ id, projectSlug, createdAt })),
|
|
42
|
+
kept: rows.length - res.deleted.length,
|
|
43
|
+
skipped: res.skipped,
|
|
44
|
+
freedBytes: res.freedBytes,
|
|
48
45
|
};
|
|
49
46
|
}
|
|
50
47
|
//# sourceMappingURL=prune.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdods/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "SDODS platform database: one schema on SQLite or Postgres, migrations, result ingest and insights.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"funding": "https://sdods.com/sponsor/",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"node": ">=22"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sdods/contracts": "0.
|
|
28
|
+
"@sdods/contracts": "0.15.0",
|
|
29
29
|
"better-sqlite3": "^13.0.3",
|
|
30
30
|
"kysely": "^0.29.6",
|
|
31
31
|
"pg": "^8.23.1",
|