@crombolo/data 0.72.0 → 0.73.2

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.72.0",
3
+ "version": "0.73.2",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@crombolo/core": "0.72.0",
32
+ "@crombolo/core": "0.73.2",
33
33
  "kysely": "0.29.6"
34
34
  }
35
35
  }
package/src/index.ts CHANGED
@@ -51,6 +51,7 @@ export * from './repositories/redirects.ts'
51
51
  export * from './repositories/references.ts'
52
52
  export * from './repositories/remote-jobs.ts'
53
53
  export * from './repositories/remote-trust.ts'
54
+ export * from './repositories/served-changes.ts'
54
55
  export * from './repositories/single-use-tokens.ts'
55
56
  export * from './repositories/tags.ts'
56
57
  export * from './repositories/templates.ts'
@@ -63,6 +64,7 @@ export * from './repositories/users.ts'
63
64
  export * from './repositories/webhooks.ts'
64
65
  export * from './repositories/workspace-files.ts'
65
66
  export * from './repositories/workspace-links.ts'
67
+ export * from './repositories/workspace-processes.ts'
66
68
  export * from './repositories/workspaces.ts'
67
69
  export * from './schema/approval-schedules.ts'
68
70
  export * from './schema/approvals.ts'
@@ -131,6 +133,7 @@ export * from './schema/rich-text-ui.ts'
131
133
  export * from './schema/search-index.ts'
132
134
  export * from './schema/search-removals.ts'
133
135
  export * from './schema/seed.ts'
136
+ export * from './schema/served-changes.ts'
134
137
  export * from './schema/session-view-as.ts'
135
138
  export * from './schema/since-version.ts'
136
139
  export * from './schema/single-use-token.ts'
@@ -152,6 +155,7 @@ export * from './schema/webhooks.ts'
152
155
  export * from './schema/workspace-links.ts'
153
156
  export * from './schema/workspace-merge.ts'
154
157
  export * from './schema/workspace-privacy.ts'
158
+ export * from './schema/workspace-processes.ts'
155
159
  export * from './schema/workspace-schema.ts'
156
160
  export * from './schema/workspaces.ts'
157
161
  export * from './schema-ops.ts'
@@ -18,6 +18,9 @@ export type ChangeSource = 'bundle' | 'replace' | 'merge' | 'edit' | 'revert'
18
18
  /** How long a person's direct edits keep gathering in one change. */
19
19
  export const EDIT_WINDOW_MS = 10 * 60 * 1000
20
20
 
21
+ /** Where a change keeps a page's schedule among its items (story 395): `schedules/<page key>`. */
22
+ export const SCHEDULE_PREFIX = 'schedules/'
23
+
21
24
  export interface Change {
22
25
  id: string
23
26
  kind: ChangeSource
@@ -219,6 +222,36 @@ export class ChangeRepository {
219
222
  await this.#touch(id, now)
220
223
  }
221
224
 
225
+ /**
226
+ * A page's schedule a person set or cleared straight in Shared (story 395): in their
227
+ * open change with the page, kept as an item of its own, as the change carries it.
228
+ */
229
+ async scheduleOf(
230
+ madeBy: string,
231
+ page: { key: string; kind: string },
232
+ entries: readonly unknown[],
233
+ now = new Date(),
234
+ ): Promise<void> {
235
+ const id = await this.#openEdit(madeBy, now)
236
+ if (!(await this.#recordPage(id, page))) return
237
+ const path = `${SCHEDULE_PREFIX}${normaliseUuid(page.key)}`
238
+ const after = JSON.stringify(entries)
239
+ const found = await this.#db.q
240
+ .selectFrom('change_item')
241
+ .select('id')
242
+ .where('run_id', '=', id)
243
+ .where('path', '=', path)
244
+ .execute()
245
+ if (found[0])
246
+ await this.#db.q
247
+ .updateTable('change_item')
248
+ .set({ after_hash: await this.#put(after) })
249
+ .where('id', '=', Number(found[0].id))
250
+ .execute()
251
+ else await this.item(id, { path, kind: 'page', class: 'none', before: null, after })
252
+ await this.#touch(id, now)
253
+ }
254
+
222
255
  /**
223
256
  * A page a person published straight in Shared (story 388): in their open change as
224
257
  * it is now, and the change closed, so it is finished and can be passed on. Their
@@ -0,0 +1,211 @@
1
+ /**
2
+ * What the served copy of a site holds (story 395): each change a host reports
3
+ * applying there, kept as a set, since pages go out at once and a release later.
4
+ * And the history of the site's schema and code files, change by change, that
5
+ * says what of it the served copy has.
6
+ */
7
+ import { normaliseUuid } from '@crombolo/core'
8
+ import type { Db } from '../database.ts'
9
+ import { DbDate } from '../dialect.ts'
10
+
11
+ /** One version of a file, as a change left it. */
12
+ export interface FileVersion {
13
+ path: string
14
+ changeKey: string
15
+ changeName: string | null
16
+ startedAt: Date
17
+ /** Whether the change made the file, rather than changed or removed it. */
18
+ made: boolean
19
+ removed: boolean
20
+ afterHash: string | null
21
+ }
22
+
23
+ export class ServedChangeRepository {
24
+ #db: Db
25
+
26
+ constructor(db: Db) {
27
+ this.#db = db
28
+ }
29
+
30
+ /** Records that the served copy holds a change; reporting it again changes nothing. */
31
+ async report(key: string, by: string | null, now = new Date()): Promise<void> {
32
+ const changeKey = normaliseUuid(key)
33
+ const found = await this.#db.q
34
+ .selectFrom('served_change')
35
+ .select('change_key')
36
+ .where('change_key', '=', changeKey)
37
+ .execute()
38
+ if (found.length > 0) return
39
+ await this.#db.q
40
+ .insertInto('served_change')
41
+ .values({ change_key: changeKey, reported_by: by, reported_at: DbDate.toDb(now) })
42
+ .execute()
43
+ }
44
+
45
+ async keys(): Promise<Set<string>> {
46
+ const rows = await this.#db.q.selectFrom('served_change').select('change_key').execute()
47
+ return new Set(rows.map((r) => String(r.change_key)))
48
+ }
49
+
50
+ /** The newest change reported, by when it was made here. */
51
+ async newest(): Promise<{ key: string; name: string | null; reportedAt: Date } | undefined> {
52
+ const row = await this.#db.q
53
+ .selectFrom('served_change as s')
54
+ .innerJoin('content_transfer_run as r', 'r.change_key', 's.change_key')
55
+ .select(['s.change_key', 'r.name', 'r.bundle_label', 's.reported_at'])
56
+ .orderBy('r.started_at', 'desc')
57
+ .limit(1)
58
+ .executeTakeFirst()
59
+ if (!row) return undefined
60
+ return {
61
+ key: String(row.change_key),
62
+ name: (row.name as string | null) ?? (row.bundle_label as string | null) ?? null,
63
+ reportedAt: DbDate.fromDb(row.reported_at) ?? new Date(0),
64
+ }
65
+ }
66
+
67
+ /** When the oldest reported change was made here: what came before it, the served copy had. */
68
+ async since(): Promise<Date | undefined> {
69
+ const row = await this.#db.q
70
+ .selectFrom('served_change as s')
71
+ .innerJoin('content_transfer_run as r', 'r.change_key', 's.change_key')
72
+ .select('r.started_at')
73
+ .orderBy('r.started_at')
74
+ .limit(1)
75
+ .executeTakeFirst()
76
+ return row ? (DbDate.fromDb(row.started_at) ?? undefined) : undefined
77
+ }
78
+
79
+ /** A fingerprint that moves whenever a report or a file's change is recorded. */
80
+ async revision(): Promise<string> {
81
+ const [reports] = await this.#db.q
82
+ .selectFrom('served_change')
83
+ .select((eb) => eb.fn.countAll<number>().as('n'))
84
+ .execute()
85
+ const [items] = await this.#db.q
86
+ .selectFrom('change_item')
87
+ .select((eb) => [eb.fn.max('id').as('top'), eb.fn.countAll<number>().as('n')])
88
+ .execute()
89
+ return `${reports?.n ?? 0}:${items?.top ?? 0}:${items?.n ?? 0}`
90
+ }
91
+
92
+ /** Every version of the files under these prefixes, oldest first. */
93
+ async fileVersions(prefixes: readonly string[]): Promise<FileVersion[]> {
94
+ if (prefixes.length === 0) return []
95
+ const rows = await this.#db.q
96
+ .selectFrom('change_item as i')
97
+ .innerJoin('content_transfer_run as r', 'r.id', 'i.run_id')
98
+ .select([
99
+ 'i.path',
100
+ 'i.before_hash',
101
+ 'i.after_hash',
102
+ 'r.change_key',
103
+ 'r.bundle_id',
104
+ 'r.name',
105
+ 'r.bundle_label',
106
+ 'r.started_at',
107
+ ])
108
+ .where((eb) => eb.or(prefixes.map((p) => eb('i.path', 'like', `${p}%`))))
109
+ .where('r.status', '=', 'applied')
110
+ .orderBy('r.started_at')
111
+ .orderBy('i.id')
112
+ .execute()
113
+ return rows.map((r) => ({
114
+ path: String(r.path),
115
+ changeKey: String(r.change_key ?? r.bundle_id),
116
+ changeName: (r.name as string | null) ?? (r.bundle_label as string | null) ?? null,
117
+ startedAt: DbDate.fromDb(r.started_at) ?? new Date(0),
118
+ made: r.before_hash === null,
119
+ removed: r.after_hash === null,
120
+ afterHash: (r.after_hash as string | null) ?? null,
121
+ }))
122
+ }
123
+
124
+ /** The texts of files by their hashes. */
125
+ async texts(hashes: readonly string[]): Promise<Map<string, string>> {
126
+ const wanted = [...new Set(hashes)]
127
+ if (wanted.length === 0) return new Map()
128
+ const rows = await this.#db.q
129
+ .selectFrom('file_blob')
130
+ .select(['hash', 'text'])
131
+ .where('hash', 'in', wanted)
132
+ .execute()
133
+ return new Map(rows.map((r) => [String(r.hash), String(r.text)]))
134
+ }
135
+ }
136
+
137
+ /** A notice a host left for someone in the back office (story 395). */
138
+ export interface BackofficeNotice {
139
+ id: number
140
+ kind: 'success' | 'failure'
141
+ message: string
142
+ link: string | null
143
+ createdAt: Date
144
+ }
145
+
146
+ /** How long a notice waits to be seen. */
147
+ export const NOTICE_KEPT_MS = 30 * 24 * 3600_000
148
+
149
+ export class BackofficeNoticeRepository {
150
+ #db: Db
151
+
152
+ constructor(db: Db) {
153
+ this.#db = db
154
+ }
155
+
156
+ async add(notice: {
157
+ userKey: string
158
+ kind: 'success' | 'failure'
159
+ message: string
160
+ link: string | null
161
+ now?: Date
162
+ }): Promise<number> {
163
+ const row = await this.#db.q
164
+ .insertInto('backoffice_notice')
165
+ .values({
166
+ user_key: normaliseUuid(notice.userKey),
167
+ kind: notice.kind,
168
+ message: notice.message,
169
+ link: notice.link,
170
+ created_at: DbDate.toDb(notice.now ?? new Date()),
171
+ })
172
+ .returning('id')
173
+ .executeTakeFirstOrThrow()
174
+ return Number(row.id)
175
+ }
176
+
177
+ /** The person's notices not yet seen, oldest first, marked seen as they are taken. */
178
+ async take(userKey: string, now = new Date()): Promise<BackofficeNotice[]> {
179
+ const user = normaliseUuid(userKey)
180
+ const cutoff = DbDate.toDb(new Date(now.getTime() - NOTICE_KEPT_MS))
181
+ await this.#db.q
182
+ .deleteFrom('backoffice_notice')
183
+ .where('seen_at', 'is', null)
184
+ .where('created_at', '<', cutoff)
185
+ .execute()
186
+ const rows = await this.#db.q
187
+ .selectFrom('backoffice_notice')
188
+ .select(['id', 'kind', 'message', 'link', 'created_at'])
189
+ .where('user_key', '=', user)
190
+ .where('seen_at', 'is', null)
191
+ .orderBy('id')
192
+ .execute()
193
+ if (rows.length === 0) return []
194
+ await this.#db.q
195
+ .updateTable('backoffice_notice')
196
+ .set({ seen_at: DbDate.toDb(now) })
197
+ .where(
198
+ 'id',
199
+ 'in',
200
+ rows.map((r) => Number(r.id)),
201
+ )
202
+ .execute()
203
+ return rows.map((r) => ({
204
+ id: Number(r.id),
205
+ kind: r.kind === 'failure' ? 'failure' : 'success',
206
+ message: String(r.message),
207
+ link: (r.link as string | null) ?? null,
208
+ createdAt: DbDate.fromDb(r.created_at) ?? now,
209
+ }))
210
+ }
211
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The processes workspaces render in, as each node reports them (story 396): which
3
+ * run on which node, and each failure, kept for an hour, so any node can answer for
4
+ * the whole site.
5
+ */
6
+ import { normaliseUuid } from '@crombolo/core'
7
+ import type { Db } from '../database.ts'
8
+ import { DbDate } from '../dialect.ts'
9
+
10
+ /** How far back failures are counted. */
11
+ export const PROCESS_FAILURE_WINDOW_MS = 3600_000
12
+
13
+ /** One workspace's processes and failures, across the nodes. */
14
+ export interface WorkspaceProcessReport {
15
+ key: string
16
+ /** The live nodes running a process for it. */
17
+ nodes: string[]
18
+ failures: number
19
+ lastError: string | null
20
+ /** When its first counted failure happened, or when its oldest process started. */
21
+ since: Date
22
+ }
23
+
24
+ export class WorkspaceProcessRepository {
25
+ #db: Db
26
+
27
+ constructor(db: Db) {
28
+ this.#db = db
29
+ }
30
+
31
+ async started(nodeId: string, workspaceKey: string, now = new Date()): Promise<void> {
32
+ const key = normaliseUuid(workspaceKey)
33
+ await this.stopped(nodeId, key)
34
+ await this.#db.q
35
+ .insertInto('workspace_process')
36
+ .values({ node_id: nodeId, workspace_key: key, started_at: DbDate.toDb(now) })
37
+ .execute()
38
+ }
39
+
40
+ async stopped(nodeId: string, workspaceKey: string): Promise<void> {
41
+ await this.#db.q
42
+ .deleteFrom('workspace_process')
43
+ .where('node_id', '=', nodeId)
44
+ .where('workspace_key', '=', normaliseUuid(workspaceKey))
45
+ .execute()
46
+ }
47
+
48
+ /** Forgets what a node said it ran: it starts with none. */
49
+ async nodeStarted(nodeId: string): Promise<void> {
50
+ await this.#db.q.deleteFrom('workspace_process').where('node_id', '=', nodeId).execute()
51
+ }
52
+
53
+ async failed(
54
+ nodeId: string,
55
+ workspaceKey: string,
56
+ reason: string,
57
+ now = new Date(),
58
+ ): Promise<void> {
59
+ await this.#db.q
60
+ .deleteFrom('workspace_process_failure')
61
+ .where('failed_at', '<', DbDate.toDb(new Date(now.getTime() - PROCESS_FAILURE_WINDOW_MS)))
62
+ .execute()
63
+ await this.#db.q
64
+ .insertInto('workspace_process_failure')
65
+ .values({
66
+ node_id: nodeId,
67
+ workspace_key: normaliseUuid(workspaceKey),
68
+ reason: reason.slice(0, 1000),
69
+ failed_at: DbDate.toDb(now),
70
+ })
71
+ .execute()
72
+ }
73
+
74
+ /**
75
+ * Each workspace with a process on a node seen within `seenWithinMs`, or a failure
76
+ * in the last hour, whichever node it was on.
77
+ */
78
+ async report(options: { seenWithinMs: number; now?: Date }): Promise<WorkspaceProcessReport[]> {
79
+ const now = options.now ?? new Date()
80
+ const running = await this.#db.q
81
+ .selectFrom('workspace_process as p')
82
+ .innerJoin('server as s', 's.node_id', 'p.node_id')
83
+ .select(['p.workspace_key', 'p.node_id', 'p.started_at'])
84
+ .where('s.last_seen', '>=', DbDate.toDb(new Date(now.getTime() - options.seenWithinMs)))
85
+ .execute()
86
+ const failures = await this.#db.q
87
+ .selectFrom('workspace_process_failure')
88
+ .select(['workspace_key', 'reason', 'failed_at'])
89
+ .where('failed_at', '>=', DbDate.toDb(new Date(now.getTime() - PROCESS_FAILURE_WINDOW_MS)))
90
+ .orderBy('failed_at')
91
+ .orderBy('id')
92
+ .execute()
93
+ const out = new Map<string, WorkspaceProcessReport>()
94
+ const entry = (key: string, at: Date) => {
95
+ const found = out.get(key)
96
+ if (found) {
97
+ if (at < found.since) found.since = at
98
+ return found
99
+ }
100
+ const made: WorkspaceProcessReport = {
101
+ key,
102
+ nodes: [],
103
+ failures: 0,
104
+ lastError: null,
105
+ since: at,
106
+ }
107
+ out.set(key, made)
108
+ return made
109
+ }
110
+ for (const row of running) {
111
+ const report = entry(String(row.workspace_key), DbDate.fromDb(row.started_at) ?? now)
112
+ report.nodes.push(String(row.node_id))
113
+ }
114
+ for (const row of failures) {
115
+ const report = entry(String(row.workspace_key), DbDate.fromDb(row.failed_at) ?? now)
116
+ report.failures += 1
117
+ report.lastError = String(row.reason)
118
+ }
119
+ for (const report of out.values()) report.nodes.sort()
120
+ return [...out.values()]
121
+ }
122
+
123
+ /** How many workspaces failed `atLeast` times in the last hour. */
124
+ async failing(atLeast: number, now = new Date()): Promise<number> {
125
+ const rows = await this.#db.q
126
+ .selectFrom('workspace_process_failure')
127
+ .select(['workspace_key', (eb) => eb.fn.countAll<number>().as('n')])
128
+ .where('failed_at', '>=', DbDate.toDb(new Date(now.getTime() - PROCESS_FAILURE_WINDOW_MS)))
129
+ .groupBy('workspace_key')
130
+ .execute()
131
+ return rows.filter((r) => Number(r.n) >= atLeast).length
132
+ }
133
+ }
@@ -10,6 +10,21 @@ import { Locks } from '../locks.ts'
10
10
  import { type ContentKind, deleteNodeRows } from './documents.ts'
11
11
  import { WorkspaceFileRepository } from './workspace-files.ts'
12
12
 
13
+ /** A change staged in a workspace (story 383), with the schedules its merge sets (story 395). */
14
+ export interface StagedChange {
15
+ key: string
16
+ name: string | null
17
+ schedules?: Array<{
18
+ key: string
19
+ kind: string
20
+ entries: Array<{
21
+ culture: string | null
22
+ publishTime: string | null
23
+ unpublishTime: string | null
24
+ }>
25
+ }>
26
+ }
27
+
13
28
  export interface Workspace {
14
29
  id: number
15
30
  key: string
@@ -25,7 +40,7 @@ export interface Workspace {
25
40
  createdAt: Date
26
41
  updatedAt: Date
27
42
  /** Changes from another site it holds (story 383), which its merge applies. */
28
- stagedChanges: Array<{ key: string; name: string | null }> | null
43
+ stagedChanges: StagedChange[] | null
29
44
  /** Staged to be looked at and applied: nobody edits it. A refused apply's is open to edit. */
30
45
  stagedReadOnly: boolean
31
46
  /** Who can see it (story 384): its members, or everyone who may edit, reading only. */
@@ -301,7 +316,7 @@ export class WorkspaceRepository {
301
316
  /** Marks a workspace as holding changes from another site, read-only or open to edit (story 383). */
302
317
  async setStaged(
303
318
  id: number,
304
- changes: ReadonlyArray<{ key: string; name: string | null }> | null,
319
+ changes: readonly StagedChange[] | null,
305
320
  readOnly = true,
306
321
  ): Promise<void> {
307
322
  await this.#db.q
@@ -79,6 +79,7 @@ import { remoteTrustMigration } from './remote-trust.ts'
79
79
  import { richTextUiMigration } from './rich-text-ui.ts'
80
80
  import { searchIndexMigration } from './search-index.ts'
81
81
  import { searchRemovalsMigration } from './search-removals.ts'
82
+ import { servedChangesMigration } from './served-changes.ts'
82
83
  import { serverRoleMigration } from './server-role.ts'
83
84
  import { sessionViewAsMigration } from './session-view-as.ts'
84
85
  import { sinceVersionMigration } from './since-version.ts'
@@ -101,6 +102,7 @@ import { webhooksMigration } from './webhooks.ts'
101
102
  import { workspaceLinksMigration } from './workspace-links.ts'
102
103
  import { workspaceMergeMigration } from './workspace-merge.ts'
103
104
  import { workspacePrivacyMigration } from './workspace-privacy.ts'
105
+ import { workspaceProcessesMigration } from './workspace-processes.ts'
104
106
  import { workspaceSchemaMigration } from './workspace-schema.ts'
105
107
  import { workspacesMigration } from './workspaces.ts'
106
108
 
@@ -195,4 +197,6 @@ export const cromboloPlan = new MigrationPlan([
195
197
  changeTransferMigration,
196
198
  environmentValuesMigration,
197
199
  workspacePrivacyMigration,
200
+ servedChangesMigration,
201
+ workspaceProcessesMigration,
198
202
  ])
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Migration 091 — what the served copy holds, and notices for a person (story 395):
3
+ * each change a host reports applying to the served copy, and the notices a host
4
+ * leaves for someone, kept until they see them.
5
+ */
6
+ import type { Db } from '../database.ts'
7
+ import type { Migration } from '../migrations.ts'
8
+ import { sql } from '../query.ts'
9
+ import { STATE_WORKSPACE_PRIVACY } from './workspace-privacy.ts'
10
+
11
+ export const STATE_SERVED_CHANGES = '{6c3a9e14-0091-4b2d-8f57-1e9d4a7c0091}'
12
+
13
+ export const servedChangesMigration: Migration = {
14
+ from: STATE_WORKSPACE_PRIVACY,
15
+ to: STATE_SERVED_CHANGES,
16
+ name: 'AddServedChanges',
17
+ kind: 'expand',
18
+ release: '0.73.0',
19
+ async up(db: Db) {
20
+ const t = db.dialect.types
21
+ await db.q.schema
22
+ .createTable('served_change')
23
+ .addColumn('change_key', sql.raw(t.varchar(64)), (c) => c.primaryKey())
24
+ .addColumn('reported_by', sql.raw(t.varchar(255)))
25
+ .addColumn('reported_at', sql.raw(t.timestamp), (c) => c.notNull())
26
+ .execute()
27
+ await db.q.schema
28
+ .createTable('backoffice_notice')
29
+ .addColumn('id', sql.raw(t.identity))
30
+ .addColumn('user_key', sql.raw(t.uuid), (c) => c.notNull())
31
+ .addColumn('kind', sql.raw(t.varchar(16)), (c) => c.notNull())
32
+ .addColumn('message', sql.raw(t.varchar(1000)), (c) => c.notNull())
33
+ .addColumn('link', sql.raw(t.varchar(1000)))
34
+ .addColumn('created_at', sql.raw(t.timestamp), (c) => c.notNull())
35
+ .addColumn('seen_at', sql.raw(t.timestamp))
36
+ .execute()
37
+ await db.q.schema
38
+ .createIndex('ix_backoffice_notice_user')
39
+ .on('backoffice_notice')
40
+ .column('user_key')
41
+ .execute()
42
+ },
43
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Migration 092 — the processes workspaces render in, as each node reports them
3
+ * (story 396): which run where, and each that failed, so any node can say which
4
+ * workspace keeps failing, whichever node it fails on.
5
+ */
6
+ import type { Db } from '../database.ts'
7
+ import type { Migration } from '../migrations.ts'
8
+ import { sql } from '../query.ts'
9
+ import { STATE_SERVED_CHANGES } from './served-changes.ts'
10
+
11
+ export const STATE_WORKSPACE_PROCESSES = '{8d1e4b27-0092-4c6a-a3f8-7b2c9e5d0092}'
12
+
13
+ export const workspaceProcessesMigration: Migration = {
14
+ from: STATE_SERVED_CHANGES,
15
+ to: STATE_WORKSPACE_PROCESSES,
16
+ name: 'AddWorkspaceProcesses',
17
+ kind: 'expand',
18
+ release: '0.73.0',
19
+ async up(db: Db) {
20
+ const t = db.dialect.types
21
+ await db.q.schema
22
+ .createTable('workspace_process')
23
+ .addColumn('node_id', sql.raw(t.varchar(64)), (c) => c.notNull())
24
+ .addColumn('workspace_key', sql.raw(t.varchar(64)), (c) => c.notNull())
25
+ .addColumn('started_at', sql.raw(t.timestamp), (c) => c.notNull())
26
+ .addPrimaryKeyConstraint('pk_workspace_process', ['node_id', 'workspace_key'])
27
+ .execute()
28
+ await db.q.schema
29
+ .createTable('workspace_process_failure')
30
+ .addColumn('id', sql.raw(t.identity))
31
+ .addColumn('node_id', sql.raw(t.varchar(64)), (c) => c.notNull())
32
+ .addColumn('workspace_key', sql.raw(t.varchar(64)), (c) => c.notNull())
33
+ .addColumn('reason', sql.raw(t.varchar(1000)), (c) => c.notNull())
34
+ .addColumn('failed_at', sql.raw(t.timestamp), (c) => c.notNull())
35
+ .execute()
36
+ await db.q.schema
37
+ .createIndex('ix_workspace_process_failure_at')
38
+ .on('workspace_process_failure')
39
+ .column('failed_at')
40
+ .execute()
41
+ },
42
+ }
package/src/tables.gen.ts CHANGED
@@ -98,6 +98,15 @@ export interface CoreTables {
98
98
  token_type: string
99
99
  user_id: number
100
100
  }
101
+ backoffice_notice: {
102
+ created_at: Timestamp
103
+ id: Generated<number>
104
+ kind: string
105
+ link: string | null
106
+ message: string
107
+ seen_at: Timestamp | null
108
+ user_key: string
109
+ }
101
110
  bundle: {
102
111
  components: string
103
112
  content_load_child_nodes: Bool
@@ -786,6 +795,11 @@ export interface CoreTables {
786
795
  node_key: string
787
796
  removed_at: Timestamp
788
797
  }
798
+ served_change: {
799
+ change_key: string
800
+ reported_at: Timestamp
801
+ reported_by: string | null
802
+ }
789
803
  server: {
790
804
  crombolo_version: string | null
791
805
  last_seen: Timestamp
@@ -1076,4 +1090,16 @@ export interface CoreTables {
1076
1090
  user_id: number | null
1077
1091
  workspace_id: number
1078
1092
  }
1093
+ workspace_process: {
1094
+ node_id: string
1095
+ started_at: Timestamp
1096
+ workspace_key: string
1097
+ }
1098
+ workspace_process_failure: {
1099
+ failed_at: Timestamp
1100
+ id: Generated<number>
1101
+ node_id: string
1102
+ reason: string
1103
+ workspace_key: string
1104
+ }
1079
1105
  }