@crombolo/data 0.14.4 → 0.16.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
31
|
+
"@crombolo/core": "0.16.0"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -77,6 +77,7 @@ export * from './schema/site-search.ts'
|
|
|
77
77
|
export * from './schema/transfer-answers.ts'
|
|
78
78
|
export * from './schema/transfer-run-package.ts'
|
|
79
79
|
export * from './schema/transfer-runs.ts'
|
|
80
|
+
export * from './schema/trashed-date.ts'
|
|
80
81
|
export * from './schema/two-factor.ts'
|
|
81
82
|
export * from './schema/upgrade-report.ts'
|
|
82
83
|
export * from './schema/users-localisation.ts'
|
|
@@ -1071,10 +1071,14 @@ export class DocumentRepository {
|
|
|
1071
1071
|
).map((row) => Number(row.id))
|
|
1072
1072
|
const t = tx.dialect.boolValue(true)
|
|
1073
1073
|
const f = tx.dialect.boolValue(false)
|
|
1074
|
-
await tx.exec(
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1074
|
+
await tx.exec(
|
|
1075
|
+
'UPDATE document SET original_parent_id = ?, trashed_date = ? WHERE node_id = ?',
|
|
1076
|
+
[
|
|
1077
|
+
node.parentId === SystemNodes.Root ? null : node.parentId,
|
|
1078
|
+
DbDate.toDb(new Date()),
|
|
1079
|
+
node.id,
|
|
1080
|
+
],
|
|
1081
|
+
)
|
|
1078
1082
|
// The whole branch goes with it, and stays unpublished while trashed.
|
|
1079
1083
|
await tx.exec('UPDATE node SET trashed = ? WHERE id = ? OR path LIKE ?', [
|
|
1080
1084
|
t,
|
|
@@ -1162,9 +1166,10 @@ export class DocumentRepository {
|
|
|
1162
1166
|
node.id,
|
|
1163
1167
|
`${node.path},%`,
|
|
1164
1168
|
])
|
|
1165
|
-
await tx.exec(
|
|
1166
|
-
|
|
1167
|
-
|
|
1169
|
+
await tx.exec(
|
|
1170
|
+
'UPDATE document SET original_parent_id = NULL, trashed_date = NULL WHERE node_id = ?',
|
|
1171
|
+
[node.id],
|
|
1172
|
+
)
|
|
1168
1173
|
}
|
|
1169
1174
|
await repo.nodes.move(node.id, parentId)
|
|
1170
1175
|
await tx.exec('UPDATE node SET sort_order = ? WHERE id = ?', [
|
|
@@ -1313,7 +1318,10 @@ export class DocumentRepository {
|
|
|
1313
1318
|
await repo.#nextSortOrder(parentId, node.id),
|
|
1314
1319
|
node.id,
|
|
1315
1320
|
])
|
|
1316
|
-
await tx.exec(
|
|
1321
|
+
await tx.exec(
|
|
1322
|
+
'UPDATE document SET original_parent_id = NULL, trashed_date = NULL WHERE node_id = ?',
|
|
1323
|
+
[node.id],
|
|
1324
|
+
)
|
|
1317
1325
|
return 'restored' as const
|
|
1318
1326
|
}),
|
|
1319
1327
|
)
|
|
@@ -1643,6 +1651,21 @@ export class DocumentRepository {
|
|
|
1643
1651
|
return (await this.trashed(null, 0, Number.MAX_SAFE_INTEGER)).items
|
|
1644
1652
|
}
|
|
1645
1653
|
|
|
1654
|
+
/** When each item went into the recycle bin; absent for one trashed before that was recorded. */
|
|
1655
|
+
async trashedDates(nodeIds: readonly number[]): Promise<Map<number, Date>> {
|
|
1656
|
+
if (nodeIds.length === 0) return new Map()
|
|
1657
|
+
const rows = await this.#db.query<{ node_id: number; trashed_date: unknown }>(
|
|
1658
|
+
`SELECT node_id, trashed_date FROM document WHERE trashed_date IS NOT NULL AND node_id IN (${nodeIds.map(() => '?').join(', ')})`,
|
|
1659
|
+
[...nodeIds],
|
|
1660
|
+
)
|
|
1661
|
+
const out = new Map<number, Date>()
|
|
1662
|
+
for (const row of rows) {
|
|
1663
|
+
const date = DbDate.fromDb(row.trashed_date)
|
|
1664
|
+
if (date) out.set(Number(row.node_id), date)
|
|
1665
|
+
}
|
|
1666
|
+
return out
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1646
1669
|
async #nextSortOrder(parentId: number, excludingId: number): Promise<number> {
|
|
1647
1670
|
const rows = await this.#db.query<{ next: number | null }>(
|
|
1648
1671
|
'SELECT MAX(sort_order) AS next FROM node WHERE parent_id = ? AND node_object_type = ? AND id <> ?',
|
|
@@ -138,14 +138,19 @@ export class TransferRunRepository {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/** Runs, newest first. */
|
|
141
|
-
async recent(limit = 20): Promise<TransferRun[]> {
|
|
141
|
+
async recent(limit = 20, offset = 0): Promise<TransferRun[]> {
|
|
142
142
|
const rows = await this.#db.query(
|
|
143
|
-
'SELECT * FROM content_transfer_run ORDER BY started_at DESC, id DESC LIMIT ?',
|
|
144
|
-
[limit],
|
|
143
|
+
'SELECT * FROM content_transfer_run ORDER BY started_at DESC, id DESC LIMIT ? OFFSET ?',
|
|
144
|
+
[limit, offset],
|
|
145
145
|
)
|
|
146
146
|
return rows.map(mapRun)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
async count(): Promise<number> {
|
|
150
|
+
const rows = await this.#db.query('SELECT COUNT(*) AS n FROM content_transfer_run')
|
|
151
|
+
return Number(rows[0]?.n ?? 0)
|
|
152
|
+
}
|
|
153
|
+
|
|
149
154
|
async changes(runId: string): Promise<TransferChange[]> {
|
|
150
155
|
const rows = await this.#db.query(
|
|
151
156
|
'SELECT * FROM content_transfer_change WHERE run_id = ? ORDER BY id',
|
package/src/schema/plan.ts
CHANGED
|
@@ -49,6 +49,7 @@ import { siteSearchMigration } from './site-search.ts'
|
|
|
49
49
|
import { transferAnswersMigration } from './transfer-answers.ts'
|
|
50
50
|
import { transferRunPackageMigration } from './transfer-run-package.ts'
|
|
51
51
|
import { transferRunsMigration } from './transfer-runs.ts'
|
|
52
|
+
import { trashedDateMigration } from './trashed-date.ts'
|
|
52
53
|
import { twoFactorMigration } from './two-factor.ts'
|
|
53
54
|
import { upgradeReportMigration } from './upgrade-report.ts'
|
|
54
55
|
import { usersLocalisationMigration } from './users-localisation.ts'
|
|
@@ -97,4 +98,5 @@ export const cromboloPlan = new MigrationPlan([
|
|
|
97
98
|
siteSearchMigration,
|
|
98
99
|
twoFactorMigration,
|
|
99
100
|
remoteMigration,
|
|
101
|
+
trashedDateMigration,
|
|
100
102
|
])
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 042 — `document.trashed_date`: when an item went into the recycle
|
|
3
|
+
* bin, so `crombolo recycle-bin empty --older-than` can leave what was trashed
|
|
4
|
+
* recently (story 152). Items trashed before this migration have none, and are
|
|
5
|
+
* treated as of unknown age.
|
|
6
|
+
*/
|
|
7
|
+
import type { Db } from '../database.ts'
|
|
8
|
+
import type { Migration } from '../migrations.ts'
|
|
9
|
+
import { schemaOps } from '../schema-ops.ts'
|
|
10
|
+
import { STATE_REMOTE } from './remote.ts'
|
|
11
|
+
|
|
12
|
+
export const STATE_TRASHED_DATE = '{8d3f1a62-0042-4b7e-9c15-2e6a4f0b8d43}'
|
|
13
|
+
|
|
14
|
+
export const trashedDateMigration: Migration = {
|
|
15
|
+
from: STATE_REMOTE,
|
|
16
|
+
to: STATE_TRASHED_DATE,
|
|
17
|
+
name: 'AddTrashedDate',
|
|
18
|
+
kind: 'expand',
|
|
19
|
+
release: '0.16.0',
|
|
20
|
+
async up(db: Db) {
|
|
21
|
+
await schemaOps(db).addColumn('document', 'trashed_date', db.dialect.types.timestamp)
|
|
22
|
+
},
|
|
23
|
+
}
|