@crombolo/data 0.56.0 → 0.58.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.56.0",
3
+ "version": "0.58.0",
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",
@@ -18,7 +18,8 @@
18
18
  },
19
19
  "type": "module",
20
20
  "exports": {
21
- ".": "./src/index.ts"
21
+ ".": "./src/index.ts",
22
+ "./tables-builder": "./src/custom-tables/builder.ts"
22
23
  },
23
24
  "files": [
24
25
  "src",
@@ -28,7 +29,7 @@
28
29
  "access": "public"
29
30
  },
30
31
  "dependencies": {
31
- "@crombolo/core": "0.56.0",
32
+ "@crombolo/core": "0.58.0",
32
33
  "kysely": "0.29.6"
33
34
  }
34
35
  }
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export * from './repositories/document-listing.ts'
29
29
  export * from './repositories/documents.ts'
30
30
  export * from './repositories/domains.ts'
31
31
  export * from './repositories/dynamic-roots.ts'
32
+ export * from './repositories/extension-settings.ts'
32
33
  export * from './repositories/external-logins.ts'
33
34
  export * from './repositories/folders.ts'
34
35
  export * from './repositories/form-entries.ts'
@@ -50,6 +51,7 @@ export * from './repositories/tags.ts'
50
51
  export * from './repositories/templates.ts'
51
52
  export * from './repositories/transfer-answers.ts'
52
53
  export * from './repositories/transfer-runs.ts'
54
+ export * from './repositories/trusted-signers.ts'
53
55
  export * from './repositories/two-factor.ts'
54
56
  export * from './repositories/user-data.ts'
55
57
  export * from './repositories/users.ts'
@@ -61,7 +63,9 @@ export * from './schema/audit-log.ts'
61
63
  export * from './schema/built-in-content-types.ts'
62
64
  export * from './schema/built-in-media-types.ts'
63
65
  export * from './schema/built-in-member-types.ts'
66
+ export * from './schema/bundle-grant-reach.ts'
64
67
  export * from './schema/bundle-grants.ts'
68
+ export * from './schema/bundle-kind.ts'
65
69
  export * from './schema/bundle-package.ts'
66
70
  export * from './schema/bundle-schema-picks.ts'
67
71
  export * from './schema/bundles-disabled.ts'
@@ -75,11 +79,13 @@ export * from './schema/content-checkpoint.ts'
75
79
  export * from './schema/content-events.ts'
76
80
  export * from './schema/content-notifications.ts'
77
81
  export * from './schema/content-seed.ts'
82
+ export * from './schema/content-type-seo.ts'
78
83
  export * from './schema/created-packages.ts'
79
84
  export * from './schema/delivery-member-tokens.ts'
80
85
  export * from './schema/diagnostics.ts'
81
86
  export * from './schema/drop-assistant.ts'
82
87
  export * from './schema/elements.ts'
88
+ export * from './schema/extension-settings.ts'
83
89
  export * from './schema/form-library.ts'
84
90
  export * from './schema/form-library-types.ts'
85
91
  export * from './schema/form-permission-prefix.ts'
@@ -110,9 +116,11 @@ export * from './schema/since-version.ts'
110
116
  export * from './schema/site-search.ts'
111
117
  export * from './schema/site-settings-types.ts'
112
118
  export * from './schema/transfer-answers.ts'
119
+ export * from './schema/transfer-run-bundle-type.ts'
113
120
  export * from './schema/transfer-run-package.ts'
114
121
  export * from './schema/transfer-runs.ts'
115
122
  export * from './schema/trashed-date.ts'
123
+ export * from './schema/trusted-signers.ts'
116
124
  export * from './schema/two-factor.ts'
117
125
  export * from './schema/upgrade-report.ts'
118
126
  export * from './schema/users-localisation.ts'
@@ -11,8 +11,20 @@ export interface BundleGrant {
11
11
  packageName: string
12
12
  version: string
13
13
  permissions: string[]
14
+ /** What its `http.outbound` may reach (story 308); empty when it was granted none. */
15
+ origins: string[]
16
+ /**
17
+ * Whom it acts for under `actAs`: `installer:<user key>`, `caller`, or
18
+ * `user:<user key>`; null when it acts as itself.
19
+ */
20
+ actAs: string | null
14
21
  grantedBy: string | null
15
22
  grantedAt: Date
23
+ /**
24
+ * Someone granted it (story 309): false for the row `disable` keeps for a
25
+ * bundle never granted, which grants nothing.
26
+ */
27
+ recorded: boolean
16
28
  /** Who disabled the bundle, and when; null while it may run. */
17
29
  disabledBy: string | null
18
30
  disabledAt: Date | null
@@ -41,8 +53,11 @@ export class BundleGrantRepository {
41
53
  packageName: row.package_name,
42
54
  version: row.version,
43
55
  permissions: permissionsOf(row.permissions),
56
+ origins: row.origins ? permissionsOf(row.origins) : [],
57
+ actAs: row.act_as ?? null,
44
58
  grantedBy: row.granted_by ?? null,
45
59
  grantedAt: DbDate.fromDb(row.granted_at) ?? new Date(0),
60
+ recorded: (DbDate.fromDb(row.granted_at)?.getTime() ?? 0) > 0,
46
61
  disabledBy: row.disabled_by ?? null,
47
62
  disabledAt: row.disabled_at ? (DbDate.fromDb(row.disabled_at) ?? null) : null,
48
63
  }))
@@ -53,11 +68,15 @@ export class BundleGrantRepository {
53
68
  }
54
69
 
55
70
  /** Records what a bundle is approved for, keeping whether it is disabled. */
56
- async grant(grant: Omit<BundleGrant, 'grantedAt' | 'disabledBy' | 'disabledAt'>): Promise<void> {
71
+ async grant(
72
+ grant: Omit<BundleGrant, 'grantedAt' | 'recorded' | 'disabledBy' | 'disabledAt'>,
73
+ ): Promise<void> {
57
74
  const values = {
58
75
  package_name: grant.packageName,
59
76
  version: grant.version,
60
77
  permissions: JSON.stringify(grant.permissions),
78
+ origins: JSON.stringify(grant.origins),
79
+ act_as: grant.actAs,
61
80
  granted_by: grant.grantedBy,
62
81
  granted_at: DbDate.toDb(new Date()),
63
82
  }
@@ -85,7 +104,8 @@ export class BundleGrantRepository {
85
104
  version: bundle.version,
86
105
  permissions: JSON.stringify([]),
87
106
  granted_by: null,
88
- granted_at: DbDate.toDb(new Date()),
107
+ // Not a grant: nobody granted it anything (story 309).
108
+ granted_at: DbDate.toDb(new Date(0)),
89
109
  ...disabled,
90
110
  })
91
111
  .onConflict((conflict) => conflict.column('bundle_id').doUpdateSet(disabled))
@@ -11,6 +11,8 @@ import type { Db } from '../database.ts'
11
11
  import { DbDate, fromDbBool } from '../dialect.ts'
12
12
  import { sql } from '../query.ts'
13
13
 
14
+ export type BundleDefinitionKind = 'extension' | 'site'
15
+
14
16
  export interface Bundle {
15
17
  id: string
16
18
  name: string
@@ -33,6 +35,11 @@ export interface Bundle {
33
35
  */
34
36
  packageName: string | null
35
37
  packageVersion: string | null
38
+ /**
39
+ * What it builds (story 312): an extension for other sites, or a site bundle
40
+ * to move this site. Not in Umbraco's definition either.
41
+ */
42
+ kind: BundleDefinitionKind
36
43
  createDate: Date
37
44
  updateDate: Date
38
45
  }
@@ -40,12 +47,13 @@ export interface Bundle {
40
47
  /** A definition to store; `id` is assigned when it is new, the dates always. */
41
48
  export type BundleInput = Omit<
42
49
  Bundle,
43
- 'id' | 'createDate' | 'updateDate' | 'packageName' | 'packageVersion'
50
+ 'id' | 'createDate' | 'updateDate' | 'packageName' | 'packageVersion' | 'kind'
44
51
  >
45
52
 
46
53
  interface Row {
47
54
  id: string
48
55
  name: string
56
+ kind: string
49
57
  content_node_id: string | null
50
58
  content_load_child_nodes: unknown
51
59
  media_load_child_nodes: unknown
@@ -83,6 +91,7 @@ const COLUMNS = [
83
91
  'dictionary_items',
84
92
  'package_name',
85
93
  'package_version',
94
+ 'kind',
86
95
  'create_date',
87
96
  'update_date',
88
97
  ] as const
@@ -135,6 +144,7 @@ const hydrate = (row: Row): Bundle => ({
135
144
  dictionaryItems: list(row.dictionary_items),
136
145
  packageName: row.package_name ?? null,
137
146
  packageVersion: row.package_version ?? null,
147
+ kind: row.kind === 'site' ? 'site' : 'extension',
138
148
  createDate: DbDate.fromDb(row.create_date) ?? new Date(0),
139
149
  updateDate: DbDate.fromDb(row.update_date) ?? new Date(0),
140
150
  })
@@ -248,6 +258,7 @@ export class BundleRepository {
248
258
  id,
249
259
  packageName: null,
250
260
  packageVersion: null,
261
+ kind: 'extension',
251
262
  createDate: now,
252
263
  updateDate: now,
253
264
  }
@@ -262,6 +273,14 @@ export class BundleRepository {
262
273
  }
263
274
 
264
275
  /** The npm package a definition is built as; null clears a value back to its default. */
276
+ async setKind(id: string, kind: BundleDefinitionKind): Promise<void> {
277
+ await this.#db.q
278
+ .updateTable('bundle')
279
+ .set({ kind, update_date: DbDate.toDb(new Date()) })
280
+ .where('id', '=', id)
281
+ .execute()
282
+ }
283
+
265
284
  async setPackage(
266
285
  id: string,
267
286
  pkg: { name: string | null; version: string | null },
@@ -18,6 +18,7 @@ import {
18
18
  type PropertyGroupModel,
19
19
  PropertyGroupType,
20
20
  type PropertyTypeModel,
21
+ type SeoMapping,
21
22
  type SiteSearchLevel,
22
23
  SystemNodes,
23
24
  variationFlags,
@@ -61,6 +62,23 @@ async function propertySignature(db: Db, contentTypeNodeId: number): Promise<str
61
62
  }
62
63
 
63
64
  /** How a property's site-search setting is stored: its level, or `off`. */
65
+ /** A type's search and sharing values as stored: JSON, or null when it sets none. */
66
+ function seoColumn(mapping: SeoMapping | null): string | null {
67
+ const set = Object.entries(mapping ?? {}).filter(
68
+ ([, value]) => typeof value === 'string' && value !== '',
69
+ )
70
+ return set.length > 0 ? JSON.stringify(Object.fromEntries(set)) : null
71
+ }
72
+
73
+ function seoFromColumn(value: unknown): SeoMapping | null {
74
+ if (typeof value !== 'string' || value === '') return null
75
+ try {
76
+ return JSON.parse(value) as SeoMapping
77
+ } catch {
78
+ return null
79
+ }
80
+ }
81
+
64
82
  function siteSearchColumn(value: SiteSearchLevel | false | undefined): string {
65
83
  return value === false ? 'off' : (value ?? 'normal')
66
84
  }
@@ -368,6 +386,12 @@ export class ContentTypeRepository {
368
386
  .set({ site_search: bool(aggregate.siteSearch) })
369
387
  .where('node_id', '=', nodeId)
370
388
  .execute()
389
+ if (aggregate.seo !== undefined)
390
+ await tx.q
391
+ .updateTable('content_type')
392
+ .set({ seo: seoColumn(aggregate.seo) })
393
+ .where('node_id', '=', nodeId)
394
+ .execute()
371
395
  if (aggregate.siteSettings !== undefined)
372
396
  await tx.q
373
397
  .updateTable('content_type')
@@ -689,6 +713,24 @@ export class ContentTypeRepository {
689
713
  return this.byKeys(rows.map((r) => String(r.unique_id)))
690
714
  }
691
715
 
716
+ /** Each live type's search and sharing values, by alias, for the types that set any (story 317). */
717
+ async seoMappings(): Promise<Record<string, SeoMapping>> {
718
+ const rows = await this.#db.q
719
+ .selectFrom('content_type as ct')
720
+ .innerJoin('node as n', 'n.id', 'ct.node_id')
721
+ .select(['ct.alias', 'ct.seo'])
722
+ .where('ct.retired_at', 'is', null)
723
+ .where('ct.seo', 'is not', null)
724
+ .where('n.node_object_type', '=', this.#objectType)
725
+ .execute()
726
+ const out: Record<string, SeoMapping> = {}
727
+ for (const row of rows) {
728
+ const mapping = seoFromColumn(row.seo)
729
+ if (mapping) out[String(row.alias)] = mapping
730
+ }
731
+ return out
732
+ }
733
+
692
734
  /** Every live type's alias by its key, without loading the types themselves. */
693
735
  async aliasesByKey(): Promise<Map<string, string>> {
694
736
  const rows = await this.#db.q
@@ -835,6 +877,17 @@ export class ContentTypeRepository {
835
877
  return out
836
878
  }
837
879
 
880
+ /** Sets a type's search and sharing values alone (story 317); null clears them. */
881
+ async setSeo(typeKey: string, mapping: SeoMapping | null): Promise<void> {
882
+ const node = await this.#nodes.byKey(typeKey)
883
+ if (!node || node.objectType !== this.#objectType) return
884
+ await this.#db.q
885
+ .updateTable('content_type')
886
+ .set({ seo: seoColumn(mapping) })
887
+ .where('node_id', '=', node.id)
888
+ .execute()
889
+ }
890
+
838
891
  async contentCount(typeKey: string): Promise<number> {
839
892
  const node = await this.#nodes.byKey(typeKey)
840
893
  if (!node) return 0
@@ -931,6 +984,7 @@ export class ContentTypeRepository {
931
984
  'ct.since_version',
932
985
  'ct.site_search',
933
986
  'ct.site_settings',
987
+ 'ct.seo',
934
988
  'ct.form_key',
935
989
  'ss.version as since_v',
936
990
  'ss.revision as since_r',
@@ -1063,6 +1117,7 @@ export class ContentTypeRepository {
1063
1117
  allowedInLibrary: fromDbBool(type.allow_in_library),
1064
1118
  siteSearch: fromDbBool(type.site_search),
1065
1119
  siteSettings: fromDbBool(type.site_settings),
1120
+ seo: seoFromColumn(type.seo),
1066
1121
  formKey: (type.form_key as string | null) ?? null,
1067
1122
  collectionKey: type.list_view ? normaliseUuid(String(type.list_view)) : null,
1068
1123
  cleanup: {
@@ -0,0 +1,51 @@
1
+ /**
2
+ * An extension's settings as set in the back office (story 310), each stored as
3
+ * JSON; a secret arrives already sealed. docs/bundles.md, "Settings".
4
+ */
5
+ import type { Db } from '../database.ts'
6
+ import { DbDate } from '../dialect.ts'
7
+
8
+ export class ExtensionSettingRepository {
9
+ constructor(private readonly db: Db) {}
10
+
11
+ /** Every stored value, by extension and key. */
12
+ async all(): Promise<Map<string, Record<string, unknown>>> {
13
+ const rows = await this.db.q.selectFrom('extension_setting').selectAll().execute()
14
+ const out = new Map<string, Record<string, unknown>>()
15
+ for (const row of rows) {
16
+ const values = out.get(row.bundle_id) ?? {}
17
+ try {
18
+ values[row.setting_key] = JSON.parse(row.value) as unknown
19
+ } catch {
20
+ continue
21
+ }
22
+ out.set(row.bundle_id, values)
23
+ }
24
+ return out
25
+ }
26
+
27
+ /** One extension's stored values. */
28
+ async of(bundleId: string): Promise<Record<string, unknown>> {
29
+ return (await this.all()).get(bundleId) ?? {}
30
+ }
31
+
32
+ /** Sets one value, or with `undefined` takes it back to its default. */
33
+ async set(bundleId: string, key: string, value: unknown, by: string | null): Promise<void> {
34
+ await this.db.q
35
+ .deleteFrom('extension_setting')
36
+ .where('bundle_id', '=', bundleId)
37
+ .where('setting_key', '=', key)
38
+ .execute()
39
+ if (value === undefined) return
40
+ await this.db.q
41
+ .insertInto('extension_setting')
42
+ .values({
43
+ bundle_id: bundleId,
44
+ setting_key: key,
45
+ value: JSON.stringify(value),
46
+ updated_by: by,
47
+ updated_at: DbDate.toDb(new Date()),
48
+ })
49
+ .execute()
50
+ }
51
+ }
@@ -28,6 +28,10 @@ export interface TransferRun {
28
28
  /** The npm package the content arrived in, and its version. */
29
29
  packageName: string | null
30
30
  packageVersion: string | null
31
+ /** A site package's or an extension's (story 306); null for a run before that was recorded. */
32
+ bundleType: 'site' | 'extension' | null
33
+ /** Who signed its bundle, a key's fingerprint or a CI source's repository (story 316); null when nobody did. */
34
+ signedBy?: string | null
31
35
  direction: TransferDirection
32
36
  revertsRunId: string | null
33
37
  schemaStateId: number
@@ -67,6 +71,8 @@ export class TransferRunRepository {
67
71
  bundle_label: run.bundleLabel,
68
72
  package_name: run.packageName,
69
73
  package_version: run.packageVersion,
74
+ bundle_type: run.bundleType,
75
+ signed_by: run.signedBy ?? null,
70
76
  direction: run.direction,
71
77
  reverts_run_id: run.revertsRunId,
72
78
  schema_state_id: run.schemaStateId,
@@ -134,6 +140,19 @@ export class TransferRunRepository {
134
140
  return row ? mapRun(row) : undefined
135
141
  }
136
142
 
143
+ /** The versions of a package one signer's bundles brought, in applied imports (story 316). */
144
+ async versionsSignedBy(signer: string, packageName: string): Promise<string[]> {
145
+ const rows = await this.#db.q
146
+ .selectFrom('content_transfer_run')
147
+ .select('package_version')
148
+ .where('direction', '=', 'import')
149
+ .where('status', '=', 'applied')
150
+ .where('signed_by', '=', signer)
151
+ .where('package_name', '=', packageName)
152
+ .execute()
153
+ return rows.flatMap((row) => (row.package_version ? [row.package_version] : []))
154
+ }
155
+
137
156
  /** The latest standing import, narrowed by the caller. */
138
157
  #standing() {
139
158
  return this.#db.q
@@ -205,6 +224,9 @@ function mapRun(row: Record<string, unknown>): TransferRun {
205
224
  bundleLabel: (row.bundle_label as string | null) ?? null,
206
225
  packageName: (row.package_name as string | null) ?? null,
207
226
  packageVersion: (row.package_version as string | null) ?? null,
227
+ bundleType:
228
+ row.bundle_type === 'site' || row.bundle_type === 'extension' ? row.bundle_type : null,
229
+ signedBy: (row.signed_by as string | null) ?? null,
208
230
  direction: String(row.direction) as TransferDirection,
209
231
  revertsRunId: (row.reverts_run_id as string | null) ?? null,
210
232
  schemaStateId: Number(row.schema_state_id),
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The keys and CI sources a site trusts to sign the site bundles it applies
3
+ * (story 316), as an administrator manages them in Settings.
4
+ */
5
+ import { randomUUID } from 'node:crypto'
6
+ import type { Db } from '../database.ts'
7
+ import { DbDate } from '../dialect.ts'
8
+
9
+ export type TrustedSignerKind = 'user' | 'site' | 'source'
10
+
11
+ export interface TrustedSigner {
12
+ id: string
13
+ kind: TrustedSignerKind
14
+ name: string
15
+ /** A key's public line; null for a CI source. */
16
+ publicKey: string | null
17
+ fingerprint: string | null
18
+ /** A CI source, `org/repo@v*`; null for a key. */
19
+ source: string | null
20
+ addedBy: string | null
21
+ addedAt: Date
22
+ lastSignedAt: Date | null
23
+ }
24
+
25
+ const map = (row: Record<string, unknown>): TrustedSigner => ({
26
+ id: String(row.id),
27
+ kind: row.kind === 'site' ? 'site' : row.kind === 'source' ? 'source' : 'user',
28
+ name: String(row.name),
29
+ publicKey: (row.public_key as string | null) ?? null,
30
+ fingerprint: (row.fingerprint as string | null) ?? null,
31
+ source: (row.source as string | null) ?? null,
32
+ addedBy: (row.added_by as string | null) ?? null,
33
+ addedAt: DbDate.fromDb(row.added_at) ?? new Date(0),
34
+ lastSignedAt: DbDate.fromDb(row.last_signed_at) ?? null,
35
+ })
36
+
37
+ export class TrustedSignerRepository {
38
+ readonly #db: Db
39
+ constructor(db: Db) {
40
+ this.#db = db
41
+ }
42
+
43
+ async all(): Promise<TrustedSigner[]> {
44
+ const rows = await this.#db.q
45
+ .selectFrom('trusted_signer')
46
+ .selectAll()
47
+ .orderBy('added_at')
48
+ .execute()
49
+ return rows.map((row) => map(row as Record<string, unknown>))
50
+ }
51
+
52
+ async add(
53
+ signer: Pick<
54
+ TrustedSigner,
55
+ 'kind' | 'name' | 'publicKey' | 'fingerprint' | 'source' | 'addedBy'
56
+ >,
57
+ ): Promise<TrustedSigner> {
58
+ const id = randomUUID()
59
+ const now = new Date()
60
+ await this.#db.q
61
+ .insertInto('trusted_signer')
62
+ .values({
63
+ id,
64
+ kind: signer.kind,
65
+ name: signer.name,
66
+ public_key: signer.publicKey,
67
+ fingerprint: signer.fingerprint,
68
+ source: signer.source,
69
+ added_by: signer.addedBy,
70
+ added_at: DbDate.toDb(now),
71
+ })
72
+ .execute()
73
+ return { ...signer, id, addedAt: now, lastSignedAt: null }
74
+ }
75
+
76
+ async rename(id: string, name: string): Promise<boolean> {
77
+ const result = await this.#db.q
78
+ .updateTable('trusted_signer')
79
+ .set({ name })
80
+ .where('id', '=', id)
81
+ .executeTakeFirst()
82
+ return Number(result.numUpdatedRows) > 0
83
+ }
84
+
85
+ async remove(id: string): Promise<boolean> {
86
+ const result = await this.#db.q
87
+ .deleteFrom('trusted_signer')
88
+ .where('id', '=', id)
89
+ .executeTakeFirst()
90
+ return Number(result.numDeletedRows) > 0
91
+ }
92
+
93
+ /** Notes that a signer's bundle was applied, for the list's "last signed". */
94
+ async signed(id: string): Promise<void> {
95
+ await this.#db.q
96
+ .updateTable('trusted_signer')
97
+ .set({ last_signed_at: DbDate.toDb(new Date()) })
98
+ .where('id', '=', id)
99
+ .execute()
100
+ }
101
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Migration 066 — what a grant covers beyond the permissions' names (story
3
+ * 308): the origins its `http.outbound` may reach, and whom `actAs` acts for.
4
+ * Nullable: a grant before this one covered neither.
5
+ */
6
+ import type { Db } from '../database.ts'
7
+ import type { Migration } from '../migrations.ts'
8
+ import { schemaOps } from '../schema-ops.ts'
9
+ import { STATE_TRANSFER_RUN_BUNDLE_TYPE } from './transfer-run-bundle-type.ts'
10
+
11
+ export const STATE_BUNDLE_GRANT_REACH = '{c3e7a512-0066-4f0b-9d61-a8b2c4e60066}'
12
+
13
+ export const bundleGrantReachMigration: Migration = {
14
+ from: STATE_TRANSFER_RUN_BUNDLE_TYPE,
15
+ to: STATE_BUNDLE_GRANT_REACH,
16
+ name: 'AddBundleGrantReach',
17
+ kind: 'expand',
18
+ release: '0.57.0',
19
+ async up(db: Db) {
20
+ const ops = schemaOps(db)
21
+ await ops.addColumn('bundle_grant', 'origins', db.dialect.types.text)
22
+ await ops.addColumn('bundle_grant', 'act_as', db.dialect.types.varchar(80))
23
+ },
24
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Migration 068 — what a Bundle Editor definition builds (story 312): an
3
+ * extension for other sites, or a site bundle to move this site. Every
4
+ * definition before it built an extension (story 306).
5
+ */
6
+ import type { Db } from '../database.ts'
7
+ import type { Migration } from '../migrations.ts'
8
+ import { sql } from '../query.ts'
9
+ import { STATE_EXTENSION_SETTINGS } from './extension-settings.ts'
10
+
11
+ export const STATE_BUNDLE_KIND = '{d4f8b623-0068-4c1a-8e72-b9c3d5f70068}'
12
+
13
+ export const bundleKindMigration: Migration = {
14
+ from: STATE_EXTENSION_SETTINGS,
15
+ to: STATE_BUNDLE_KIND,
16
+ name: 'AddBundleKind',
17
+ kind: 'expand',
18
+ release: '0.57.0',
19
+ async up(db: Db) {
20
+ const t = db.dialect.types
21
+ await db.q.schema
22
+ .alterTable('bundle')
23
+ .addColumn('kind', sql.raw(t.varchar(16)), (c) => c.notNull().defaultTo('extension'))
24
+ .execute()
25
+ },
26
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Migration 070 — where a content type's search and sharing values come from
3
+ * (story 317): its `[seo]` table, kept as JSON beside the type.
4
+ */
5
+ import type { Db } from '../database.ts'
6
+ import type { Migration } from '../migrations.ts'
7
+ import { schemaOps } from '../schema-ops.ts'
8
+ import { STATE_TRUSTED_SIGNERS } from './trusted-signers.ts'
9
+
10
+ export const STATE_CONTENT_TYPE_SEO = '{7c3e15d2-0070-4a96-b2e8-5f1d0c9a7070}'
11
+
12
+ export const contentTypeSeoMigration: Migration = {
13
+ from: STATE_TRUSTED_SIGNERS,
14
+ to: STATE_CONTENT_TYPE_SEO,
15
+ name: 'AddContentTypeSeo',
16
+ kind: 'expand',
17
+ release: '0.58.0',
18
+ async up(db: Db) {
19
+ await schemaOps(db).addColumn('content_type', 'seo', db.dialect.types.text)
20
+ },
21
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Migration 067 — an extension's settings as an administrator set them in the
3
+ * back office (story 310). The config's values are not kept here: they lock the
4
+ * setting instead. A secret is kept sealed with the site's key.
5
+ */
6
+ import type { Db } from '../database.ts'
7
+ import type { Migration } from '../migrations.ts'
8
+ import { sql } from '../query.ts'
9
+ import { STATE_BUNDLE_GRANT_REACH } from './bundle-grant-reach.ts'
10
+
11
+ export const STATE_EXTENSION_SETTINGS = '{c3e7a512-0067-4f0b-9d61-a8b2c4e60067}'
12
+
13
+ export const extensionSettingsMigration: Migration = {
14
+ from: STATE_BUNDLE_GRANT_REACH,
15
+ to: STATE_EXTENSION_SETTINGS,
16
+ name: 'AddExtensionSettings',
17
+ kind: 'expand',
18
+ release: '0.57.0',
19
+ async up(db: Db) {
20
+ const t = db.dialect.types
21
+ await db.q.schema
22
+ .createTable('extension_setting')
23
+ .addColumn('bundle_id', sql.raw(t.varchar(64)), (c) => c.notNull())
24
+ .addColumn('setting_key', sql.raw(t.varchar(64)), (c) => c.notNull())
25
+ .addColumn('value', sql.raw(t.text), (c) => c.notNull())
26
+ .addColumn('updated_by', sql.raw(t.varchar(255)))
27
+ .addColumn('updated_at', sql.raw(t.timestamp), (c) => c.notNull())
28
+ .addPrimaryKeyConstraint('pk_extension_setting', ['bundle_id', 'setting_key'])
29
+ .execute()
30
+ },
31
+ }
@@ -18,7 +18,9 @@ import { approvalsMigration } from './approvals.ts'
18
18
  import { assistantMigration } from './assistant.ts'
19
19
  import { auditLogMigration } from './audit-log.ts'
20
20
  import { bundleComponentsMigration } from './bundle-components.ts'
21
+ import { bundleGrantReachMigration } from './bundle-grant-reach.ts'
21
22
  import { bundleGrantsMigration } from './bundle-grants.ts'
23
+ import { bundleKindMigration } from './bundle-kind.ts'
22
24
  import { bundlePackageMigration } from './bundle-package.ts'
23
25
  import { bundleSchemaPicksMigration } from './bundle-schema-picks.ts'
24
26
  import { bundlesDisabledMigration } from './bundles-disabled.ts'
@@ -32,11 +34,13 @@ import { contentCheckpointMigration } from './content-checkpoint.ts'
32
34
  import { contentEditingMigration } from './content-editing.ts'
33
35
  import { contentEventsMigration } from './content-events.ts'
34
36
  import { contentNotificationsMigration } from './content-notifications.ts'
37
+ import { contentTypeSeoMigration } from './content-type-seo.ts'
35
38
  import { createdPackagesMigration } from './created-packages.ts'
36
39
  import { deliveryMemberTokensMigration } from './delivery-member-tokens.ts'
37
40
  import { diagnosticsMigration } from './diagnostics.ts'
38
41
  import { dropAssistantMigration } from './drop-assistant.ts'
39
42
  import { elementsMigration } from './elements.ts'
43
+ import { extensionSettingsMigration } from './extension-settings.ts'
40
44
  import { formLibraryMigration } from './form-library.ts'
41
45
  import { formPermissionPrefixMigration } from './form-permission-prefix.ts'
42
46
  import { formPermissionsMigration } from './form-permissions.ts'
@@ -69,9 +73,11 @@ import { sinceVersionMigration } from './since-version.ts'
69
73
  import { siteSearchMigration } from './site-search.ts'
70
74
  import { siteSettingsTypesMigration } from './site-settings-types.ts'
71
75
  import { transferAnswersMigration } from './transfer-answers.ts'
76
+ import { transferRunBundleTypeMigration } from './transfer-run-bundle-type.ts'
72
77
  import { transferRunPackageMigration } from './transfer-run-package.ts'
73
78
  import { transferRunsMigration } from './transfer-runs.ts'
74
79
  import { trashedDateMigration } from './trashed-date.ts'
80
+ import { trustedSignersMigration } from './trusted-signers.ts'
75
81
  import { twoFactorMigration } from './two-factor.ts'
76
82
  import { upgradeReportMigration } from './upgrade-report.ts'
77
83
  import { usersLocalisationMigration } from './users-localisation.ts'
@@ -143,4 +149,10 @@ export const cromboloPlan = new MigrationPlan([
143
149
  mediaTreeOrderMigration,
144
150
  searchRemovalsMigration,
145
151
  imageAltTextMigration,
152
+ transferRunBundleTypeMigration,
153
+ bundleGrantReachMigration,
154
+ extensionSettingsMigration,
155
+ bundleKindMigration,
156
+ trustedSignersMigration,
157
+ contentTypeSeoMigration,
146
158
  ])
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Migration 065 — a transfer run records what kind of bundle it applied (story
3
+ * 306): a site package, which `site revert` puts back, or an extension's
4
+ * content, which uninstalling it does. Nullable: a run before this one was
5
+ * never asked.
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_IMAGE_ALT_TEXT } from './image-alt-text.ts'
11
+
12
+ export const STATE_TRANSFER_RUN_BUNDLE_TYPE = '{c3e7a512-0065-4f0b-9d61-a8b2c4e60065}'
13
+
14
+ export const transferRunBundleTypeMigration: Migration = {
15
+ from: STATE_IMAGE_ALT_TEXT,
16
+ to: STATE_TRANSFER_RUN_BUNDLE_TYPE,
17
+ name: 'AddTransferRunBundleType',
18
+ kind: 'expand',
19
+ release: '0.57.0',
20
+ async up(db: Db) {
21
+ await schemaOps(db).addColumn(
22
+ 'content_transfer_run',
23
+ 'bundle_type',
24
+ db.dialect.types.varchar(16),
25
+ )
26
+ },
27
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Migration 069 — the keys and CI sources a site trusts to sign the site
3
+ * bundles it applies (story 316), and who signed each applied run's bundle, so
4
+ * an older version from the same signer is refused.
5
+ */
6
+ import type { Db } from '../database.ts'
7
+ import type { Migration } from '../migrations.ts'
8
+ import { sql } from '../query.ts'
9
+ import { STATE_BUNDLE_KIND } from './bundle-kind.ts'
10
+
11
+ export const STATE_TRUSTED_SIGNERS = '{e5a9c734-0069-4d2b-9f83-cad4e6081069}'
12
+
13
+ export const trustedSignersMigration: Migration = {
14
+ from: STATE_BUNDLE_KIND,
15
+ to: STATE_TRUSTED_SIGNERS,
16
+ name: 'AddTrustedSigners',
17
+ kind: 'expand',
18
+ release: '0.57.0',
19
+ async up(db: Db) {
20
+ const t = db.dialect.types
21
+ await db.q.schema
22
+ .createTable('trusted_signer')
23
+ .addColumn('id', sql.raw(t.varchar(36)), (c) => c.primaryKey())
24
+ .addColumn('kind', sql.raw(t.varchar(16)), (c) => c.notNull())
25
+ .addColumn('name', sql.raw(t.varchar(255)), (c) => c.notNull())
26
+ .addColumn('public_key', sql.raw(t.text))
27
+ .addColumn('fingerprint', sql.raw(t.varchar(64)))
28
+ .addColumn('source', sql.raw(t.varchar(255)))
29
+ .addColumn('added_by', sql.raw(t.varchar(255)))
30
+ .addColumn('added_at', sql.raw(t.timestamp), (c) => c.notNull())
31
+ .addColumn('last_signed_at', sql.raw(t.timestamp))
32
+ .execute()
33
+ await db.q.schema
34
+ .alterTable('content_transfer_run')
35
+ .addColumn('signed_by', sql.raw(t.varchar(255)))
36
+ .execute()
37
+ },
38
+ }
package/src/tables.gen.ts CHANGED
@@ -100,6 +100,7 @@ export interface CoreTables {
100
100
  dictionary_items: string
101
101
  element_ids: string | null
102
102
  id: string
103
+ kind: Generated<string>
103
104
  languages: string
104
105
  media_ids: string
105
106
  media_load_child_nodes: Bool
@@ -113,11 +114,13 @@ export interface CoreTables {
113
114
  update_date: Timestamp
114
115
  }
115
116
  bundle_grant: {
117
+ act_as: string | null
116
118
  bundle_id: string
117
119
  disabled_at: Timestamp | null
118
120
  disabled_by: string | null
119
121
  granted_at: Timestamp
120
122
  granted_by: string | null
123
+ origins: string | null
121
124
  package_name: string
122
125
  permissions: string
123
126
  version: string
@@ -223,6 +226,7 @@ export interface CoreTables {
223
226
  applied_by: string | null
224
227
  bundle_id: string
225
228
  bundle_label: string | null
229
+ bundle_type: string | null
226
230
  direction: string
227
231
  finished_at: Timestamp | null
228
232
  id: string
@@ -231,6 +235,7 @@ export interface CoreTables {
231
235
  package_version: string | null
232
236
  reverts_run_id: string | null
233
237
  schema_state_id: number
238
+ signed_by: string | null
234
239
  started_at: Timestamp
235
240
  status: string
236
241
  }
@@ -248,6 +253,7 @@ export interface CoreTables {
248
253
  node_id: Generated<number>
249
254
  prevent_cleanup: Bool
250
255
  retired_at: Timestamp | null
256
+ seo: string | null
251
257
  since_state_id: number | null
252
258
  since_version: string | null
253
259
  site_search: Default<Bool>
@@ -367,6 +373,13 @@ export interface CoreTables {
367
373
  node_id: number
368
374
  sort_order: number
369
375
  }
376
+ extension_setting: {
377
+ bundle_id: string
378
+ setting_key: string
379
+ updated_at: Timestamp
380
+ updated_by: string | null
381
+ value: string
382
+ }
370
383
  external_login: {
371
384
  create_date: Timestamp
372
385
  id: Generated<number>
@@ -739,6 +752,17 @@ export interface CoreTables {
739
752
  target_kind: string
740
753
  under_target: string | null
741
754
  }
755
+ trusted_signer: {
756
+ added_at: Timestamp
757
+ added_by: string | null
758
+ fingerprint: string | null
759
+ id: string
760
+ kind: string
761
+ last_signed_at: Timestamp | null
762
+ name: string
763
+ public_key: string | null
764
+ source: string | null
765
+ }
742
766
  two_factor_login: {
743
767
  create_date: Timestamp
744
768
  id: Generated<number>