@crombolo/data 0.69.0 → 0.70.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.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Migration 083 — the places under Content are grants of their own (story 385).
3
+ * Every group keeps what it could open: one holding Content gains Pages, one
4
+ * holding Settings gains Structure and Code (`components`), and one holding a
5
+ * place under Content without Content gains Content, with Pages left off. A group
6
+ * kept in a site's `schema/user-groups/*.toml` is written from its file at the
7
+ * next sync instead, which the release notes say.
8
+ */
9
+ import type { Db } from '../database.ts'
10
+ import type { Migration } from '../migrations.ts'
11
+ import { STATE_WORKSPACES } from './workspaces.ts'
12
+
13
+ export const STATE_CONTENT_PLACES = '{4e7a1c93-0083-4b6d-a2f5-7c1e9d3b0083}'
14
+
15
+ /** Each grant a group gains (`alias`) from one it holds (`from`). */
16
+ const GAINS: ReadonlyArray<{ alias: string; from: readonly string[] }> = [
17
+ { alias: 'pages', from: ['content'] },
18
+ { alias: 'structure', from: ['settings'] },
19
+ { alias: 'components', from: ['settings'] },
20
+ { alias: 'content', from: ['media', 'workflow', 'forms'] },
21
+ ]
22
+
23
+ export const contentPlacesMigration: Migration = {
24
+ from: STATE_WORKSPACES,
25
+ to: STATE_CONTENT_PLACES,
26
+ name: 'AddContentPlaces',
27
+ kind: 'expand',
28
+ release: '0.70.0',
29
+ async up(db: Db) {
30
+ // One statement per grant, each adding it to every group that holds what it
31
+ // comes from and does not hold it already.
32
+ for (const { alias, from } of GAINS)
33
+ await db.q
34
+ .insertInto('user_group_section')
35
+ .columns(['user_group_id', 'app_alias'])
36
+ .expression((eb) =>
37
+ eb
38
+ .selectFrom('user_group_section as held')
39
+ .select(['held.user_group_id', eb.val(alias).as('app_alias')])
40
+ .where('held.app_alias', 'in', [...from])
41
+ .where((w) =>
42
+ w.not(
43
+ w.exists(
44
+ w
45
+ .selectFrom('user_group_section as has')
46
+ .select('has.app_alias')
47
+ .whereRef('has.user_group_id', '=', 'held.user_group_id')
48
+ .where('has.app_alias', '=', alias),
49
+ ),
50
+ ),
51
+ )
52
+ .distinct(),
53
+ )
54
+ .execute()
55
+ },
56
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Migration 089 — a value per environment (story 387): `property_value.environment`,
3
+ * beside language and segment, null for the shared value. A property that varies by
4
+ * environment serves the current environment's value where there is one, and the
5
+ * shared value otherwise.
6
+ */
7
+ import type { Db } from '../database.ts'
8
+ import type { Migration } from '../migrations.ts'
9
+ import { sql } from '../query.ts'
10
+ import { STATE_CHANGE_TRANSFER } from './change-transfer.ts'
11
+
12
+ export const STATE_ENVIRONMENT_VALUES = '{7a3d5e10-0089-4b6c-8e21-3f9c0d4a0089}'
13
+
14
+ export const environmentValuesMigration: Migration = {
15
+ from: STATE_CHANGE_TRANSFER,
16
+ to: STATE_ENVIRONMENT_VALUES,
17
+ name: 'AddEnvironmentValues',
18
+ kind: 'expand',
19
+ release: '0.70.0',
20
+ async up(db: Db) {
21
+ const t = db.dialect.types
22
+ await db.q.schema
23
+ .alterTable('property_value')
24
+ .addColumn('environment', sql.raw(t.varchar(64)))
25
+ .execute()
26
+ },
27
+ }
@@ -142,6 +142,8 @@ export async function ensureFormLibraryTypes(
142
142
  .select(['n.unique_id', 'ct.alias', 'ct.node_id'])
143
143
  .where('ct.form_key', 'is not', null)
144
144
  .where('ct.retired_at', 'is', null)
145
+ // A workspace's copies are its own (story 376).
146
+ .where('ct.workspace_id', 'is', null)
145
147
  .execute()
146
148
  for (const row of made) {
147
149
  const key = String(row.unique_id).toLowerCase()
@@ -28,6 +28,8 @@ import { bundlesDisabledMigration } from './bundles-disabled.ts'
28
28
  import { bundlesInSettingsMigration } from './bundles-in-settings.ts'
29
29
  import { bundlesRenameMigration } from './bundles-rename.ts'
30
30
  import { changeReportMigration } from './change-report.ts'
31
+ import { changeTransferMigration } from './change-transfer.ts'
32
+ import { changesMigration } from './changes.ts'
31
33
  import { cliTokensMigration } from './cli-tokens.ts'
32
34
  import { clientIdPrefixMigration } from './client-id-prefix.ts'
33
35
  import { contentMigration } from './content.ts'
@@ -36,12 +38,14 @@ import { contentCheckpointMigration } from './content-checkpoint.ts'
36
38
  import { contentEditingMigration } from './content-editing.ts'
37
39
  import { contentEventsMigration } from './content-events.ts'
38
40
  import { contentNotificationsMigration } from './content-notifications.ts'
41
+ import { contentPlacesMigration } from './content-places.ts'
39
42
  import { contentTypeSeoMigration } from './content-type-seo.ts'
40
43
  import { createdPackagesMigration } from './created-packages.ts'
41
44
  import { deliveryMemberTokensMigration } from './delivery-member-tokens.ts'
42
45
  import { diagnosticsMigration } from './diagnostics.ts'
43
46
  import { dropAssistantMigration } from './drop-assistant.ts'
44
47
  import { elementsMigration } from './elements.ts'
48
+ import { environmentValuesMigration } from './environment-values.ts'
45
49
  import { exchangeActorMigration } from './exchange-actor.ts'
46
50
  import { extensionActivityMigration } from './extension-activity.ts'
47
51
  import { extensionSettingsMigration } from './extension-settings.ts'
@@ -94,6 +98,11 @@ import { userStartNodesDroppedMigration } from './user-start-nodes-dropped.ts'
94
98
  import { usersLocalisationMigration } from './users-localisation.ts'
95
99
  import { valuesMigration } from './values.ts'
96
100
  import { webhooksMigration } from './webhooks.ts'
101
+ import { workspaceLinksMigration } from './workspace-links.ts'
102
+ import { workspaceMergeMigration } from './workspace-merge.ts'
103
+ import { workspacePrivacyMigration } from './workspace-privacy.ts'
104
+ import { workspaceSchemaMigration } from './workspace-schema.ts'
105
+ import { workspacesMigration } from './workspaces.ts'
97
106
 
98
107
  export const cromboloPlan = new MigrationPlan([
99
108
  identityMigration,
@@ -177,4 +186,13 @@ export const cromboloPlan = new MigrationPlan([
177
186
  remoteExchangeMigration,
178
187
  exchangeActorMigration,
179
188
  singleUseTokenMigration,
189
+ workspacesMigration,
190
+ contentPlacesMigration,
191
+ workspaceMergeMigration,
192
+ workspaceSchemaMigration,
193
+ changesMigration,
194
+ workspaceLinksMigration,
195
+ changeTransferMigration,
196
+ environmentValuesMigration,
197
+ workspacePrivacyMigration,
180
198
  ])
@@ -148,6 +148,9 @@ export const BUILT_IN_GROUPS = [
148
148
  hasAccessToAllLanguages: true,
149
149
  sections: [
150
150
  'content',
151
+ 'pages',
152
+ 'structure',
153
+ 'components',
151
154
  'media',
152
155
  'members',
153
156
  'settings',
@@ -165,7 +168,7 @@ export const BUILT_IN_GROUPS = [
165
168
  name: 'Writers',
166
169
  icon: 'icon-edit',
167
170
  hasAccessToAllLanguages: true,
168
- sections: ['content', 'library', 'workflow'],
171
+ sections: ['content', 'pages', 'library', 'workflow'],
169
172
  },
170
173
  {
171
174
  id: 3,
@@ -174,7 +177,7 @@ export const BUILT_IN_GROUPS = [
174
177
  name: 'Editors',
175
178
  icon: 'icon-tools',
176
179
  hasAccessToAllLanguages: true,
177
- sections: ['content', 'media', 'forms', 'library', 'workflow'],
180
+ sections: ['content', 'pages', 'media', 'forms', 'library', 'workflow'],
178
181
  },
179
182
  {
180
183
  id: 4,
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Migration 087 — links to a workspace's site (story 379): made by a member,
3
+ * each kept by the SHA-256 of its secret, reusable until it expires or is
4
+ * withdrawn, and no use once its maker leaves the workspace.
5
+ */
6
+ import type { Db } from '../database.ts'
7
+ import type { Migration } from '../migrations.ts'
8
+ import { sql } from '../query.ts'
9
+ import { STATE_CHANGES } from './changes.ts'
10
+
11
+ export const STATE_WORKSPACE_LINKS = '{9e2b7d40-0087-4a1c-b6f3-2d8e5c1a0087}'
12
+
13
+ export const workspaceLinksMigration: Migration = {
14
+ from: STATE_CHANGES,
15
+ to: STATE_WORKSPACE_LINKS,
16
+ name: 'AddWorkspaceLinks',
17
+ kind: 'expand',
18
+ release: '0.70.0',
19
+ async up(db: Db) {
20
+ const t = db.dialect.types
21
+ await db.q.schema
22
+ .createTable('workspace_link')
23
+ .addColumn('id', sql.raw(t.identity))
24
+ .addColumn('workspace_id', sql.raw(t.integer), (c) => c.notNull())
25
+ .addColumn('secret_hash', sql.raw(t.varchar(64)), (c) => c.notNull().unique())
26
+ .addColumn('made_by', sql.raw(t.uuid), (c) => c.notNull())
27
+ .addColumn('created_at', sql.raw(t.timestamp), (c) => c.notNull())
28
+ .addColumn('expires_at', sql.raw(t.timestamp), (c) => c.notNull())
29
+ .addColumn('withdrawn_at', sql.raw(t.timestamp))
30
+ .execute()
31
+ await db.q.schema
32
+ .createIndex('ix_workspace_link_workspace')
33
+ .on('workspace_link')
34
+ .column('workspace_id')
35
+ .execute()
36
+ },
37
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Migration 084 — what a merge needs that a workspace did not keep (story 380):
3
+ * whether it is open or merged, and when and by whom; each page's published
4
+ * state, and each language's, when the workspace first changed it; and where a
5
+ * page stood when a move, reorder or delete of it was recorded, so a merge can
6
+ * tell what Shared did since. A marker a Shared delete leaves keeps the page's
7
+ * name, since its node is gone. A person's own workspace, which
8
+ * `workspaces.required` opens for them, is marked as theirs.
9
+ */
10
+ import type { Db } from '../database.ts'
11
+ import type { Migration } from '../migrations.ts'
12
+ import { sql } from '../query.ts'
13
+ import { STATE_CONTENT_PLACES } from './content-places.ts'
14
+
15
+ export const STATE_WORKSPACE_MERGE = '{6b1d7e42-0084-4f9a-8c3e-2d5f0a7b0084}'
16
+
17
+ /** The columns the migration adds, by table, for a rewind to drop. */
18
+ export const WORKSPACE_MERGE_COLUMNS: ReadonlyArray<{ table: string; columns: readonly string[] }> =
19
+ [
20
+ { table: 'workspace', columns: ['state', 'merged_at', 'merged_by', 'personal'] },
21
+ { table: 'workspace_document', columns: ['base_published'] },
22
+ { table: 'workspace_document_culture', columns: ['base_published', 'base_published_event_id'] },
23
+ {
24
+ table: 'workspace_pending',
25
+ columns: ['base_parent_id', 'base_sort_order', 'base_event_id', 'name'],
26
+ },
27
+ ]
28
+
29
+ export const workspaceMergeMigration: Migration = {
30
+ from: STATE_CONTENT_PLACES,
31
+ to: STATE_WORKSPACE_MERGE,
32
+ name: 'AddWorkspaceMerge',
33
+ kind: 'expand',
34
+ release: '0.70.0',
35
+ async up(db: Db) {
36
+ const t = db.dialect.types
37
+ const add = async (table: string, column: string, type: string, notNullDefault?: string) => {
38
+ await db.q.schema
39
+ .alterTable(table)
40
+ .addColumn(column, sql.raw(type), (c) =>
41
+ notNullDefault === undefined ? c : c.notNull().defaultTo(sql.raw(notNullDefault)),
42
+ )
43
+ .execute()
44
+ }
45
+ await add('workspace', 'state', t.varchar(16), "'open'")
46
+ await add('workspace', 'merged_at', t.timestamp)
47
+ await add('workspace', 'merged_by', t.uuid)
48
+ // A person's own unnamed workspace, where `workspaces.required` puts their edits.
49
+ await add('workspace', 'personal', t.boolean, db.dialect.name === 'postgres' ? 'false' : '0')
50
+ await add('workspace_document', 'base_published', t.boolean)
51
+ await add('workspace_document_culture', 'base_published', t.boolean)
52
+ await add('workspace_document_culture', 'base_published_event_id', t.integer)
53
+ await add('workspace_pending', 'base_parent_id', t.integer)
54
+ await add('workspace_pending', 'base_sort_order', t.integer)
55
+ await add('workspace_pending', 'base_event_id', t.integer)
56
+ await add('workspace_pending', 'name', t.varchar(255))
57
+ },
58
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Migration 090 — a workspace's privacy (story 384), chosen by its owner: who can see
3
+ * it (`members`, or `editors`, everyone who may edit, its changes readable and editable
4
+ * only by its members), and whether someone opening an item it changed is told so.
5
+ */
6
+ import type { Db } from '../database.ts'
7
+ import type { Migration } from '../migrations.ts'
8
+ import { sql } from '../query.ts'
9
+ import { STATE_ENVIRONMENT_VALUES } from './environment-values.ts'
10
+
11
+ export const STATE_WORKSPACE_PRIVACY = '{2b8f4c61-0090-4e7a-9d13-5c6a1e2f0090}'
12
+
13
+ export const workspacePrivacyMigration: Migration = {
14
+ from: STATE_ENVIRONMENT_VALUES,
15
+ to: STATE_WORKSPACE_PRIVACY,
16
+ name: 'AddWorkspacePrivacy',
17
+ kind: 'expand',
18
+ release: '0.70.0',
19
+ async up(db: Db) {
20
+ const t = db.dialect.types
21
+ await db.q.schema
22
+ .alterTable('workspace')
23
+ .addColumn('visibility', sql.raw(t.varchar(16)), (c) => c.notNull().defaultTo('members'))
24
+ .execute()
25
+ await db.q.schema
26
+ .alterTable('workspace')
27
+ .addColumn('tell_others', sql.raw(t.boolean), (c) =>
28
+ c.notNull().defaultTo(sql.raw(db.dialect.name === 'postgres' ? 'true' : '1')),
29
+ )
30
+ .execute()
31
+ },
32
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Migration 085 — a workspace holds schema changes (story 376). Files are kept
3
+ * once each, by the SHA-256 of their text (`file_blob`), and a workspace holds a
4
+ * list of path and hash (`workspace_file`), taken when it opens: the hash then is
5
+ * each file's merge base. A workspace's copy of a type or data type is a row of
6
+ * its own, under a node and keys of its own, carrying `workspace_id` and the key
7
+ * it stands for (`origin_key`); Shared's alias index is over Shared's rows only.
8
+ *
9
+ * The added columns have no foreign key: SQLite will not drop a column one names,
10
+ * and every test rewind drops them.
11
+ */
12
+ import type { Db } from '../database.ts'
13
+ import type { Migration } from '../migrations.ts'
14
+ import { sql } from '../query.ts'
15
+ import { STATE_WORKSPACE_MERGE } from './workspace-merge.ts'
16
+
17
+ export const STATE_WORKSPACE_SCHEMA = '{7a3e9c51-0085-4b2d-8e6f-1c4a7b9d0085}'
18
+
19
+ /** The tables the migration adds, children first, for a rewind to drop. */
20
+ export const WORKSPACE_SCHEMA_TABLES = ['workspace_file', 'file_blob'] as const
21
+
22
+ /** The columns the migration adds, by table, for a rewind to drop. */
23
+ export const WORKSPACE_SCHEMA_COLUMNS: ReadonlyArray<{
24
+ table: string
25
+ columns: readonly string[]
26
+ }> = [
27
+ { table: 'workspace', columns: ['schema_built'] },
28
+ { table: 'content_type', columns: ['workspace_id', 'origin_key'] },
29
+ { table: 'data_type', columns: ['workspace_id', 'origin_key'] },
30
+ { table: 'property_type', columns: ['origin_key'] },
31
+ { table: 'property_type_group', columns: ['origin_key'] },
32
+ ]
33
+
34
+ export const workspaceSchemaMigration: Migration = {
35
+ from: STATE_WORKSPACE_MERGE,
36
+ to: STATE_WORKSPACE_SCHEMA,
37
+ name: 'AddWorkspaceSchema',
38
+ kind: 'expand',
39
+ release: '0.70.0',
40
+ async up(db: Db) {
41
+ const t = db.dialect.types
42
+ await db.q.schema
43
+ .createTable('file_blob')
44
+ .addColumn('hash', sql.raw(t.varchar(64)), (c) => c.primaryKey())
45
+ .addColumn('text', sql.raw(t.text), (c) => c.notNull())
46
+ .addColumn('size', sql.raw(t.integer), (c) => c.notNull())
47
+ .execute()
48
+ await db.q.schema
49
+ .createTable('workspace_file')
50
+ .addColumn('workspace_id', sql.raw(t.integer), (c) => c.notNull())
51
+ .addColumn('path', sql.raw(t.varchar(512)), (c) => c.notNull())
52
+ // The file's hash when the workspace opened (null: it was not there), and now (null: removed).
53
+ .addColumn('base_hash', sql.raw(t.varchar(64)))
54
+ .addColumn('hash', sql.raw(t.varchar(64)))
55
+ // The class of the workspace's change to it (story 382's four), set as it is saved.
56
+ .addColumn('class', sql.raw(t.varchar(16)))
57
+ .addPrimaryKeyConstraint('pk_workspace_file', ['workspace_id', 'path'])
58
+ .execute()
59
+ await db.q.schema
60
+ .createIndex('ix_workspace_file_hash')
61
+ .on('workspace_file')
62
+ .columns(['hash'])
63
+ .execute()
64
+
65
+ const add = async (table: string, column: string, type: string, notNullDefault?: string) => {
66
+ await db.q.schema
67
+ .alterTable(table)
68
+ .addColumn(column, sql.raw(type), (c) =>
69
+ notNullDefault === undefined ? c : c.notNull().defaultTo(sql.raw(notNullDefault)),
70
+ )
71
+ .execute()
72
+ }
73
+ await add(
74
+ 'workspace',
75
+ 'schema_built',
76
+ t.boolean,
77
+ db.dialect.name === 'postgres' ? 'false' : '0',
78
+ )
79
+ for (const table of ['content_type', 'data_type']) {
80
+ await add(table, 'workspace_id', t.integer)
81
+ await add(table, 'origin_key', t.uuid)
82
+ }
83
+ await add('property_type', 'origin_key', t.uuid)
84
+ await add('property_type_group', 'origin_key', t.uuid)
85
+ await db.q.schema
86
+ .createIndex('ix_content_type_workspace')
87
+ .on('content_type')
88
+ .columns(['workspace_id', 'origin_key'])
89
+ .execute()
90
+ await db.q.schema
91
+ .createIndex('ix_data_type_workspace')
92
+ .on('data_type')
93
+ .columns(['workspace_id', 'origin_key'])
94
+ .execute()
95
+
96
+ // An alias is Shared's to hold once; a workspace's copy holds it again, in its own.
97
+ await db.q.schema.dropIndex('ux_content_type_alias').execute()
98
+ await db.q.schema
99
+ .createIndex('ux_content_type_alias')
100
+ .on('content_type')
101
+ .column('alias')
102
+ .unique()
103
+ .where(sql.ref('workspace_id'), 'is', null)
104
+ .execute()
105
+ await db.q.schema
106
+ .createIndex('ux_content_type_workspace_alias')
107
+ .on('content_type')
108
+ .columns(['workspace_id', 'alias'])
109
+ .unique()
110
+ .where(sql.ref('workspace_id'), 'is not', null)
111
+ .execute()
112
+ },
113
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Migration 082 — workspaces (story 375): pages changed apart from Shared. A
3
+ * workspace is a row with its owner and members; a page it changes keeps the
4
+ * Shared event it started from, and its own events and values sit in the same
5
+ * tables as Shared's, carrying `workspace_id` (null for Shared). A page made in
6
+ * one has a node carrying it. Moves, reorders and deletes wait as pending rows
7
+ * until the workspace is merged (story 380).
8
+ *
9
+ * The added columns have no foreign key: SQLite will not drop a column one
10
+ * names, and every test rewind drops them.
11
+ */
12
+ import type { Db } from '../database.ts'
13
+ import type { Migration } from '../migrations.ts'
14
+ import { sql } from '../query.ts'
15
+ import { STATE_SINGLE_USE_TOKEN } from './single-use-token.ts'
16
+
17
+ export const STATE_WORKSPACES = '{8d2f4c1a-0082-4e7b-9c3d-5a6e0f2b0082}'
18
+
19
+ /** The tables the migration adds, children first, so a rewind drops them in order. */
20
+ export const WORKSPACE_TABLES = [
21
+ 'workspace_pending',
22
+ 'workspace_document_culture',
23
+ 'workspace_document',
24
+ 'workspace_member',
25
+ 'workspace',
26
+ ] as const
27
+
28
+ /** The tables that gain `workspace_id`, with the index each is given. */
29
+ export const WORKSPACE_COLUMNS = [
30
+ { table: 'node', index: 'ix_node_workspace', columns: ['workspace_id'] },
31
+ {
32
+ table: 'content_version',
33
+ index: 'ix_content_version_workspace',
34
+ columns: ['workspace_id', 'node_id'],
35
+ },
36
+ {
37
+ table: 'property_value',
38
+ index: 'ix_property_value_workspace',
39
+ columns: ['workspace_id', 'node_id'],
40
+ },
41
+ { table: 'content_schedule', index: 'ix_content_schedule_workspace', columns: ['workspace_id'] },
42
+ ] as const
43
+
44
+ export const workspacesMigration: Migration = {
45
+ from: STATE_SINGLE_USE_TOKEN,
46
+ to: STATE_WORKSPACES,
47
+ name: 'AddWorkspaces',
48
+ kind: 'expand',
49
+ release: '0.70.0',
50
+ async up(db: Db) {
51
+ const t = db.dialect.types
52
+ await db.q.schema
53
+ .createTable('workspace')
54
+ .addColumn('id', sql.raw(t.identity))
55
+ .addColumn('key', sql.raw(t.uuid), (c) => c.notNull().unique())
56
+ .addColumn('name', sql.raw(t.varchar(255)), (c) => c.notNull())
57
+ .addColumn('owner_key', sql.raw(t.uuid), (c) => c.notNull())
58
+ .addColumn('created_at', sql.raw(t.timestamp), (c) => c.notNull())
59
+ .addColumn('updated_at', sql.raw(t.timestamp), (c) => c.notNull())
60
+ .execute()
61
+ await db.q.schema
62
+ .createIndex('ix_workspace_owner')
63
+ .on('workspace')
64
+ .column('owner_key')
65
+ .execute()
66
+
67
+ await db.q.schema
68
+ .createTable('workspace_member')
69
+ .addColumn('workspace_id', sql.raw(t.integer), (c) => c.notNull().references('workspace.id'))
70
+ .addColumn('user_key', sql.raw(t.uuid), (c) => c.notNull())
71
+ .addColumn('added_at', sql.raw(t.timestamp), (c) => c.notNull())
72
+ .addPrimaryKeyConstraint('pk_workspace_member', ['workspace_id', 'user_key'])
73
+ .execute()
74
+ await db.q.schema
75
+ .createIndex('ix_workspace_member_user')
76
+ .on('workspace_member')
77
+ .column('user_key')
78
+ .execute()
79
+
80
+ // One row per page the workspace has touched: its base, and where it stands there.
81
+ await db.q.schema
82
+ .createTable('workspace_document')
83
+ .addColumn('workspace_id', sql.raw(t.integer), (c) => c.notNull().references('workspace.id'))
84
+ .addColumn('node_id', sql.raw(t.integer), (c) => c.notNull())
85
+ .addColumn('base_event_id', sql.raw(t.integer))
86
+ .addColumn('created', sql.raw(t.boolean), (c) => c.notNull())
87
+ .addColumn('published', sql.raw(t.boolean), (c) => c.notNull())
88
+ .addColumn('published_event_id', sql.raw(t.integer))
89
+ .addColumn('edited', sql.raw(t.boolean), (c) => c.notNull())
90
+ .addPrimaryKeyConstraint('pk_workspace_document', ['workspace_id', 'node_id'])
91
+ .execute()
92
+
93
+ // Each language of such a page, as `document_culture_variation` holds it for Shared.
94
+ await db.q.schema
95
+ .createTable('workspace_document_culture')
96
+ .addColumn('workspace_id', sql.raw(t.integer), (c) => c.notNull().references('workspace.id'))
97
+ .addColumn('node_id', sql.raw(t.integer), (c) => c.notNull())
98
+ .addColumn('language_id', sql.raw(t.integer), (c) => c.notNull())
99
+ .addColumn('name', sql.raw(t.varchar(255)))
100
+ .addColumn('available', sql.raw(t.boolean), (c) => c.notNull())
101
+ .addColumn('published', sql.raw(t.boolean), (c) => c.notNull())
102
+ .addColumn('edited', sql.raw(t.boolean), (c) => c.notNull())
103
+ .addColumn('published_event_id', sql.raw(t.integer))
104
+ .addColumn('published_name', sql.raw(t.varchar(255)))
105
+ .addPrimaryKeyConstraint('pk_workspace_document_culture', [
106
+ 'workspace_id',
107
+ 'node_id',
108
+ 'language_id',
109
+ ])
110
+ .execute()
111
+
112
+ await db.q.schema
113
+ .createTable('workspace_pending')
114
+ .addColumn('id', sql.raw(t.identity))
115
+ .addColumn('workspace_id', sql.raw(t.integer), (c) => c.notNull().references('workspace.id'))
116
+ .addColumn('node_id', sql.raw(t.integer), (c) => c.notNull())
117
+ .addColumn('kind', sql.raw(t.varchar(16)), (c) => c.notNull())
118
+ .addColumn('target_parent_id', sql.raw(t.integer))
119
+ .addColumn('sort_order', sql.raw(t.integer))
120
+ .addColumn('user_id', sql.raw(t.integer))
121
+ .addColumn('recorded_at', sql.raw(t.timestamp), (c) => c.notNull())
122
+ .execute()
123
+ await db.q.schema
124
+ .createIndex('ix_workspace_pending_workspace')
125
+ .on('workspace_pending')
126
+ .columns(['workspace_id', 'node_id'])
127
+ .execute()
128
+
129
+ for (const { table, index, columns } of WORKSPACE_COLUMNS) {
130
+ await db.q.schema.alterTable(table).addColumn('workspace_id', sql.raw(t.integer)).execute()
131
+ await db.q.schema
132
+ .createIndex(index)
133
+ .on(table)
134
+ .columns([...columns])
135
+ .execute()
136
+ }
137
+ },
138
+ }
@@ -120,6 +120,7 @@ export async function siteEntriesFor(db: Db, nodeId: number): Promise<SiteSearch
120
120
  'p.site_search',
121
121
  ])
122
122
  .where('pv.node_id', '=', nodeId)
123
+ .where('pv.workspace_id', 'is', null)
123
124
  .where('pv.event_id', '<=', latest)
124
125
  .where('p.retired_at', 'is', null)
125
126
  .where('p.searchable', '=', db.dialect.boolValue(true))