@surveilr/bootstrap-sql 0.0.3 → 0.0.4

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/index.js CHANGED
@@ -1,118 +1,2027 @@
1
+ // ../../drizzle/models.ts
1
2
  import {
2
- codeNotebookCellLatest,
3
- codeNotebookCellVersions,
4
- codeNotebookMigrationSql,
5
- codeNotebookSqlCellMigratable,
6
- codeNotebookSqlCellMigratableNotExecuted,
7
- codeNotebookSqlCellMigratableState,
8
- codeNotebookSqlCellMigratableVersion,
9
- consoleContentTabular,
10
- consoleInformationSchemaTable,
11
- consoleInformationSchemaTableColFkey,
12
- consoleInformationSchemaTableColIndex,
13
- consoleInformationSchemaView,
14
- deviceGraphAnalytics,
15
- deviceGraphCorrelations,
16
- deviceGraphOverview,
17
- emailMessagesWithTimezone,
18
- filesystemGraph,
19
- imapGraph,
20
- networkDeviceTopology,
21
- orchestrationExecutionSuccessRateByType,
22
- orchestrationExecutionsByType,
23
- orchestrationIssueRemediation,
24
- orchestrationLogsBySession,
25
- orchestrationSessionByDevice,
26
- orchestrationSessionDuration,
27
- orchestrationSessionScript,
28
- orchestrationSessionSummary,
29
- orchestrationSuccessRate,
30
- rssdStatisticsOverview,
31
- rssdTableStatistic,
32
- snmpCollectionSummary,
33
- snmpDeviceInventory,
34
- snmpOidPerformance,
35
- uniformResourceFile,
36
- uniformResourceImap,
37
- uniformResourceImapContent,
38
- urIngestSessionFileIssue,
39
- urIngestSessionFilesStats,
40
- urIngestSessionFilesStatsLatest,
41
- urIngestSessionTasksStats,
42
- urIngestSessionTasksStatsLatest
43
- } from "./chunk-QTY32BJY.js";
44
- import {
45
- assuranceSchema,
46
- behavior,
47
- checkJSON,
48
- codeNotebookCell,
49
- codeNotebookKernel,
50
- codeNotebookState,
51
- device,
52
- devicePartyRelationship,
53
- genderType,
54
- housekeeping,
55
- orchestrationNature,
56
- orchestrationSession,
57
- orchestrationSessionEntry,
58
- orchestrationSessionExec,
59
- orchestrationSessionIssue,
60
- orchestrationSessionIssueRelation,
61
- orchestrationSessionLog,
62
- orchestrationSessionState,
63
- organization,
64
- organizationRole,
65
- organizationRoleType,
66
- osqueryPolicy,
67
- party,
68
- partyRelation,
69
- partyRelationType,
70
- partyType,
71
- person,
72
- personType,
73
- sexType,
74
- sqleanDefine,
75
- sqlpageAideNavigation,
76
- sqlpageFiles,
77
- surveilrFunctionDoc,
78
- surveilrOsqueryMsCarve,
79
- surveilrOsqueryMsCarvedExtractedFile,
80
- surveilrOsqueryMsDistributedQuery,
81
- surveilrOsqueryMsDistributedResult,
82
- surveilrOsqueryMsNode,
83
- surveilrSnmpCollection,
84
- surveilrSnmpDevice,
85
- surveilrTableSize,
86
- uniformResource,
87
- uniformResourceEdge,
88
- uniformResourceGraph,
89
- uniformResourceTransform,
90
- urIngestResourcePathMatchRule,
91
- urIngestResourcePathRewriteRule,
92
- urIngestSession,
93
- urIngestSessionAttachment,
94
- urIngestSessionFsPath,
95
- urIngestSessionFsPathEntry,
96
- urIngestSessionImapAccount,
97
- urIngestSessionImapAcctFolder,
98
- urIngestSessionImapAcctFolderMessage,
99
- urIngestSessionOsqueryMsLog,
100
- urIngestSessionPlmAccount,
101
- urIngestSessionPlmAcctLabel,
102
- urIngestSessionPlmAcctProject,
103
- urIngestSessionPlmAcctProjectIssue,
104
- urIngestSessionPlmAcctRelationship,
105
- urIngestSessionPlmComment,
106
- urIngestSessionPlmIssueReaction,
107
- urIngestSessionPlmIssueType,
108
- urIngestSessionPlmMilestone,
109
- urIngestSessionPlmReaction,
110
- urIngestSessionPlmUser,
111
- urIngestSessionTask,
112
- urIngestSessionUdiPgpSql
113
- } from "./chunk-HZLAQ5XF.js";
3
+ blob,
4
+ check,
5
+ customType,
6
+ foreignKey,
7
+ index,
8
+ integer,
9
+ numeric,
10
+ real,
11
+ sqliteTable as table,
12
+ text,
13
+ unique
14
+ } from "drizzle-orm/sqlite-core";
15
+ import { sql } from "drizzle-orm";
16
+ var timestamptz = customType({
17
+ dataType() {
18
+ return "TIMESTAMPTZ";
19
+ },
20
+ fromDriver(value) {
21
+ return value;
22
+ },
23
+ toDriver(value) {
24
+ return value;
25
+ }
26
+ });
27
+ var date = customType({
28
+ dataType() {
29
+ return "DATE";
30
+ },
31
+ fromDriver(value) {
32
+ return value;
33
+ },
34
+ toDriver(value) {
35
+ return value;
36
+ }
37
+ });
38
+ var ulid = customType({
39
+ dataType() {
40
+ return "ULID";
41
+ },
42
+ fromDriver(value) {
43
+ return value;
44
+ },
45
+ toDriver(value) {
46
+ return value;
47
+ }
48
+ });
49
+ var varchar = customType({
50
+ dataType() {
51
+ return "VARCHAR";
52
+ },
53
+ fromDriver(value) {
54
+ return value;
55
+ },
56
+ toDriver(value) {
57
+ return value;
58
+ }
59
+ });
60
+ var textArray = customType({
61
+ dataType() {
62
+ return "TEXT[]";
63
+ },
64
+ fromDriver(value) {
65
+ return JSON.parse(value);
66
+ },
67
+ toDriver(value) {
68
+ return JSON.stringify(value);
69
+ }
70
+ });
71
+ var housekeeping = {
72
+ createdAt: timestamptz("created_at").default(sql`CURRENT_TIMESTAMP`),
73
+ createdBy: text("created_by").default("UNKNOWN"),
74
+ updatedAt: timestamptz("updated_at"),
75
+ updatedBy: text("updated_by"),
76
+ deletedAt: timestamptz("deleted_at"),
77
+ deletedBy: text("deleted_by"),
78
+ activityLog: text("activity_log")
79
+ };
80
+ var sqleanDefine = table("sqlean_define", {
81
+ name: text().primaryKey(),
82
+ type: text(),
83
+ body: text()
84
+ }, (table2) => []);
85
+ var checkJSON = (c) => check(`${c.name}_check_valid_json`, sql`json_valid(${c}) OR ${c} IS NULL`);
86
+ var assuranceSchema = table("assurance_schema", {
87
+ assuranceSchemaId: varchar("assurance_schema_id").primaryKey().notNull(),
88
+ assuranceType: text("assurance_type").notNull(),
89
+ code: text().notNull(),
90
+ codeJson: text("code_json", { mode: "json" }),
91
+ governance: text(),
92
+ ...housekeeping
93
+ }, (table2) => [
94
+ checkJSON(table2.codeJson),
95
+ checkJSON(table2.governance)
96
+ ]);
97
+ var device = table("device", {
98
+ deviceId: varchar("device_id").primaryKey().notNull(),
99
+ name: text().notNull(),
100
+ state: text().notNull(),
101
+ boundary: text().notNull(),
102
+ segmentation: text(),
103
+ stateSysinfo: text("state_sysinfo"),
104
+ elaboration: text(),
105
+ ...housekeeping
106
+ }, (table2) => [
107
+ index("idx_device__name__state").on(table2.name, table2.state),
108
+ unique().on(table2.name, table2.state, table2.boundary),
109
+ checkJSON(table2.state),
110
+ checkJSON(table2.segmentation),
111
+ checkJSON(table2.stateSysinfo),
112
+ checkJSON(table2.elaboration)
113
+ ]);
114
+ var codeNotebookKernel = table("code_notebook_kernel", {
115
+ codeNotebookKernelId: varchar("code_notebook_kernel_id").primaryKey().notNull(),
116
+ kernelName: text("kernel_name").notNull(),
117
+ description: text(),
118
+ mimeType: text("mime_type"),
119
+ fileExtn: text("file_extn"),
120
+ elaboration: text(),
121
+ governance: text(),
122
+ ...housekeeping
123
+ }, (table2) => [
124
+ unique().on(table2.kernelName),
125
+ checkJSON(table2.elaboration),
126
+ checkJSON(table2.governance)
127
+ ]);
128
+ var codeNotebookCell = table("code_notebook_cell", {
129
+ codeNotebookCellId: varchar("code_notebook_cell_id").primaryKey().notNull(),
130
+ notebookKernelId: varchar("notebook_kernel_id").notNull().references(
131
+ () => codeNotebookKernel.codeNotebookKernelId
132
+ ),
133
+ notebookName: text("notebook_name").notNull(),
134
+ cellName: text("cell_name").notNull(),
135
+ cellGovernance: text("cell_governance"),
136
+ interpretableCode: text("interpretable_code").notNull(),
137
+ interpretableCodeHash: text("interpretable_code_hash").notNull(),
138
+ description: text(),
139
+ arguments: text(),
140
+ ...housekeeping
141
+ }, (table2) => [
142
+ unique().on(table2.notebookName, table2.cellName, table2.interpretableCodeHash),
143
+ checkJSON(table2.cellGovernance),
144
+ checkJSON(table2.arguments)
145
+ ]);
146
+ var codeNotebookState = table("code_notebook_state", {
147
+ codeNotebookStateId: varchar("code_notebook_state_id").primaryKey().notNull(),
148
+ codeNotebookCellId: varchar("code_notebook_cell_id").notNull().references(
149
+ () => codeNotebookCell.codeNotebookCellId
150
+ ),
151
+ fromState: text("from_state").notNull(),
152
+ toState: text("to_state").notNull(),
153
+ transitionResult: text("transition_result"),
154
+ transitionReason: text("transition_reason"),
155
+ transitionedAt: timestamptz("transitioned_at"),
156
+ elaboration: text(),
157
+ ...housekeeping
158
+ }, (table2) => [
159
+ unique().on(table2.codeNotebookCellId, table2.fromState, table2.toState),
160
+ checkJSON(table2.transitionResult),
161
+ checkJSON(table2.elaboration)
162
+ ]);
163
+ var sqlpageFiles = table("sqlpage_files", {
164
+ path: text().primaryKey().notNull(),
165
+ contents: text().notNull(),
166
+ lastModified: numeric("last_modified").default(sql`(CURRENT_TIMESTAMP)`)
167
+ }, (table2) => []);
168
+ var surveilrTableSize = table("surveilr_table_size", {
169
+ tableName: text("table_name").primaryKey(),
170
+ tableSizeMb: real("table_size_mb")
171
+ }, (table2) => []);
172
+ var sqlpageAideNavigation = table("sqlpage_aide_navigation", {
173
+ path: text().notNull(),
174
+ caption: text().notNull(),
175
+ namespace: text().notNull(),
176
+ parentPath: text("parent_path"),
177
+ siblingOrder: integer("sibling_order"),
178
+ url: text(),
179
+ title: text(),
180
+ abbreviatedCaption: text("abbreviated_caption"),
181
+ description: text(),
182
+ elaboration: text()
183
+ }, (table2) => [
184
+ unique("unq_ns_path").on(table2.namespace, table2.parentPath, table2.path)
185
+ ]);
186
+ var partyType = table("party_type", {
187
+ partyTypeId: ulid("party_type_id").primaryKey().notNull(),
188
+ code: text().notNull(),
189
+ value: text().notNull(),
190
+ ...housekeeping
191
+ }, (table2) => [
192
+ unique("unq_party_type_code").on(table2.code)
193
+ ]);
194
+ var party = table("party", {
195
+ partyId: varchar("party_id").primaryKey().notNull(),
196
+ partyTypeId: ulid("party_type_id").notNull().references(
197
+ () => partyType.partyTypeId
198
+ ).$type(),
199
+ // ULID
200
+ partyName: text("party_name").notNull(),
201
+ elaboration: text(),
202
+ ...housekeeping
203
+ }, (table2) => [
204
+ index("idx_party__party_type_id__party_name").on(
205
+ table2.partyTypeId,
206
+ table2.partyName
207
+ )
208
+ ]);
209
+ var partyRelationType = table("party_relation_type", {
210
+ partyRelationTypeId: text("party_relation_type_id").primaryKey().notNull().$type(),
211
+ // ULID
212
+ code: text().notNull(),
213
+ value: text().notNull(),
214
+ ...housekeeping
215
+ }, (table2) => [
216
+ unique().on(table2.code)
217
+ ]);
218
+ var partyRelation = table("party_relation", {
219
+ partyRelationId: varchar("party_relation_id").primaryKey().notNull(),
220
+ partyId: text("party_id").notNull().references(() => party.partyId),
221
+ relatedPartyId: text("related_party_id").notNull().references(
222
+ () => party.partyId
223
+ ),
224
+ relationTypeId: text("relation_type_id").notNull().references(
225
+ () => partyRelationType.partyRelationTypeId
226
+ ).$type(),
227
+ // ULID
228
+ elaboration: text(),
229
+ ...housekeeping
230
+ }, (table2) => [
231
+ index("idx_party_relation__party_id__related_party_id__relation_type_id").on(
232
+ table2.partyId,
233
+ table2.relatedPartyId,
234
+ table2.relationTypeId
235
+ ),
236
+ unique().on(table2.partyId, table2.relatedPartyId, table2.relationTypeId),
237
+ checkJSON(table2.elaboration)
238
+ ]);
239
+ var genderType = table("gender_type", {
240
+ genderTypeId: ulid("gender_type_id").primaryKey().notNull(),
241
+ code: text().notNull(),
242
+ value: text().notNull(),
243
+ ...housekeeping
244
+ }, (table2) => [
245
+ unique().on(table2.code)
246
+ ]);
247
+ var sexType = table("sex_type", {
248
+ sexTypeId: ulid("sex_type_id").primaryKey().notNull(),
249
+ code: text().notNull(),
250
+ value: text().notNull(),
251
+ ...housekeeping
252
+ }, (table2) => [
253
+ unique().on(table2.code)
254
+ ]);
255
+ var personType = table("person_type", {
256
+ personTypeId: ulid("person_type_id").primaryKey().notNull(),
257
+ code: text().notNull(),
258
+ value: text().notNull(),
259
+ ...housekeeping
260
+ }, (table2) => [
261
+ unique().on(table2.code)
262
+ ]);
263
+ var person = table("person", {
264
+ personId: ulid("person_id").primaryKey().notNull(),
265
+ partyId: text("party_id").notNull().references(() => party.partyId),
266
+ personTypeId: ulid("person_type_id").notNull().references(
267
+ () => personType.personTypeId
268
+ ),
269
+ personFirstName: text("person_first_name").notNull(),
270
+ personMiddleName: text("person_middle_name"),
271
+ personLastName: text("person_last_name").notNull(),
272
+ previousName: text("previous_name"),
273
+ honorificPrefix: text("honorific_prefix"),
274
+ honorificSuffix: text("honorific_suffix"),
275
+ genderId: ulid("gender_id").notNull().references(
276
+ () => genderType.genderTypeId
277
+ ),
278
+ sexId: ulid("sex_id").notNull().references(() => sexType.sexTypeId),
279
+ elaboration: text(),
280
+ ...housekeeping
281
+ }, (table2) => [
282
+ checkJSON(table2.elaboration)
283
+ ]);
284
+ var organization = table("organization", {
285
+ organizationId: ulid("organization_id").primaryKey().notNull(),
286
+ partyId: text("party_id").notNull().references(() => party.partyId),
287
+ name: text().notNull(),
288
+ alias: text(),
289
+ description: text(),
290
+ license: text().notNull(),
291
+ federalTaxIdNum: text("federal_tax_id_num"),
292
+ registrationDate: date("registration_date").notNull(),
293
+ elaboration: text(),
294
+ ...housekeeping
295
+ }, (table2) => [
296
+ checkJSON(table2.elaboration)
297
+ ]);
298
+ var organizationRoleType = table("organization_role_type", {
299
+ organizationRoleTypeId: ulid("organization_role_type_id").primaryKey().notNull(),
300
+ code: text().notNull(),
301
+ value: text().notNull(),
302
+ ...housekeeping
303
+ }, (table2) => [
304
+ unique().on(table2.code)
305
+ ]);
306
+ var organizationRole = table("organization_role", {
307
+ organizationRoleId: text("organization_role_id").primaryKey().notNull(),
308
+ personId: text("person_id").notNull().references(() => party.partyId),
309
+ organizationId: text("organization_id").notNull().references(
310
+ () => party.partyId
311
+ ),
312
+ organizationRoleTypeId: ulid("organization_role_type_id").notNull().references(() => organizationRoleType.organizationRoleTypeId),
313
+ elaboration: text(),
314
+ ...housekeeping
315
+ }, (table2) => [
316
+ index(
317
+ "idx_organization_role__person_id__organization_id__organization_role_type_id"
318
+ ).on(table2.personId, table2.organizationId, table2.organizationRoleTypeId),
319
+ unique().on(table2.personId, table2.organizationId, table2.organizationRoleTypeId),
320
+ checkJSON(table2.elaboration)
321
+ ]);
322
+ var devicePartyRelationship = table("device_party_relationship", {
323
+ devicePartyRelationshipId: text("device_party_relationship_id").primaryKey().notNull(),
324
+ deviceId: text("device_id").notNull().references(() => device.deviceId),
325
+ partyId: text("party_id").notNull().references(() => party.partyId),
326
+ elaboration: text(),
327
+ ...housekeeping
328
+ }, (table2) => [
329
+ index("idx_device_party_relationship__device_id__party_id").on(
330
+ table2.deviceId,
331
+ table2.partyId
332
+ ),
333
+ unique().on(table2.deviceId, table2.partyId),
334
+ checkJSON(table2.elaboration)
335
+ ]);
336
+ var behavior = table("behavior", {
337
+ behaviorId: varchar("behavior_id").primaryKey().notNull(),
338
+ deviceId: text("device_id").notNull(),
339
+ behaviorName: text("behavior_name").notNull(),
340
+ behaviorConfJson: text("behavior_conf_json").notNull(),
341
+ assuranceSchemaId: text("assurance_schema_id"),
342
+ governance: text(),
343
+ ...housekeeping
344
+ }, (table2) => [
345
+ unique().on(table2.deviceId, table2.behaviorName),
346
+ checkJSON(table2.behaviorConfJson),
347
+ checkJSON(table2.governance)
348
+ ]);
349
+ var urIngestResourcePathMatchRule = table(
350
+ "ur_ingest_resource_path_match_rule",
351
+ {
352
+ urIngestResourcePathMatchRuleId: text(
353
+ "ur_ingest_resource_path_match_rule_id"
354
+ ).primaryKey().notNull(),
355
+ namespace: text().notNull(),
356
+ regex: text().notNull(),
357
+ flags: text().notNull(),
358
+ nature: text(),
359
+ priority: text(),
360
+ description: text(),
361
+ includeGlobPatterns: textArray("include_glob_patterns"),
362
+ excludeGlobPatterns: textArray("exclude_glob_patterns"),
363
+ elaboration: text(),
364
+ ...housekeeping
365
+ },
366
+ (table2) => [
367
+ checkJSON(table2.elaboration),
368
+ unique("unq_path_match_regex").on(table2.namespace, table2.regex)
369
+ ]
370
+ );
371
+ var urIngestResourcePathRewriteRule = table(
372
+ "ur_ingest_resource_path_rewrite_rule",
373
+ {
374
+ urIngestResourcePathRewriteRuleId: text(
375
+ "ur_ingest_resource_path_rewrite_rule_id"
376
+ ).primaryKey().notNull(),
377
+ namespace: text().notNull(),
378
+ regex: text().notNull(),
379
+ replace: text().notNull(),
380
+ priority: text(),
381
+ description: text(),
382
+ elaboration: text(),
383
+ ...housekeeping
384
+ },
385
+ (table2) => [
386
+ unique().on(table2.namespace, table2.regex, table2.replace),
387
+ checkJSON(table2.elaboration)
388
+ ]
389
+ );
390
+ var urIngestSession = table("ur_ingest_session", {
391
+ urIngestSessionId: text("ur_ingest_session_id").primaryKey().notNull(),
392
+ deviceId: text("device_id").notNull().references(() => device.deviceId),
393
+ behaviorId: text("behavior_id").references(() => behavior.behaviorId),
394
+ behaviorJson: text("behavior_json"),
395
+ ingestStartedAt: timestamptz("ingest_started_at").notNull(),
396
+ ingestFinishedAt: timestamptz("ingest_finished_at"),
397
+ sessionAgent: text("session_agent").notNull(),
398
+ elaboration: text(),
399
+ ...housekeeping
400
+ }, (table2) => [
401
+ unique().on(table2.deviceId, table2.createdAt),
402
+ checkJSON(table2.behaviorJson),
403
+ checkJSON(table2.sessionAgent),
404
+ checkJSON(table2.elaboration)
405
+ ]);
406
+ var urIngestSessionFsPath = table("ur_ingest_session_fs_path", {
407
+ urIngestSessionFsPathId: text("ur_ingest_session_fs_path_id").primaryKey().notNull(),
408
+ ingestSessionId: text("ingest_session_id").notNull().references(
409
+ () => urIngestSession.urIngestSessionId
410
+ ),
411
+ rootPath: text("root_path").notNull(),
412
+ includeGlobPatterns: textArray("include_glob_patterns"),
413
+ excludeGlobPatterns: textArray("exclude_glob_patterns"),
414
+ elaboration: text(),
415
+ ...housekeeping
416
+ }, (table2) => [
417
+ index("idx_ur_ingest_session_fs_path__ingest_session_id__root_path").on(
418
+ table2.ingestSessionId,
419
+ table2.rootPath
420
+ ),
421
+ unique().on(table2.ingestSessionId, table2.rootPath, table2.createdAt),
422
+ checkJSON(table2.elaboration)
423
+ ]);
424
+ var uniformResource = table("uniform_resource", {
425
+ uniformResourceId: text("uniform_resource_id").primaryKey().notNull(),
426
+ deviceId: text("device_id").notNull().references(() => device.deviceId),
427
+ ingestSessionId: text("ingest_session_id").notNull().references(
428
+ () => urIngestSession.urIngestSessionId
429
+ ),
430
+ ingestFsPathId: text("ingest_fs_path_id").references(
431
+ () => urIngestSessionFsPath.urIngestSessionFsPathId
432
+ ),
433
+ ingestSessionImapAcctFolderMessage: text(
434
+ "ingest_session_imap_acct_folder_message"
435
+ ).references(
436
+ () => urIngestSessionImapAcctFolderMessage.urIngestSessionImapAcctFolderMessageId
437
+ ),
438
+ ingestIssueAcctProjectId: text("ingest_issue_acct_project_id").references(
439
+ () => urIngestSessionPlmAcctProject.urIngestSessionPlmAcctProjectId
440
+ ),
441
+ uri: text().notNull(),
442
+ contentDigest: text("content_digest").notNull(),
443
+ content: blob(),
444
+ nature: text(),
445
+ sizeBytes: integer("size_bytes"),
446
+ lastModifiedAt: timestamptz("last_modified_at"),
447
+ contentFmBodyAttrs: text("content_fm_body_attrs"),
448
+ frontmatter: text(),
449
+ elaboration: text(),
450
+ ...housekeeping
451
+ }, (table2) => [
452
+ index("idx_uniform_resource__device_id__uri").on(table2.deviceId, table2.uri),
453
+ unique().on(table2.deviceId, table2.contentDigest, table2.uri, table2.sizeBytes),
454
+ checkJSON(table2.contentFmBodyAttrs),
455
+ checkJSON(table2.frontmatter),
456
+ checkJSON(table2.elaboration)
457
+ ]);
458
+ var uniformResourceTransform = table("uniform_resource_transform", {
459
+ uniformResourceTransformId: text("uniform_resource_transform_id").primaryKey().notNull(),
460
+ uniformResourceId: text("uniform_resource_id").notNull().references(
461
+ () => uniformResource.uniformResourceId
462
+ ),
463
+ uri: text().notNull(),
464
+ contentDigest: text("content_digest").notNull(),
465
+ content: text(),
466
+ nature: text(),
467
+ sizeBytes: integer("size_bytes"),
468
+ elaboration: text(),
469
+ ...housekeeping
470
+ }, (table2) => [
471
+ index("idx_uniform_resource_transform__uniform_resource_id__content_digest").on(table2.uniformResourceId, table2.contentDigest),
472
+ unique().on(table2.uniformResourceId, table2.contentDigest, table2.nature, table2.sizeBytes),
473
+ checkJSON(table2.elaboration)
474
+ ]);
475
+ var urIngestSessionFsPathEntry = table(
476
+ "ur_ingest_session_fs_path_entry",
477
+ {
478
+ urIngestSessionFsPathEntryId: text("ur_ingest_session_fs_path_entry_id").primaryKey().notNull(),
479
+ ingestSessionId: text("ingest_session_id").notNull().references(
480
+ () => urIngestSession.urIngestSessionId
481
+ ),
482
+ ingestFsPathId: text("ingest_fs_path_id").notNull().references(
483
+ () => urIngestSessionFsPath.urIngestSessionFsPathId
484
+ ),
485
+ uniformResourceId: text("uniform_resource_id").references(
486
+ () => uniformResource.uniformResourceId
487
+ ),
488
+ filePathAbs: text("file_path_abs").notNull(),
489
+ filePathRelParent: text("file_path_rel_parent").notNull(),
490
+ filePathRel: text("file_path_rel").notNull(),
491
+ fileBasename: text("file_basename").notNull(),
492
+ fileExtn: text("file_extn"),
493
+ capturedExecutable: text("captured_executable"),
494
+ urStatus: text("ur_status"),
495
+ urDiagnostics: text("ur_diagnostics"),
496
+ urTransformations: text("ur_transformations"),
497
+ elaboration: text(),
498
+ ...housekeeping
499
+ },
500
+ (table2) => [
501
+ index(
502
+ "idx_ur_ingest_session_fs_path_entry__ingest_session_id__file_path_abs"
503
+ ).on(table2.ingestSessionId, table2.filePathAbs),
504
+ unique(
505
+ "uq_ur_ingest_session_fs_path_entry__ingest_session_id__ingest_fs_path_id__file_path_abs"
506
+ ).on(table2.ingestSessionId, table2.ingestFsPathId, table2.filePathAbs),
507
+ checkJSON(table2.capturedExecutable),
508
+ checkJSON(table2.urDiagnostics),
509
+ checkJSON(table2.urTransformations),
510
+ checkJSON(table2.elaboration)
511
+ ]
512
+ );
513
+ var urIngestSessionTask = table("ur_ingest_session_task", {
514
+ urIngestSessionTaskId: text("ur_ingest_session_task_id").primaryKey().notNull(),
515
+ ingestSessionId: text("ingest_session_id").notNull().references(
516
+ () => urIngestSession.urIngestSessionId
517
+ ),
518
+ uniformResourceId: text("uniform_resource_id").references(
519
+ () => uniformResource.uniformResourceId
520
+ ),
521
+ capturedExecutable: text("captured_executable").notNull(),
522
+ urStatus: text("ur_status"),
523
+ urDiagnostics: text("ur_diagnostics"),
524
+ urTransformations: text("ur_transformations"),
525
+ elaboration: text(),
526
+ ...housekeeping
527
+ }, (table2) => [
528
+ index("idx_ur_ingest_session_task__ingest_session_id").on(
529
+ table2.ingestSessionId
530
+ ),
531
+ checkJSON(table2.capturedExecutable),
532
+ checkJSON(table2.urDiagnostics),
533
+ checkJSON(table2.urTransformations),
534
+ checkJSON(table2.elaboration)
535
+ ]);
536
+ var urIngestSessionImapAccount = table(
537
+ "ur_ingest_session_imap_account",
538
+ {
539
+ urIngestSessionImapAccountId: text("ur_ingest_session_imap_account_id").primaryKey().notNull(),
540
+ ingestSessionId: text("ingest_session_id").notNull().references(
541
+ () => urIngestSession.urIngestSessionId
542
+ ),
543
+ email: text(),
544
+ password: text(),
545
+ host: text(),
546
+ elaboration: text(),
547
+ ...housekeeping
548
+ },
549
+ (table2) => [
550
+ index("idx_ur_ingest_session_imap_account__ingest_session_id__email").on(
551
+ table2.ingestSessionId,
552
+ table2.email
553
+ ),
554
+ unique().on(table2.ingestSessionId, table2.email)
555
+ ]
556
+ );
557
+ var urIngestSessionImapAcctFolder = table(
558
+ "ur_ingest_session_imap_acct_folder",
559
+ {
560
+ urIngestSessionImapAcctFolderId: text(
561
+ "ur_ingest_session_imap_acct_folder_id"
562
+ ).primaryKey().notNull(),
563
+ ingestSessionId: text("ingest_session_id").notNull().references(
564
+ () => urIngestSession.urIngestSessionId
565
+ ),
566
+ ingestAccountId: text("ingest_account_id").notNull().references(
567
+ () => urIngestSessionImapAccount.urIngestSessionImapAccountId
568
+ ),
569
+ folderName: text("folder_name").notNull(),
570
+ includeSenders: textArray("include_senders"),
571
+ excludeSenders: textArray("exclude_senders"),
572
+ elaboration: text(),
573
+ ...housekeeping
574
+ },
575
+ (table2) => [
576
+ index(
577
+ "idx_ur_ingest_session_imap_acct_folder__ingest_session_id__folder_name"
578
+ ).on(table2.ingestSessionId, table2.folderName),
579
+ unique().on(table2.ingestAccountId, table2.folderName)
580
+ ]
581
+ );
582
+ var urIngestSessionImapAcctFolderMessage = table(
583
+ "ur_ingest_session_imap_acct_folder_message",
584
+ {
585
+ urIngestSessionImapAcctFolderMessageId: text(
586
+ "ur_ingest_session_imap_acct_folder_message_id"
587
+ ).primaryKey().notNull(),
588
+ ingestSessionId: text("ingest_session_id").notNull().references(
589
+ () => urIngestSession.urIngestSessionId
590
+ ),
591
+ ingestImapAcctFolderId: text("ingest_imap_acct_folder_id").notNull().references(
592
+ () => urIngestSessionImapAcctFolder.urIngestSessionImapAcctFolderId
593
+ ),
594
+ message: text().notNull(),
595
+ messageId: text("message_id").notNull(),
596
+ subject: text().notNull(),
597
+ from: text().notNull(),
598
+ cc: text().notNull(),
599
+ bcc: text().notNull(),
600
+ status: textArray().notNull(),
601
+ date: date(),
602
+ emailReferences: text("email_references").notNull(),
603
+ ...housekeeping
604
+ },
605
+ (table2) => [
606
+ index("idx_ur_ingest_session_imap_acct_folder_message__ingest_session_id").on(table2.ingestSessionId),
607
+ unique().on(table2.message, table2.messageId),
608
+ checkJSON(table2.cc),
609
+ checkJSON(table2.bcc),
610
+ checkJSON(table2.emailReferences)
611
+ ]
612
+ );
613
+ var urIngestSessionPlmAccount = table(
614
+ "ur_ingest_session_plm_account",
615
+ {
616
+ urIngestSessionPlmAccountId: varchar("ur_ingest_session_plm_account_id").primaryKey().notNull(),
617
+ ingestSessionId: text("ingest_session_id").notNull().references(
618
+ () => urIngestSession.urIngestSessionId
619
+ ),
620
+ provider: text().notNull(),
621
+ orgName: text("org_name").notNull(),
622
+ elaboration: text(),
623
+ ...housekeeping
624
+ },
625
+ (table2) => [
626
+ unique().on(table2.provider, table2.orgName),
627
+ checkJSON(table2.elaboration)
628
+ ]
629
+ );
630
+ var urIngestSessionPlmAcctProject = table(
631
+ "ur_ingest_session_plm_acct_project",
632
+ {
633
+ urIngestSessionPlmAcctProjectId: varchar(
634
+ "ur_ingest_session_plm_acct_project_id"
635
+ ).primaryKey().notNull(),
636
+ ingestSessionId: text("ingest_session_id").notNull().references(
637
+ () => urIngestSession.urIngestSessionId
638
+ ),
639
+ ingestAccountId: text("ingest_account_id").notNull().references(
640
+ () => urIngestSessionPlmAccount.urIngestSessionPlmAccountId
641
+ ),
642
+ parentProjectId: text("parent_project_id"),
643
+ name: text().notNull(),
644
+ description: text(),
645
+ id: text(),
646
+ key: text(),
647
+ elaboration: text(),
648
+ ...housekeeping
649
+ },
650
+ (table2) => [
651
+ unique().on(table2.name, table2.description),
652
+ checkJSON(table2.elaboration)
653
+ ]
654
+ );
655
+ var urIngestSessionPlmUser = table("ur_ingest_session_plm_user", {
656
+ urIngestSessionPlmUserId: varchar("ur_ingest_session_plm_user_id").primaryKey().notNull(),
657
+ userId: text("user_id").notNull(),
658
+ login: text().notNull(),
659
+ email: text(),
660
+ name: text(),
661
+ url: text().notNull(),
662
+ elaboration: text(),
663
+ ...housekeeping
664
+ }, (table2) => [
665
+ unique().on(table2.userId, table2.login),
666
+ checkJSON(table2.elaboration)
667
+ ]);
668
+ var urIngestSessionPlmIssueType = table(
669
+ "ur_ingest_session_plm_issue_type",
670
+ {
671
+ urIngestSessionPlmIssueTypeId: varchar("ur_ingest_session_plm_issue_type_id").primaryKey().notNull(),
672
+ avatarId: text("avatar_id"),
673
+ description: text().notNull(),
674
+ iconUrl: text("icon_url").notNull(),
675
+ id: text().notNull(),
676
+ name: text().notNull(),
677
+ subtask: integer().notNull(),
678
+ url: text().notNull(),
679
+ elaboration: text(),
680
+ ...housekeeping
681
+ },
682
+ (table2) => [
683
+ unique().on(table2.id, table2.name),
684
+ checkJSON(table2.elaboration)
685
+ ]
686
+ );
687
+ var urIngestSessionPlmAcctProjectIssue = table(
688
+ "ur_ingest_session_plm_acct_project_issue",
689
+ {
690
+ urIngestSessionPlmAcctProjectIssueId: varchar(
691
+ "ur_ingest_session_plm_acct_project_issue_id"
692
+ ).primaryKey().notNull(),
693
+ ingestSessionId: text("ingest_session_id").notNull().references(
694
+ () => urIngestSession.urIngestSessionId
695
+ ),
696
+ urIngestSessionPlmAcctProjectId: text(
697
+ "ur_ingest_session_plm_acct_project_id"
698
+ ).notNull().references(
699
+ () => urIngestSessionPlmAcctProject.urIngestSessionPlmAcctProjectId
700
+ ),
701
+ uniformResourceId: text("uniform_resource_id").references(
702
+ () => uniformResource.uniformResourceId
703
+ ),
704
+ issueId: text("issue_id").notNull(),
705
+ issueNumber: integer("issue_number"),
706
+ parentIssueId: text("parent_issue_id"),
707
+ title: text().notNull(),
708
+ body: text(),
709
+ bodyText: text("body_text"),
710
+ bodyHtml: text("body_html"),
711
+ state: text().notNull(),
712
+ assignedTo: text("assigned_to"),
713
+ user: text().notNull().references(
714
+ () => urIngestSessionPlmUser.urIngestSessionPlmUserId
715
+ ),
716
+ url: text().notNull(),
717
+ closedAt: text("closed_at"),
718
+ issueTypeId: text("issue_type_id").references(
719
+ () => urIngestSessionPlmIssueType.urIngestSessionPlmIssueTypeId
720
+ ),
721
+ timeEstimate: integer("time_estimate"),
722
+ aggregateTimeEstimate: integer("aggregate_time_estimate"),
723
+ timeOriginalEstimate: integer("time_original_estimate"),
724
+ timeSpent: integer("time_spent"),
725
+ aggregateTimeSpent: integer("aggregate_time_spent"),
726
+ aggregateTimeOriginalEstimate: integer("aggregate_time_original_estimate"),
727
+ workratio: integer(),
728
+ currentProgress: integer("current_progress"),
729
+ totalProgress: integer("total_progress"),
730
+ resolutionName: text("resolution_name"),
731
+ resolutionDate: text("resolution_date"),
732
+ elaboration: text(),
733
+ ...housekeeping
734
+ },
735
+ (table2) => [
736
+ unique().on(table2.title, table2.issueId, table2.state, table2.assignedTo),
737
+ checkJSON(table2.elaboration)
738
+ ]
739
+ );
740
+ var urIngestSessionPlmAcctLabel = table(
741
+ "ur_ingest_session_plm_acct_label",
742
+ {
743
+ urIngestSessionPlmAcctLabelId: varchar("ur_ingest_session_plm_acct_label_id").primaryKey().notNull(),
744
+ urIngestSessionPlmAcctProjectId: text(
745
+ "ur_ingest_session_plm_acct_project_id"
746
+ ).notNull().references(
747
+ () => urIngestSessionPlmAcctProject.urIngestSessionPlmAcctProjectId
748
+ ),
749
+ urIngestSessionPlmAcctProjectIssueId: text(
750
+ "ur_ingest_session_plm_acct_project_issue_id"
751
+ ).notNull().references(
752
+ () => urIngestSessionPlmAcctProjectIssue.urIngestSessionPlmAcctProjectIssueId
753
+ ),
754
+ label: text().notNull(),
755
+ elaboration: text(),
756
+ ...housekeeping
757
+ },
758
+ (table2) => [
759
+ checkJSON(table2.elaboration)
760
+ ]
761
+ );
762
+ var urIngestSessionPlmMilestone = table(
763
+ "ur_ingest_session_plm_milestone",
764
+ {
765
+ urIngestSessionPlmMilestoneId: varchar("ur_ingest_session_plm_milestone_id").primaryKey().notNull(),
766
+ urIngestSessionPlmAcctProjectId: text(
767
+ "ur_ingest_session_plm_acct_project_id"
768
+ ).notNull().references(
769
+ () => urIngestSessionPlmAcctProject.urIngestSessionPlmAcctProjectId
770
+ ),
771
+ title: text().notNull(),
772
+ milestoneId: text("milestone_id").notNull(),
773
+ url: text().notNull(),
774
+ htmlUrl: text("html_url").notNull(),
775
+ openIssues: integer("open_issues"),
776
+ closedIssues: integer("closed_issues"),
777
+ dueOn: timestamptz("due_on"),
778
+ closedAt: timestamptz("closed_at"),
779
+ elaboration: text(),
780
+ ...housekeeping
781
+ },
782
+ (table2) => [
783
+ checkJSON(table2.elaboration)
784
+ ]
785
+ );
786
+ var urIngestSessionPlmAcctRelationship = table(
787
+ "ur_ingest_session_plm_acct_relationship",
788
+ {
789
+ urIngestSessionPlmAcctRelationshipId: varchar(
790
+ "ur_ingest_session_plm_acct_relationship_id"
791
+ ).primaryKey().notNull(),
792
+ urIngestSessionPlmAcctProjectIdPrime: text(
793
+ "ur_ingest_session_plm_acct_project_id_prime"
794
+ ).notNull().references(
795
+ () => urIngestSessionPlmAcctProject.urIngestSessionPlmAcctProjectId
796
+ ),
797
+ urIngestSessionPlmAcctProjectIdRelated: text(
798
+ "ur_ingest_session_plm_acct_project_id_related"
799
+ ).notNull(),
800
+ urIngestSessionPlmAcctProjectIssueIdPrime: text(
801
+ "ur_ingest_session_plm_acct_project_issue_id_prime"
802
+ ).notNull().references(
803
+ () => urIngestSessionPlmAcctProjectIssue.urIngestSessionPlmAcctProjectIssueId
804
+ ),
805
+ urIngestSessionPlmAcctProjectIssueIdRelated: text(
806
+ "ur_ingest_session_plm_acct_project_issue_id_related"
807
+ ).notNull(),
808
+ relationship: text(),
809
+ elaboration: text(),
810
+ ...housekeeping
811
+ },
812
+ (table2) => [
813
+ checkJSON(table2.elaboration)
814
+ ]
815
+ );
816
+ var urIngestSessionPlmComment = table(
817
+ "ur_ingest_session_plm_comment",
818
+ {
819
+ urIngestSessionPlmCommentId: varchar("ur_ingest_session_plm_comment_id").primaryKey().notNull(),
820
+ urIngestSessionPlmAcctProjectIssueId: text(
821
+ "ur_ingest_session_plm_acct_project_issue_id"
822
+ ).notNull().references(
823
+ () => urIngestSessionPlmAcctProjectIssue.urIngestSessionPlmAcctProjectIssueId
824
+ ),
825
+ commentId: text("comment_id").notNull(),
826
+ nodeId: text("node_id").notNull(),
827
+ url: text().notNull(),
828
+ body: text(),
829
+ bodyText: text("body_text"),
830
+ bodyHtml: text("body_html"),
831
+ user: text().notNull().references(
832
+ () => urIngestSessionPlmUser.urIngestSessionPlmUserId
833
+ ),
834
+ elaboration: text(),
835
+ ...housekeeping
836
+ },
837
+ (table2) => [
838
+ unique().on(table2.commentId, table2.url, table2.body),
839
+ checkJSON(table2.elaboration)
840
+ ]
841
+ );
842
+ var urIngestSessionPlmReaction = table(
843
+ "ur_ingest_session_plm_reaction",
844
+ {
845
+ urIngestSessionPlmReactionId: varchar("ur_ingest_session_plm_reaction_id").primaryKey().notNull(),
846
+ reactionId: text("reaction_id").notNull(),
847
+ reactionType: text("reaction_type").notNull(),
848
+ elaboration: text(),
849
+ ...housekeeping
850
+ },
851
+ (table2) => [
852
+ unique().on(table2.reactionType),
853
+ checkJSON(table2.elaboration)
854
+ ]
855
+ );
856
+ var urIngestSessionPlmIssueReaction = table(
857
+ "ur_ingest_session_plm_issue_reaction",
858
+ {
859
+ urIngestSessionPlmIssueReactionId: varchar(
860
+ "ur_ingest_session_plm_issue_reaction_id"
861
+ ).primaryKey().notNull(),
862
+ urIngestPlmReactionId: text("ur_ingest_plm_reaction_id").notNull().references(() => urIngestSessionPlmReaction.urIngestSessionPlmReactionId),
863
+ urIngestPlmIssueId: text("ur_ingest_plm_issue_id").notNull().references(
864
+ () => urIngestSessionPlmAcctProjectIssue.urIngestSessionPlmAcctProjectIssueId
865
+ ),
866
+ count: integer().default(1),
867
+ elaboration: text(),
868
+ ...housekeeping
869
+ },
870
+ (table2) => [
871
+ unique().on(table2.urIngestPlmIssueId, table2.urIngestPlmReactionId),
872
+ checkJSON(table2.elaboration)
873
+ ]
874
+ );
875
+ var urIngestSessionAttachment = table("ur_ingest_session_attachment", {
876
+ urIngestSessionAttachmentId: text("ur_ingest_session_attachment_id").primaryKey().notNull(),
877
+ uniformResourceId: text("uniform_resource_id").references(
878
+ () => uniformResource.uniformResourceId
879
+ ),
880
+ name: text(),
881
+ uri: text().notNull(),
882
+ content: blob(),
883
+ nature: text(),
884
+ size: integer(),
885
+ checksum: text(),
886
+ elaboration: text(),
887
+ ...housekeeping
888
+ }, (table2) => [
889
+ index("idx_ur_ingest_session_attachment__uniform_resource_id__content").on(
890
+ table2.uniformResourceId,
891
+ table2.content
892
+ ),
893
+ unique().on(table2.uniformResourceId, table2.checksum, table2.nature, table2.size)
894
+ ]);
895
+ var urIngestSessionUdiPgpSql = table("ur_ingest_session_udi_pgp_sql", {
896
+ urIngestSessionUdiPgpSqlId: text("ur_ingest_session_udi_pgp_sql_id").primaryKey().notNull(),
897
+ sql: text().notNull(),
898
+ nature: text().notNull(),
899
+ content: blob(),
900
+ behaviour: text(),
901
+ queryError: text("query_error"),
902
+ uniformResourceId: text("uniform_resource_id").references(
903
+ () => uniformResource.uniformResourceId
904
+ ),
905
+ ingestSessionId: text("ingest_session_id").references(
906
+ () => urIngestSession.urIngestSessionId
907
+ ),
908
+ ...housekeeping
909
+ }, (table2) => [
910
+ index("idx_ur_ingest_session_udi_pgp_sql__ingest_session_id").on(
911
+ table2.ingestSessionId
912
+ ),
913
+ unique().on(table2.sql, table2.ingestSessionId),
914
+ checkJSON(table2.behaviour)
915
+ ]);
916
+ var orchestrationNature = table("orchestration_nature", {
917
+ orchestrationNatureId: text("orchestration_nature_id").primaryKey().notNull(),
918
+ nature: text().notNull(),
919
+ elaboration: text(),
920
+ ...housekeeping
921
+ }, (table2) => [
922
+ index("idx_orchestration_nature__orchestration_nature_id__nature").on(
923
+ table2.orchestrationNatureId,
924
+ table2.nature
925
+ ),
926
+ unique().on(table2.orchestrationNatureId, table2.nature)
927
+ ]);
928
+ var orchestrationSession = table("orchestration_session", {
929
+ orchestrationSessionId: text("orchestration_session_id").primaryKey().notNull(),
930
+ deviceId: text("device_id").notNull().references(() => device.deviceId),
931
+ orchestrationNatureId: text("orchestration_nature_id").notNull().references(
932
+ () => orchestrationNature.orchestrationNatureId
933
+ ),
934
+ version: text().notNull(),
935
+ orchStartedAt: timestamptz("orch_started_at"),
936
+ orchFinishedAt: timestamptz("orch_finished_at"),
937
+ elaboration: text(),
938
+ argsJson: text("args_json"),
939
+ diagnosticsJson: text("diagnostics_json"),
940
+ diagnosticsMd: text("diagnostics_md")
941
+ }, (table2) => [
942
+ checkJSON(table2.elaboration),
943
+ checkJSON(table2.argsJson),
944
+ checkJSON(table2.diagnosticsJson)
945
+ ]);
946
+ var orchestrationSessionEntry = table("orchestration_session_entry", {
947
+ orchestrationSessionEntryId: text("orchestration_session_entry_id").primaryKey().notNull(),
948
+ sessionId: text("session_id").notNull().references(
949
+ () => orchestrationSession.orchestrationSessionId
950
+ ),
951
+ ingestSrc: text("ingest_src").notNull(),
952
+ ingestTableName: text("ingest_table_name"),
953
+ elaboration: text()
954
+ }, (table2) => []);
955
+ var orchestrationSessionState = table("orchestration_session_state", {
956
+ orchestrationSessionStateId: text("orchestration_session_state_id").primaryKey().notNull(),
957
+ sessionId: text("session_id").notNull().references(
958
+ () => orchestrationSession.orchestrationSessionId
959
+ ),
960
+ sessionEntryId: text("session_entry_id").references(
961
+ () => orchestrationSessionEntry.orchestrationSessionEntryId
962
+ ),
963
+ fromState: text("from_state").notNull(),
964
+ toState: text("to_state").notNull(),
965
+ transitionResult: text("transition_result"),
966
+ transitionReason: text("transition_reason"),
967
+ transitionedAt: timestamptz("transitioned_at"),
968
+ elaboration: text()
969
+ }, (table2) => [
970
+ unique().on(table2.orchestrationSessionStateId, table2.fromState, table2.toState)
971
+ ]);
972
+ var orchestrationSessionExec = table("orchestration_session_exec", {
973
+ orchestrationSessionExecId: text("orchestration_session_exec_id").primaryKey().notNull(),
974
+ execNature: text("exec_nature").notNull(),
975
+ sessionId: text("session_id").notNull().references(
976
+ () => orchestrationSession.orchestrationSessionId
977
+ ),
978
+ sessionEntryId: text("session_entry_id").references(
979
+ () => orchestrationSessionEntry.orchestrationSessionEntryId
980
+ ),
981
+ parentExecId: text("parent_exec_id"),
982
+ namespace: text(),
983
+ execIdentity: text("exec_identity"),
984
+ execCode: text("exec_code").notNull(),
985
+ execStatus: integer("exec_status").notNull(),
986
+ inputText: text("input_text"),
987
+ execErrorText: text("exec_error_text"),
988
+ outputText: text("output_text"),
989
+ outputNature: text("output_nature"),
990
+ narrativeMd: text("narrative_md"),
991
+ elaboration: text()
992
+ }, (table2) => [
993
+ foreignKey(() => ({
994
+ columns: [table2.parentExecId],
995
+ foreignColumns: [table2.orchestrationSessionExecId],
996
+ name: "orchestration_session_exec_parent_exec_id_orchestration_session_exec_orchestration_session_exec_id_fk"
997
+ }))
998
+ ]);
999
+ var orchestrationSessionIssue = table("orchestration_session_issue", {
1000
+ orchestrationSessionIssueId: numeric("orchestration_session_issue_id").primaryKey().notNull(),
1001
+ sessionId: text("session_id").notNull().references(
1002
+ () => orchestrationSession.orchestrationSessionId
1003
+ ),
1004
+ sessionEntryId: text("session_entry_id").references(
1005
+ () => orchestrationSessionEntry.orchestrationSessionEntryId
1006
+ ),
1007
+ issueType: text("issue_type").notNull(),
1008
+ issueMessage: text("issue_message").notNull(),
1009
+ issueRow: integer("issue_row"),
1010
+ issueColumn: text("issue_column"),
1011
+ invalidValue: text("invalid_value"),
1012
+ remediation: text(),
1013
+ elaboration: text()
1014
+ }, (table2) => []);
1015
+ var orchestrationSessionIssueRelation = table(
1016
+ "orchestration_session_issue_relation",
1017
+ {
1018
+ orchestrationSessionIssueRelationId: numeric(
1019
+ "orchestration_session_issue_relation_id"
1020
+ ).primaryKey().notNull(),
1021
+ issueIdPrime: numeric("issue_id_prime").notNull().references(
1022
+ () => orchestrationSessionIssue.orchestrationSessionIssueId
1023
+ ),
1024
+ issueIdRel: text("issue_id_rel").notNull(),
1025
+ relationshipNature: text("relationship_nature").notNull(),
1026
+ elaboration: text()
1027
+ },
1028
+ (table2) => []
1029
+ );
1030
+ var orchestrationSessionLog = table("orchestration_session_log", {
1031
+ orchestrationSessionLogId: numeric("orchestration_session_log_id").primaryKey().notNull(),
1032
+ category: text(),
1033
+ parentExecId: numeric("parent_exec_id"),
1034
+ content: text().notNull(),
1035
+ siblingOrder: integer("sibling_order"),
1036
+ elaboration: text()
1037
+ }, (table2) => [
1038
+ foreignKey(() => ({
1039
+ columns: [table2.parentExecId],
1040
+ foreignColumns: [table2.orchestrationSessionLogId],
1041
+ name: "orchestration_session_log_parent_exec_id_orchestration_session_log_orchestration_session_log_id_fk"
1042
+ }))
1043
+ ]);
1044
+ var uniformResourceGraph = table("uniform_resource_graph", {
1045
+ name: text().primaryKey().notNull(),
1046
+ elaboration: text()
1047
+ }, (table2) => []);
1048
+ var uniformResourceEdge = table("uniform_resource_edge", {
1049
+ graphName: text("graph_name").notNull().references(
1050
+ () => uniformResourceGraph.name
1051
+ ),
1052
+ nature: text().notNull(),
1053
+ nodeId: text("node_id").notNull(),
1054
+ uniformResourceId: text("uniform_resource_id").notNull().references(
1055
+ () => uniformResource.uniformResourceId
1056
+ ),
1057
+ elaboration: text()
1058
+ }, (table2) => [
1059
+ index("idx_uniform_resource_edge__uniform_resource_id").on(
1060
+ table2.uniformResourceId
1061
+ ),
1062
+ unique().on(table2.graphName, table2.nature, table2.nodeId, table2.uniformResourceId)
1063
+ ]);
1064
+ var surveilrOsqueryMsNode = table("surveilr_osquery_ms_node", {
1065
+ surveilrOsqueryMsNodeId: text("surveilr_osquery_ms_node_id").primaryKey().notNull(),
1066
+ nodeKey: text("node_key").notNull(),
1067
+ hostIdentifier: text("host_identifier").notNull(),
1068
+ tlsCertSubject: text("tls_cert_subject"),
1069
+ osVersion: text("os_version").notNull(),
1070
+ platform: text().notNull(),
1071
+ lastSeen: numeric("last_seen").notNull(),
1072
+ status: text().default("active").notNull(),
1073
+ osqueryVersion: text("osquery_version"),
1074
+ osqueryBuildPlatform: text("osquery_build_platform").notNull(),
1075
+ deviceId: text("device_id").notNull().references(() => device.deviceId),
1076
+ behaviorId: text("behavior_id").references(() => behavior.behaviorId),
1077
+ accelerate: integer().default(60).notNull(),
1078
+ ...housekeeping
1079
+ }, (table2) => [
1080
+ index("idx_surveilr_osquery_ms_node__node_key").on(table2.nodeKey),
1081
+ unique().on(table2.hostIdentifier, table2.osVersion),
1082
+ unique().on(table2.nodeKey)
1083
+ ]);
1084
+ var urIngestSessionOsqueryMsLog = table(
1085
+ "ur_ingest_session_osquery_ms_log",
1086
+ {
1087
+ urIngestSessionOsqueryMsLogId: text("ur_ingest_session_osquery_ms_log_id").primaryKey().notNull(),
1088
+ nodeKey: text("node_key").notNull().references(
1089
+ () => surveilrOsqueryMsNode.nodeKey
1090
+ ),
1091
+ logType: text("log_type").notNull(),
1092
+ logData: text("log_data").notNull(),
1093
+ appliedJqFilters: text("applied_jq_filters"),
1094
+ ...housekeeping
1095
+ },
1096
+ (table2) => [
1097
+ unique().on(table2.nodeKey, table2.logType, table2.logData)
1098
+ ]
1099
+ );
1100
+ var osqueryPolicy = table("osquery_policy", {
1101
+ osqueryPolicyId: text("osquery_policy_id").primaryKey().notNull(),
1102
+ policyGroup: text("policy_group"),
1103
+ policyName: text("policy_name").notNull(),
1104
+ osqueryCode: text("osquery_code").notNull(),
1105
+ policyDescription: text("policy_description").notNull(),
1106
+ policyPassLabel: text("policy_pass_label").default("Pass").notNull(),
1107
+ policyFailLabel: text("policy_fail_label").default("Fail").notNull(),
1108
+ policyPassRemarks: text("policy_pass_remarks"),
1109
+ policyFailRemarks: text("policy_fail_remarks"),
1110
+ osqueryPlatforms: text("osquery_platforms"),
1111
+ ...housekeeping
1112
+ }, (table2) => [
1113
+ unique().on(table2.policyName, table2.osqueryCode)
1114
+ ]);
1115
+ var surveilrOsqueryMsDistributedQuery = table(
1116
+ "surveilr_osquery_ms_distributed_query",
1117
+ {
1118
+ queryId: text("query_id").primaryKey().notNull(),
1119
+ nodeKey: text("node_key").notNull().references(
1120
+ () => surveilrOsqueryMsNode.nodeKey
1121
+ ),
1122
+ queryName: text("query_name").notNull(),
1123
+ querySql: text("query_sql").notNull(),
1124
+ discoveryQuery: text("discovery_query"),
1125
+ status: text().notNull(),
1126
+ elaboration: text(),
1127
+ interval: integer().notNull(),
1128
+ ...housekeeping
1129
+ },
1130
+ (table2) => []
1131
+ );
1132
+ var surveilrOsqueryMsDistributedResult = table(
1133
+ "surveilr_osquery_ms_distributed_result",
1134
+ {
1135
+ surveilrOsqueryMsDistributedResultId: text(
1136
+ "surveilr_osquery_ms_distributed_result_id"
1137
+ ).primaryKey().notNull(),
1138
+ queryId: text("query_id").notNull().references(
1139
+ () => surveilrOsqueryMsDistributedQuery.queryId
1140
+ ),
1141
+ nodeKey: text("node_key").notNull().references(
1142
+ () => surveilrOsqueryMsNode.nodeKey
1143
+ ),
1144
+ results: text().notNull(),
1145
+ statusCode: integer("status_code").notNull(),
1146
+ ...housekeeping
1147
+ },
1148
+ (table2) => []
1149
+ );
1150
+ var surveilrOsqueryMsCarve = table("surveilr_osquery_ms_carve", {
1151
+ surveilrOsqueryMsCarveId: text("surveilr_osquery_ms_carve_id").primaryKey().notNull(),
1152
+ nodeKey: text("node_key").notNull().references(
1153
+ () => surveilrOsqueryMsNode.nodeKey
1154
+ ),
1155
+ sessionId: text("session_id").notNull(),
1156
+ carveGuid: text("carve_guid").notNull(),
1157
+ carveSize: integer("carve_size").notNull(),
1158
+ blockCount: integer("block_count").notNull(),
1159
+ blockSize: integer("block_size").notNull(),
1160
+ receivedBlocks: integer("received_blocks").default(0).notNull(),
1161
+ carvePath: text("carve_path"),
1162
+ status: text().notNull(),
1163
+ startTime: numeric("start_time").notNull(),
1164
+ completionTime: numeric("completion_time"),
1165
+ elaboration: text(),
1166
+ ...housekeeping
1167
+ }, (table2) => [
1168
+ unique().on(table2.sessionId),
1169
+ unique().on(table2.carveGuid)
1170
+ ]);
1171
+ var surveilrOsqueryMsCarvedExtractedFile = table(
1172
+ "surveilr_osquery_ms_carved_extracted_file",
1173
+ {
1174
+ surveilrOsqueryMsCarvedExtractedFileId: text(
1175
+ "surveilr_osquery_ms_carved_extracted_file_id"
1176
+ ).primaryKey().notNull(),
1177
+ carveGuid: text("carve_guid").notNull().references(
1178
+ () => surveilrOsqueryMsCarve.carveGuid
1179
+ ),
1180
+ path: text().notNull(),
1181
+ sizeBytes: integer("size_bytes").notNull(),
1182
+ contentDigest: text("content_digest").notNull(),
1183
+ nature: text(),
1184
+ extractedAt: timestamptz("extracted_at").notNull(),
1185
+ ...housekeeping
1186
+ },
1187
+ (table2) => [
1188
+ index("idx_surveilr_osquery_ms_carved_extracted_file__path__carve_guid").on(
1189
+ table2.path,
1190
+ table2.carveGuid
1191
+ )
1192
+ ]
1193
+ );
1194
+ var surveilrSnmpDevice = table("surveilr_snmp_device", {
1195
+ surveilrSnmpDeviceId: text("surveilr_snmp_device_id").primaryKey().notNull(),
1196
+ deviceKey: text("device_key").notNull(),
1197
+ snmpHost: text("snmp_host").notNull(),
1198
+ snmpPort: integer("snmp_port").default(161).notNull(),
1199
+ snmpCommunity: text("snmp_community").notNull(),
1200
+ snmpVersion: text("snmp_version").default("2c").notNull(),
1201
+ snmpTimeout: integer("snmp_timeout").default(5).notNull(),
1202
+ snmpRetries: integer("snmp_retries").default(3).notNull(),
1203
+ deviceType: text("device_type"),
1204
+ deviceDescription: text("device_description"),
1205
+ lastSeen: numeric("last_seen").notNull(),
1206
+ status: text().default("active").notNull(),
1207
+ deviceId: text("device_id").notNull().references(() => device.deviceId),
1208
+ behaviorId: text("behavior_id").references(() => behavior.behaviorId),
1209
+ elaboration: text(),
1210
+ ...housekeeping
1211
+ }, (table2) => [
1212
+ index("idx_surveilr_snmp_device__device_key").on(table2.deviceKey),
1213
+ unique().on(table2.snmpHost, table2.snmpPort),
1214
+ unique().on(table2.deviceKey),
1215
+ checkJSON(table2.elaboration)
1216
+ ]);
1217
+ var surveilrSnmpCollection = table("surveilr_snmp_collection", {
1218
+ surveilrSnmpCollectionId: text("surveilr_snmp_collection_id").primaryKey().notNull(),
1219
+ deviceKey: text("device_key").notNull().references(
1220
+ () => surveilrSnmpDevice.deviceKey
1221
+ ),
1222
+ oid: text().notNull(),
1223
+ oidValue: text("oid_value").notNull(),
1224
+ oidType: text("oid_type").notNull(),
1225
+ collectedAt: timestamptz("collected_at").notNull(),
1226
+ elaboration: text(),
1227
+ ...housekeeping
1228
+ }, (table2) => [
1229
+ index("idx_surveilr_snmp_collection__device_key__oid").on(
1230
+ table2.deviceKey,
1231
+ table2.oid
1232
+ ),
1233
+ index("idx_surveilr_snmp_collection__collected_at").on(table2.collectedAt),
1234
+ checkJSON(table2.elaboration)
1235
+ ]);
1236
+ var surveilrFunctionDoc = table("surveilr_function_doc", {
1237
+ name: text().primaryKey(),
1238
+ description: text(),
1239
+ parameters: text({ mode: "json" }),
1240
+ returnType: text("return_type"),
1241
+ version: text()
1242
+ }, (table2) => [
1243
+ checkJSON(table2.parameters)
1244
+ ]);
1245
+
1246
+ // ../../drizzle/views.ts
1247
+ import { sqliteView as sqliteView2 } from "drizzle-orm/sqlite-core";
1248
+ import { sql as sql2, count, min, max, sum, eq, and } from "drizzle-orm";
1249
+ var codeNotebookCellVersions = sqliteView2("code_notebook_cell_versions").as((qb) => {
1250
+ return qb.select({
1251
+ notebookName: codeNotebookCell.notebookName,
1252
+ notebookKernelId: codeNotebookCell.notebookKernelId,
1253
+ cellName: codeNotebookCell.cellName,
1254
+ versions: sql2`COUNT(*) OVER(PARTITION BY ${codeNotebookCell.notebookName}, ${codeNotebookCell.cellName})`.as("versions"),
1255
+ codeNotebookCellId: codeNotebookCell.codeNotebookCellId
1256
+ }).from(codeNotebookCell).orderBy(codeNotebookCell.notebookName, codeNotebookCell.cellName);
1257
+ });
1258
+ var codeNotebookCellLatest = sqliteView2("code_notebook_cell_latest").as((qb) => {
1259
+ return qb.select({
1260
+ codeNotebookCellId: codeNotebookCell.codeNotebookCellId,
1261
+ notebookKernelId: codeNotebookCell.notebookKernelId,
1262
+ notebookName: codeNotebookCell.notebookName,
1263
+ cellName: codeNotebookCell.cellName,
1264
+ interpretableCode: codeNotebookCell.interpretableCode,
1265
+ interpretableCodeHash: codeNotebookCell.interpretableCodeHash,
1266
+ description: codeNotebookCell.description,
1267
+ cellGovernance: codeNotebookCell.cellGovernance,
1268
+ arguments: codeNotebookCell.arguments,
1269
+ activityLog: codeNotebookCell.activityLog,
1270
+ versionTimestamp: sql2`COALESCE(${codeNotebookCell.updatedAt}, ${codeNotebookCell.createdAt})`.as("version_timestamp")
1271
+ }).from(codeNotebookCell).where(sql2`${codeNotebookCell.codeNotebookCellId} IN (
1272
+ SELECT code_notebook_cell_id
1273
+ FROM (
1274
+ SELECT code_notebook_cell_id,
1275
+ ROW_NUMBER() OVER (
1276
+ PARTITION BY code_notebook_cell_id
1277
+ ORDER BY COALESCE(updated_at, created_at) DESC
1278
+ ) AS rn
1279
+ FROM code_notebook_cell
1280
+ ) ranked WHERE rn = 1
1281
+ )`);
1282
+ });
1283
+ var codeNotebookSqlCellMigratableVersion = sqliteView2("code_notebook_sql_cell_migratable_version").as((qb) => {
1284
+ return qb.select({
1285
+ codeNotebookCellId: codeNotebookCell.codeNotebookCellId,
1286
+ notebookName: codeNotebookCell.notebookName,
1287
+ cellName: codeNotebookCell.cellName,
1288
+ interpretableCode: codeNotebookCell.interpretableCode,
1289
+ interpretableCodeHash: codeNotebookCell.interpretableCodeHash,
1290
+ isIdempotent: sql2`CASE WHEN ${codeNotebookCell.cellName} LIKE '%_once_%' THEN FALSE ELSE TRUE END`.as("is_idempotent"),
1291
+ versionTimestamp: sql2`COALESCE(${codeNotebookCell.updatedAt}, ${codeNotebookCell.createdAt})`.as("version_timestamp")
1292
+ }).from(codeNotebookCell).where(eq(codeNotebookCell.notebookName, "ConstructionSqlNotebook")).orderBy(codeNotebookCell.cellName);
1293
+ });
1294
+ var codeNotebookSqlCellMigratable = sqliteView2("code_notebook_sql_cell_migratable").as((qb) => {
1295
+ return qb.select({
1296
+ codeNotebookCellId: codeNotebookCell.codeNotebookCellId,
1297
+ notebookKernelId: codeNotebookCell.notebookKernelId,
1298
+ notebookName: codeNotebookCell.notebookName,
1299
+ cellName: codeNotebookCell.cellName,
1300
+ interpretableCode: codeNotebookCell.interpretableCode,
1301
+ interpretableCodeHash: codeNotebookCell.interpretableCodeHash,
1302
+ description: codeNotebookCell.description,
1303
+ cellGovernance: codeNotebookCell.cellGovernance,
1304
+ arguments: codeNotebookCell.arguments,
1305
+ activityLog: codeNotebookCell.activityLog,
1306
+ isIdempotent: sql2`CASE WHEN ${codeNotebookCell.cellName} LIKE '%_once_%' THEN FALSE ELSE TRUE END`.as("is_idempotent")
1307
+ }).from(codeNotebookCell).where(eq(codeNotebookCell.notebookName, "ConstructionSqlNotebook")).orderBy(codeNotebookCell.cellName);
1308
+ });
1309
+ var codeNotebookSqlCellMigratableState = sqliteView2("code_notebook_sql_cell_migratable_state").as((qb) => {
1310
+ return qb.select({
1311
+ codeNotebookCellId: codeNotebookCell.codeNotebookCellId,
1312
+ notebookKernelId: codeNotebookCell.notebookKernelId,
1313
+ notebookName: codeNotebookCell.notebookName,
1314
+ cellName: codeNotebookCell.cellName,
1315
+ interpretableCode: codeNotebookCell.interpretableCode,
1316
+ interpretableCodeHash: codeNotebookCell.interpretableCodeHash,
1317
+ description: codeNotebookCell.description,
1318
+ cellGovernance: codeNotebookCell.cellGovernance,
1319
+ arguments: codeNotebookCell.arguments,
1320
+ activityLog: codeNotebookCell.activityLog,
1321
+ fromState: codeNotebookState.fromState,
1322
+ toState: codeNotebookState.toState,
1323
+ transitionReason: codeNotebookState.transitionReason,
1324
+ transitionResult: codeNotebookState.transitionResult,
1325
+ transitionedAt: codeNotebookState.transitionedAt
1326
+ }).from(codeNotebookCell).innerJoin(codeNotebookState, eq(codeNotebookCell.codeNotebookCellId, codeNotebookState.codeNotebookCellId)).where(eq(codeNotebookCell.notebookName, "ConstructionSqlNotebook")).orderBy(codeNotebookCell.cellName);
1327
+ });
1328
+ var codeNotebookSqlCellMigratableNotExecuted = sqliteView2("code_notebook_sql_cell_migratable_not_executed").as((qb) => {
1329
+ return qb.select({
1330
+ codeNotebookCellId: codeNotebookCell.codeNotebookCellId,
1331
+ notebookKernelId: codeNotebookCell.notebookKernelId,
1332
+ notebookName: codeNotebookCell.notebookName,
1333
+ cellName: codeNotebookCell.cellName,
1334
+ interpretableCode: codeNotebookCell.interpretableCode,
1335
+ interpretableCodeHash: codeNotebookCell.interpretableCodeHash,
1336
+ description: codeNotebookCell.description,
1337
+ cellGovernance: codeNotebookCell.cellGovernance,
1338
+ arguments: codeNotebookCell.arguments,
1339
+ activityLog: codeNotebookCell.activityLog
1340
+ }).from(codeNotebookCell).leftJoin(codeNotebookState, and(
1341
+ eq(codeNotebookCell.codeNotebookCellId, codeNotebookState.codeNotebookCellId),
1342
+ eq(codeNotebookState.toState, "EXECUTED")
1343
+ )).where(
1344
+ and(
1345
+ eq(codeNotebookCell.notebookName, "ConstructionSqlNotebook"),
1346
+ sql2`${codeNotebookState.codeNotebookCellId} IS NULL`
1347
+ )
1348
+ ).orderBy(codeNotebookCell.cellName);
1349
+ });
1350
+ var codeNotebookMigrationSql = sqliteView2("code_notebook_migration_sql", {}).as(sql2`
1351
+ SELECT 'BEGIN TRANSACTION;
1352
+
1353
+ ' ||
1354
+ 'CREATE TEMP TABLE IF NOT EXISTS "session_state_ephemeral" (
1355
+ "key" TEXT PRIMARY KEY NOT NULL,
1356
+ "value" TEXT NOT NULL
1357
+ );
1358
+
1359
+ ' ||
1360
+ GROUP_CONCAT(
1361
+ CASE
1362
+ -- Case 1: Non-idempotent and already executed
1363
+ WHEN c.is_idempotent = FALSE AND s.code_notebook_cell_id IS NOT NULL THEN
1364
+ '-- ' || c.notebook_name || '.' || c.cell_name || ' not included because it is non-idempotent and was already executed on ' || s.transitioned_at || '
1365
+
1366
+ '
1367
+ -- Case 2: Idempotent and not yet executed, idempotent and being reapplied, or non-idempotent and being run for the first time
1368
+ ELSE
1369
+ '-- ' || c.notebook_name || '.' || c.cell_name || '
1370
+ ' ||
1371
+ CASE
1372
+ -- First execution (non-idempotent or idempotent)
1373
+ WHEN s.code_notebook_cell_id IS NULL THEN
1374
+ '-- Executing for the first time.
1375
+ '
1376
+ -- Reapplying execution (idempotent)
1377
+ ELSE
1378
+ '-- Reapplying execution. Last executed on ' || s.transitioned_at || '
1379
+ '
1380
+ END ||
1381
+ c.interpretable_code || '
1382
+ ' ||
1383
+ 'INSERT INTO code_notebook_state (code_notebook_state_id, code_notebook_cell_id, from_state, to_state, transition_reason, created_at) ' ||
1384
+ 'VALUES (' ||
1385
+ '''' || c.code_notebook_cell_id || '__' || strftime('%Y%m%d%H%M%S', 'now') || '''' || ', ' ||
1386
+ '''' || c.code_notebook_cell_id || '''' || ', ' ||
1387
+ '''MIGRATION_CANDIDATE''' || ', ' ||
1388
+ '''EXECUTED''' || ', ' ||
1389
+ CASE
1390
+ WHEN s.code_notebook_cell_id IS NULL THEN '''Migration'''
1391
+ ELSE '''Reapplication'''
1392
+ END || ', ' ||
1393
+ 'CURRENT_TIMESTAMP' || ')' || '
1394
+ ' ||
1395
+ 'ON CONFLICT(code_notebook_cell_id, from_state, to_state) DO UPDATE SET updated_at = CURRENT_TIMESTAMP, ' ||
1396
+ 'transition_reason = ''Reapplied ' || datetime('now', 'localtime') || ''';' || '
1397
+ '
1398
+ END,
1399
+ '
1400
+ '
1401
+ ) || '
1402
+
1403
+ COMMIT;' as migration_sql
1404
+ FROM code_notebook_sql_cell_migratable c
1405
+ LEFT JOIN code_notebook_state s
1406
+ ON c.code_notebook_cell_id = s.code_notebook_cell_id AND s.to_state = 'EXECUTED'
1407
+ ORDER BY c.cell_name`);
1408
+ var imapGraph = sqliteView2("imap_graph").as((qb) => {
1409
+ return qb.select({
1410
+ graphName: uniformResourceEdge.graphName,
1411
+ uniformResourceId: uniformResource.uniformResourceId,
1412
+ nature: uniformResource.nature,
1413
+ uri: uniformResource.uri,
1414
+ content: uniformResource.content,
1415
+ urIngestSessionImapAcctFolderMessageId: urIngestSessionImapAcctFolderMessage.urIngestSessionImapAcctFolderMessageId,
1416
+ ingestImapAcctFolderId: urIngestSessionImapAcctFolderMessage.ingestImapAcctFolderId,
1417
+ messageId: urIngestSessionImapAcctFolderMessage.messageId
1418
+ }).from(uniformResourceEdge).innerJoin(uniformResource, eq(uniformResourceEdge.uniformResourceId, uniformResource.uniformResourceId)).innerJoin(urIngestSessionImapAcctFolderMessage, eq(uniformResourceEdge.nodeId, urIngestSessionImapAcctFolderMessage.urIngestSessionImapAcctFolderMessageId)).where(eq(uniformResourceEdge.graphName, "imap"));
1419
+ });
1420
+ var filesystemGraph = sqliteView2("filesystem_graph").as((qb) => {
1421
+ return qb.select({
1422
+ graphName: uniformResourceEdge.graphName,
1423
+ uniformResourceId: uniformResource.uniformResourceId,
1424
+ nature: uniformResource.nature,
1425
+ uri: uniformResource.uri,
1426
+ urIngestSessionFsPathId: urIngestSessionFsPath.urIngestSessionFsPathId,
1427
+ rootPath: urIngestSessionFsPath.rootPath
1428
+ }).from(uniformResourceEdge).innerJoin(uniformResource, eq(uniformResourceEdge.uniformResourceId, uniformResource.uniformResourceId)).innerJoin(urIngestSessionFsPath, eq(uniformResourceEdge.nodeId, urIngestSessionFsPath.urIngestSessionFsPathId)).where(eq(uniformResourceEdge.graphName, "filesystem"));
1429
+ });
1430
+ var consoleInformationSchemaTable = sqliteView2("console_information_schema_table", {}).as(sql2`
1431
+ SELECT
1432
+ tbl.name AS table_name,
1433
+ col.name AS column_name,
1434
+ col.type AS data_type,
1435
+ CASE WHEN col.pk = 1 THEN 'Yes' ELSE 'No' END AS is_primary_key,
1436
+ CASE WHEN col."notnull" = 1 THEN 'Yes' ELSE 'No' END AS is_not_null,
1437
+ col.dflt_value AS default_value,
1438
+ 'console/info-schema/table.sql?name=' || tbl.name || '&stats=yes' as info_schema_web_ui_path,
1439
+ '[Content](console/info-schema/table.sql?name=' || tbl.name || '&stats=yes)' as info_schema_link_abbrev_md,
1440
+ '[' || tbl.name || ' (table) Schema](console/info-schema/table.sql?name=' || tbl.name || '&stats=yes)' as info_schema_link_full_md,
1441
+ 'console/content/table/' || tbl.name || '.sql?stats=yes' as content_web_ui_path,
1442
+ '[Content]($SITE_PREFIX_URL/console/content/table/' || tbl.name || '.sql?stats=yes)' as content_web_ui_link_abbrev_md,
1443
+ '[' || tbl.name || ' (table) Content](console/content/table/' || tbl.name || '.sql?stats=yes)' as content_web_ui_link_full_md,
1444
+ tbl.sql as sql_ddl
1445
+ FROM sqlite_master tbl
1446
+ JOIN pragma_table_info(tbl.name) col
1447
+ WHERE tbl.type = 'table' AND tbl.name NOT LIKE 'sqlite_%'
1448
+ `);
1449
+ var consoleInformationSchemaView = sqliteView2("console_information_schema_view", {}).as(sql2`
1450
+ SELECT
1451
+ vw.name AS view_name,
1452
+ col.name AS column_name,
1453
+ col.type AS data_type,
1454
+ '/console/info-schema/view.sql?name=' || vw.name || '&stats=yes' as info_schema_web_ui_path,
1455
+ '[Content](console/info-schema/view.sql?name=' || vw.name || '&stats=yes)' as info_schema_link_abbrev_md,
1456
+ '[' || vw.name || ' (view) Schema](console/info-schema/view.sql?name=' || vw.name || '&stats=yes)' as info_schema_link_full_md,
1457
+ '/console/content/view/' || vw.name || '.sql?stats=yes' as content_web_ui_path,
1458
+ '[Content]($SITE_PREFIX_URL/console/content/view/' || vw.name || '.sql?stats=yes)' as content_web_ui_link_abbrev_md,
1459
+ '[' || vw.name || ' (view) Content](console/content/view/' || vw.name || '.sql?stats=yes)' as content_web_ui_link_full_md,
1460
+ vw.sql as sql_ddl
1461
+ FROM sqlite_master vw
1462
+ JOIN pragma_table_info(vw.name) col
1463
+ WHERE vw.type = 'view' AND vw.name NOT LIKE 'sqlite_%'
1464
+ `);
1465
+ var consoleContentTabular = sqliteView2("console_content_tabular").as((qb) => {
1466
+ const tableQuery = qb.select({
1467
+ tabularNature: sql2`'table'`.as("tabular_nature"),
1468
+ tabularName: sql2`table_name`.as("tabular_name"),
1469
+ infoSchemaWebUiPath: sql2`info_schema_web_ui_path`.as("info_schema_web_ui_path"),
1470
+ infoSchemaLinkAbbrevMd: sql2`info_schema_link_abbrev_md`.as("info_schema_link_abbrev_md"),
1471
+ infoSchemaLinkFullMd: sql2`info_schema_link_full_md`.as("info_schema_link_full_md"),
1472
+ contentWebUiPath: sql2`content_web_ui_path`.as("content_web_ui_path"),
1473
+ contentWebUiLinkAbbrevMd: sql2`content_web_ui_link_abbrev_md`.as("content_web_ui_link_abbrev_md"),
1474
+ contentWebUiLinkFullMd: sql2`content_web_ui_link_full_md`.as("content_web_ui_link_full_md")
1475
+ }).from(consoleInformationSchemaTable);
1476
+ const viewQuery = qb.select({
1477
+ tabularNature: sql2`'view'`.as("tabular_nature"),
1478
+ tabularName: sql2`view_name`.as("tabular_name"),
1479
+ infoSchemaWebUiPath: sql2`info_schema_web_ui_path`.as("info_schema_web_ui_path"),
1480
+ infoSchemaLinkAbbrevMd: sql2`info_schema_link_abbrev_md`.as("info_schema_link_abbrev_md"),
1481
+ infoSchemaLinkFullMd: sql2`info_schema_link_full_md`.as("info_schema_link_full_md"),
1482
+ contentWebUiPath: sql2`content_web_ui_path`.as("content_web_ui_path"),
1483
+ contentWebUiLinkAbbrevMd: sql2`content_web_ui_link_abbrev_md`.as("content_web_ui_link_abbrev_md"),
1484
+ contentWebUiLinkFullMd: sql2`content_web_ui_link_full_md`.as("content_web_ui_link_full_md")
1485
+ }).from(consoleInformationSchemaView);
1486
+ return tableQuery.unionAll(viewQuery);
1487
+ });
1488
+ var consoleInformationSchemaTableColFkey = sqliteView2("console_information_schema_table_col_fkey", {}).as(sql2`
1489
+ SELECT
1490
+ tbl.name AS table_name,
1491
+ f."from" AS column_name,
1492
+ f."from" || ' references ' || f."table" || '.' || f."to" AS foreign_key
1493
+ FROM sqlite_master tbl
1494
+ JOIN pragma_foreign_key_list(tbl.name) f
1495
+ WHERE tbl.type = 'table' AND tbl.name NOT LIKE 'sqlite_%'
1496
+ `);
1497
+ var consoleInformationSchemaTableColIndex = sqliteView2("console_information_schema_table_col_index", {}).as(sql2`
1498
+ SELECT
1499
+ tbl.name AS table_name,
1500
+ pi.name AS column_name,
1501
+ idx.name AS index_name
1502
+ FROM sqlite_master tbl
1503
+ JOIN pragma_index_list(tbl.name) idx
1504
+ JOIN pragma_index_info(idx.name) pi
1505
+ WHERE tbl.type = 'table' AND tbl.name NOT LIKE 'sqlite_%'
1506
+ `);
1507
+ var rssdStatisticsOverview = sqliteView2("rssd_statistics_overview").as((qb) => {
1508
+ return qb.select({
1509
+ dbSizeMb: sql2`(SELECT ROUND(page_count * page_size / (1024.0 * 1024), 2) FROM pragma_page_count(), pragma_page_size())`.as("db_size_mb"),
1510
+ dbSizeGb: sql2`(SELECT ROUND(page_count * page_size / (1024.0 * 1024 * 1024), 4) FROM pragma_page_count(), pragma_page_size())`.as("db_size_gb"),
1511
+ totalTables: sql2`(SELECT COUNT(*) FROM sqlite_master WHERE type = 'table')`.as("total_tables"),
1512
+ totalIndexes: sql2`(SELECT COUNT(*) FROM sqlite_master WHERE type = 'index')`.as("total_indexes"),
1513
+ totalRows: sql2`(SELECT SUM(tbl_rows) FROM (SELECT name, (SELECT COUNT(*) FROM sqlite_master sm WHERE sm.type='table' AND sm.name=t.name) AS tbl_rows FROM sqlite_master t WHERE type='table'))`.as("total_rows"),
1514
+ pageSize: sql2`(SELECT page_size FROM pragma_page_size())`.as("page_size"),
1515
+ totalPages: sql2`(SELECT page_count FROM pragma_page_count())`.as("total_pages")
1516
+ }).from(sql2`(SELECT 1) AS dummy`);
1517
+ });
1518
+ var rssdTableStatistic = sqliteView2("rssd_table_statistic", {}).as(sql2`
1519
+ SELECT
1520
+ m.name AS table_name,
1521
+ (SELECT COUNT(*) FROM pragma_table_info(m.name)) AS total_columns,
1522
+ (SELECT COUNT(*) FROM pragma_index_list(m.name)) AS total_indexes,
1523
+ (SELECT COUNT(*) FROM pragma_foreign_key_list(m.name)) AS foreign_keys,
1524
+ (SELECT COUNT(*) FROM pragma_table_info(m.name) WHERE pk != 0) AS primary_keys,
1525
+ (SELECT table_size_mb FROM surveilr_table_size WHERE table_name = m.name) AS table_size_mb
1526
+ FROM sqlite_master m
1527
+ WHERE m.type = 'table'
1528
+ `);
1529
+ var uniformResourceFile = sqliteView2("uniform_resource_file").as((qb) => {
1530
+ return qb.select({
1531
+ uniformResourceId: uniformResource.uniformResourceId,
1532
+ nature: uniformResource.nature,
1533
+ sourcePath: urIngestSessionFsPath.rootPath,
1534
+ filePathRel: urIngestSessionFsPathEntry.filePathRel,
1535
+ sizeBytes: uniformResource.sizeBytes
1536
+ }).from(uniformResource).leftJoin(
1537
+ uniformResourceEdge,
1538
+ and(
1539
+ eq(uniformResource.uniformResourceId, uniformResourceEdge.uniformResourceId),
1540
+ eq(uniformResourceEdge.nature, "ingest_fs_path")
1541
+ )
1542
+ ).leftJoin(urIngestSessionFsPath, eq(uniformResourceEdge.nodeId, urIngestSessionFsPath.urIngestSessionFsPathId)).leftJoin(urIngestSessionFsPathEntry, eq(uniformResource.uniformResourceId, urIngestSessionFsPathEntry.uniformResourceId));
1543
+ });
1544
+ var uniformResourceImap = sqliteView2("uniform_resource_imap").as((qb) => {
1545
+ return qb.select({
1546
+ uniformResourceId: uniformResource.uniformResourceId,
1547
+ graphName: uniformResourceGraph.name,
1548
+ urIngestSessionImapAccountId: urIngestSessionImapAccount.urIngestSessionImapAccountId,
1549
+ email: urIngestSessionImapAccount.email,
1550
+ host: urIngestSessionImapAccount.host,
1551
+ subject: urIngestSessionImapAcctFolderMessage.subject,
1552
+ from: urIngestSessionImapAcctFolderMessage.from,
1553
+ message: urIngestSessionImapAcctFolderMessage.message,
1554
+ date: urIngestSessionImapAcctFolderMessage.date,
1555
+ urIngestSessionImapAcctFolderId: urIngestSessionImapAcctFolder.urIngestSessionImapAcctFolderId,
1556
+ ingestAccountId: urIngestSessionImapAcctFolder.ingestAccountId,
1557
+ folderName: urIngestSessionImapAcctFolder.folderName,
1558
+ sizeBytes: uniformResource.sizeBytes,
1559
+ nature: uniformResource.nature,
1560
+ content: uniformResource.content
1561
+ }).from(uniformResource).innerJoin(uniformResourceEdge, eq(uniformResourceEdge.uniformResourceId, uniformResource.uniformResourceId)).innerJoin(uniformResourceGraph, eq(uniformResourceGraph.name, uniformResourceEdge.graphName)).innerJoin(urIngestSessionImapAcctFolderMessage, eq(urIngestSessionImapAcctFolderMessage.urIngestSessionImapAcctFolderMessageId, uniformResourceEdge.nodeId)).innerJoin(urIngestSessionImapAcctFolder, eq(urIngestSessionImapAcctFolderMessage.ingestImapAcctFolderId, urIngestSessionImapAcctFolder.urIngestSessionImapAcctFolderId)).leftJoin(urIngestSessionImapAccount, eq(urIngestSessionImapAccount.urIngestSessionImapAccountId, urIngestSessionImapAcctFolder.ingestAccountId)).where(and(
1562
+ eq(uniformResource.nature, "text"),
1563
+ eq(uniformResourceGraph.name, "imap"),
1564
+ sql2`${uniformResource.ingestSessionImapAcctFolderMessage} IS NOT NULL`
1565
+ ));
1566
+ });
1567
+ var uniformResourceImapContent = sqliteView2("uniform_resource_imap_content").as((qb) => {
1568
+ return qb.select({
1569
+ uniformResourceId: uniformResourceImap.uniformResourceId,
1570
+ baseId: sql2`base_ur.uniform_resource_id`.as("base_id"),
1571
+ extId: sql2`ext_ur.uniform_resource_id`.as("ext_id"),
1572
+ baseUri: sql2`base_ur.uri`.as("base_uri"),
1573
+ extUri: sql2`ext_ur.uri`.as("ext_uri"),
1574
+ baseNature: sql2`base_ur.nature`.as("base_nature"),
1575
+ extNature: sql2`ext_ur.nature`.as("ext_nature"),
1576
+ htmlContent: sql2`json_extract(part.value, '$.body.Html')`.as("html_content")
1577
+ }).from(uniformResourceImap).innerJoin(sql2`uniform_resource base_ur`, sql2`base_ur.uniform_resource_id = ${uniformResourceImap.uniformResourceId}`).innerJoin(sql2`uniform_resource ext_ur`, sql2`ext_ur.uri = base_ur.uri || '/json' AND ext_ur.nature = 'json'`).crossJoin(sql2`json_each(ext_ur.content, '$.parts') AS part`).where(and(
1578
+ sql2`ext_ur.nature = 'json'`,
1579
+ sql2`json_extract(part.value, '$.body.Html') IS NOT NULL`
1580
+ ));
1581
+ });
1582
+ var urIngestSessionFilesStats = sqliteView2("ur_ingest_session_files_stats").as((qb) => {
1583
+ return qb.select({
1584
+ deviceId: device.deviceId,
1585
+ ingestSessionId: urIngestSession.urIngestSessionId,
1586
+ ingestSessionStartedAt: urIngestSession.ingestStartedAt,
1587
+ ingestSessionFinishedAt: urIngestSession.ingestFinishedAt,
1588
+ fileExtension: sql2`COALESCE(${urIngestSessionFsPathEntry.fileExtn}, '')`.as("file_extension"),
1589
+ ingestSessionFsPathId: urIngestSessionFsPath.urIngestSessionFsPathId,
1590
+ ingestSessionRootFsPath: urIngestSessionFsPath.rootPath,
1591
+ totalFileCount: count(urIngestSessionFsPathEntry.uniformResourceId).as("total_file_count"),
1592
+ fileCountWithContent: sum(sql2`CASE WHEN ${uniformResource.content} IS NOT NULL THEN 1 ELSE 0 END`).as("file_count_with_content"),
1593
+ fileCountWithFrontmatter: sum(sql2`CASE WHEN ${uniformResource.frontmatter} IS NOT NULL THEN 1 ELSE 0 END`).as("file_count_with_frontmatter"),
1594
+ minFileSizeBytes: min(uniformResource.sizeBytes).as("min_file_size_bytes"),
1595
+ averageFileSizeBytes: sql2`CAST(ROUND(AVG(${uniformResource.sizeBytes})) AS INTEGER)`.as("average_file_size_bytes"),
1596
+ maxFileSizeBytes: max(uniformResource.sizeBytes).as("max_file_size_bytes"),
1597
+ oldestFileLastModifiedDatetime: min(uniformResource.lastModifiedAt).as("oldest_file_last_modified_datetime"),
1598
+ youngestFileLastModifiedDatetime: max(uniformResource.lastModifiedAt).as("youngest_file_last_modified_datetime")
1599
+ }).from(urIngestSession).innerJoin(device, eq(urIngestSession.deviceId, device.deviceId)).leftJoin(urIngestSessionFsPath, eq(urIngestSession.urIngestSessionId, urIngestSessionFsPath.ingestSessionId)).leftJoin(urIngestSessionFsPathEntry, eq(urIngestSessionFsPath.urIngestSessionFsPathId, urIngestSessionFsPathEntry.ingestFsPathId)).leftJoin(uniformResource, eq(urIngestSessionFsPathEntry.uniformResourceId, uniformResource.uniformResourceId)).groupBy(
1600
+ device.deviceId,
1601
+ urIngestSession.urIngestSessionId,
1602
+ urIngestSession.ingestStartedAt,
1603
+ urIngestSession.ingestFinishedAt,
1604
+ urIngestSessionFsPathEntry.fileExtn,
1605
+ urIngestSessionFsPath.rootPath
1606
+ ).orderBy(device.deviceId, urIngestSession.ingestFinishedAt, urIngestSessionFsPathEntry.fileExtn);
1607
+ });
1608
+ var urIngestSessionFilesStatsLatest = sqliteView2("ur_ingest_session_files_stats_latest").as((qb) => {
1609
+ return qb.select({
1610
+ deviceId: urIngestSessionFilesStats.deviceId,
1611
+ ingestSessionId: urIngestSessionFilesStats.ingestSessionId,
1612
+ ingestSessionStartedAt: urIngestSessionFilesStats.ingestSessionStartedAt,
1613
+ ingestSessionFinishedAt: urIngestSessionFilesStats.ingestSessionFinishedAt,
1614
+ fileExtension: urIngestSessionFilesStats.fileExtension,
1615
+ ingestSessionFsPathId: urIngestSessionFilesStats.ingestSessionFsPathId,
1616
+ ingestSessionRootFsPath: urIngestSessionFilesStats.ingestSessionRootFsPath,
1617
+ totalFileCount: urIngestSessionFilesStats.totalFileCount,
1618
+ fileCountWithContent: urIngestSessionFilesStats.fileCountWithContent,
1619
+ fileCountWithFrontmatter: urIngestSessionFilesStats.fileCountWithFrontmatter,
1620
+ minFileSizeBytes: urIngestSessionFilesStats.minFileSizeBytes,
1621
+ averageFileSizeBytes: urIngestSessionFilesStats.averageFileSizeBytes,
1622
+ maxFileSizeBytes: urIngestSessionFilesStats.maxFileSizeBytes,
1623
+ oldestFileLastModifiedDatetime: urIngestSessionFilesStats.oldestFileLastModifiedDatetime,
1624
+ youngestFileLastModifiedDatetime: urIngestSessionFilesStats.youngestFileLastModifiedDatetime
1625
+ }).from(urIngestSessionFilesStats).where(sql2`${urIngestSessionFilesStats.ingestSessionId} IN (
1626
+ SELECT ${urIngestSession.urIngestSessionId}
1627
+ FROM ${urIngestSession}
1628
+ ORDER BY ${urIngestSession.ingestFinishedAt} DESC
1629
+ LIMIT 1
1630
+ )`);
1631
+ });
1632
+ var urIngestSessionTasksStats = sqliteView2("ur_ingest_session_tasks_stats").as((qb) => {
1633
+ return qb.select({
1634
+ deviceId: device.deviceId,
1635
+ ingestSessionId: urIngestSession.urIngestSessionId,
1636
+ ingestSessionStartedAt: urIngestSession.ingestStartedAt,
1637
+ ingestSessionFinishedAt: urIngestSession.ingestFinishedAt,
1638
+ urStatus: sql2`COALESCE(${urIngestSessionTask.urStatus}, 'Ok')`.as("ur_status"),
1639
+ nature: sql2`COALESCE(${uniformResource.nature}, 'UNKNOWN')`.as("nature"),
1640
+ totalFileCount: count(urIngestSessionTask.uniformResourceId).as("total_file_count"),
1641
+ fileCountWithContent: sum(sql2`CASE WHEN ${uniformResource.content} IS NOT NULL THEN 1 ELSE 0 END`).as("file_count_with_content"),
1642
+ fileCountWithFrontmatter: sum(sql2`CASE WHEN ${uniformResource.frontmatter} IS NOT NULL THEN 1 ELSE 0 END`).as("file_count_with_frontmatter"),
1643
+ minFileSizeBytes: min(uniformResource.sizeBytes).as("min_file_size_bytes"),
1644
+ averageFileSizeBytes: sql2`CAST(ROUND(AVG(${uniformResource.sizeBytes})) AS INTEGER)`.as("average_file_size_bytes"),
1645
+ maxFileSizeBytes: max(uniformResource.sizeBytes).as("max_file_size_bytes"),
1646
+ oldestFileLastModifiedDatetime: min(uniformResource.lastModifiedAt).as("oldest_file_last_modified_datetime"),
1647
+ youngestFileLastModifiedDatetime: max(uniformResource.lastModifiedAt).as("youngest_file_last_modified_datetime")
1648
+ }).from(urIngestSession).innerJoin(device, eq(urIngestSession.deviceId, device.deviceId)).leftJoin(urIngestSessionTask, eq(urIngestSession.urIngestSessionId, urIngestSessionTask.ingestSessionId)).leftJoin(uniformResource, eq(urIngestSessionTask.uniformResourceId, uniformResource.uniformResourceId)).groupBy(
1649
+ device.deviceId,
1650
+ urIngestSession.urIngestSessionId,
1651
+ urIngestSession.ingestStartedAt,
1652
+ urIngestSession.ingestFinishedAt,
1653
+ urIngestSessionTask.capturedExecutable
1654
+ ).orderBy(device.deviceId, urIngestSession.ingestFinishedAt, urIngestSessionTask.urStatus);
1655
+ });
1656
+ var urIngestSessionTasksStatsLatest = sqliteView2("ur_ingest_session_tasks_stats_latest").as((qb) => {
1657
+ return qb.select({
1658
+ deviceId: urIngestSessionTasksStats.deviceId,
1659
+ ingestSessionId: urIngestSessionTasksStats.ingestSessionId,
1660
+ ingestSessionStartedAt: urIngestSessionTasksStats.ingestSessionStartedAt,
1661
+ ingestSessionFinishedAt: urIngestSessionTasksStats.ingestSessionFinishedAt,
1662
+ urStatus: urIngestSessionTasksStats.urStatus,
1663
+ nature: urIngestSessionTasksStats.nature,
1664
+ totalFileCount: urIngestSessionTasksStats.totalFileCount,
1665
+ fileCountWithContent: urIngestSessionTasksStats.fileCountWithContent,
1666
+ fileCountWithFrontmatter: urIngestSessionTasksStats.fileCountWithFrontmatter,
1667
+ minFileSizeBytes: urIngestSessionTasksStats.minFileSizeBytes,
1668
+ averageFileSizeBytes: urIngestSessionTasksStats.averageFileSizeBytes,
1669
+ maxFileSizeBytes: urIngestSessionTasksStats.maxFileSizeBytes,
1670
+ oldestFileLastModifiedDatetime: urIngestSessionTasksStats.oldestFileLastModifiedDatetime,
1671
+ youngestFileLastModifiedDatetime: urIngestSessionTasksStats.youngestFileLastModifiedDatetime
1672
+ }).from(urIngestSessionTasksStats).where(sql2`${urIngestSessionTasksStats.ingestSessionId} IN (
1673
+ SELECT ${urIngestSession.urIngestSessionId}
1674
+ FROM ${urIngestSession}
1675
+ ORDER BY ${urIngestSession.ingestFinishedAt} DESC
1676
+ LIMIT 1
1677
+ )`);
1678
+ });
1679
+ var urIngestSessionFileIssue = sqliteView2("ur_ingest_session_file_issue").as((qb) => {
1680
+ return qb.select({
1681
+ deviceId: urIngestSession.deviceId,
1682
+ urIngestSessionId: urIngestSession.urIngestSessionId,
1683
+ urIngestSessionFsPathId: urIngestSessionFsPath.urIngestSessionFsPathId,
1684
+ rootPath: urIngestSessionFsPath.rootPath,
1685
+ urIngestSessionFsPathEntryId: urIngestSessionFsPathEntry.urIngestSessionFsPathEntryId,
1686
+ filePathAbs: urIngestSessionFsPathEntry.filePathAbs,
1687
+ urStatus: urIngestSessionFsPathEntry.urStatus,
1688
+ urDiagnostics: urIngestSessionFsPathEntry.urDiagnostics
1689
+ }).from(urIngestSessionFsPathEntry).innerJoin(urIngestSessionFsPath, eq(urIngestSessionFsPathEntry.ingestFsPathId, urIngestSessionFsPath.urIngestSessionFsPathId)).innerJoin(urIngestSession, eq(urIngestSessionFsPath.ingestSessionId, urIngestSession.urIngestSessionId)).where(sql2`${urIngestSessionFsPathEntry.urStatus} IS NOT NULL`).groupBy(
1690
+ urIngestSession.deviceId,
1691
+ urIngestSession.urIngestSessionId,
1692
+ urIngestSessionFsPath.urIngestSessionFsPathId,
1693
+ urIngestSessionFsPath.rootPath,
1694
+ urIngestSessionFsPathEntry.urIngestSessionFsPathEntryId,
1695
+ urIngestSessionFsPathEntry.filePathAbs,
1696
+ urIngestSessionFsPathEntry.urStatus,
1697
+ urIngestSessionFsPathEntry.urDiagnostics
1698
+ );
1699
+ });
1700
+ var orchestrationSessionByDevice = sqliteView2("orchestration_session_by_device").as((qb) => {
1701
+ return qb.select({
1702
+ deviceId: device.deviceId,
1703
+ deviceName: device.name,
1704
+ sessionCount: count(orchestrationSession.orchestrationSessionId).as("session_count")
1705
+ }).from(orchestrationSession).innerJoin(device, eq(orchestrationSession.deviceId, device.deviceId)).groupBy(device.deviceId, device.name);
1706
+ });
1707
+ var orchestrationSessionDuration = sqliteView2("orchestration_session_duration").as((qb) => {
1708
+ return qb.select({
1709
+ orchestrationSessionId: orchestrationSession.orchestrationSessionId,
1710
+ orchestrationNature: orchestrationNature.nature,
1711
+ orchStartedAt: orchestrationSession.orchStartedAt,
1712
+ orchFinishedAt: orchestrationSession.orchFinishedAt,
1713
+ durationSeconds: sql2`(JULIANDAY(${orchestrationSession.orchFinishedAt}) - JULIANDAY(${orchestrationSession.orchStartedAt})) * 24 * 60 * 60`.as("duration_seconds")
1714
+ }).from(orchestrationSession).innerJoin(orchestrationNature, eq(orchestrationSession.orchestrationNatureId, orchestrationNature.orchestrationNatureId)).where(sql2`${orchestrationSession.orchFinishedAt} IS NOT NULL`);
1715
+ });
1716
+ var orchestrationSuccessRate = sqliteView2("orchestration_success_rate").as((qb) => {
1717
+ return qb.select({
1718
+ orchestrationNature: orchestrationNature.nature,
1719
+ totalSessions: count().as("total_sessions"),
1720
+ successfulSessions: sum(sql2`CASE WHEN ${orchestrationSessionState.toState} = 'surveilr_orch_completed' THEN 1 ELSE 0 END`).as("successful_sessions"),
1721
+ successRate: sql2`(CAST(SUM(CASE WHEN ${orchestrationSessionState.toState} = 'surveilr_orch_completed' THEN 1 ELSE 0 END) AS FLOAT) / COUNT(*)) * 100`.as("success_rate")
1722
+ }).from(orchestrationSession).innerJoin(orchestrationNature, eq(orchestrationSession.orchestrationNatureId, orchestrationNature.orchestrationNatureId)).innerJoin(orchestrationSessionState, eq(orchestrationSession.orchestrationSessionId, orchestrationSessionState.sessionId)).where(sql2`${orchestrationSessionState.toState} IN ('surveilr_orch_completed', 'surveilr_orch_failed')`).groupBy(orchestrationNature.nature);
1723
+ });
1724
+ var orchestrationSessionScript = sqliteView2("orchestration_session_script").as((qb) => {
1725
+ return qb.select({
1726
+ orchestrationSessionId: orchestrationSession.orchestrationSessionId,
1727
+ orchestrationNature: orchestrationNature.nature,
1728
+ scriptCount: count(orchestrationSessionEntry.orchestrationSessionEntryId).as("script_count")
1729
+ }).from(orchestrationSession).innerJoin(orchestrationNature, eq(orchestrationSession.orchestrationNatureId, orchestrationNature.orchestrationNatureId)).innerJoin(orchestrationSessionEntry, eq(orchestrationSession.orchestrationSessionId, orchestrationSessionEntry.sessionId)).groupBy(orchestrationSession.orchestrationSessionId, orchestrationNature.nature);
1730
+ });
1731
+ var orchestrationExecutionsByType = sqliteView2("orchestration_executions_by_type").as((qb) => {
1732
+ return qb.select({
1733
+ execNature: orchestrationSessionExec.execNature,
1734
+ executionCount: count(orchestrationSessionExec.orchestrationSessionExecId).as("execution_count")
1735
+ }).from(orchestrationSessionExec).groupBy(orchestrationSessionExec.execNature);
1736
+ });
1737
+ var orchestrationExecutionSuccessRateByType = sqliteView2("orchestration_execution_success_rate_by_type").as((qb) => {
1738
+ return qb.select({
1739
+ execNature: orchestrationSessionExec.execNature,
1740
+ totalExecutions: count().as("total_executions"),
1741
+ successfulExecutions: sum(sql2`CASE WHEN ${orchestrationSessionExec.execStatus} = 0 THEN 1 ELSE 0 END`).as("successful_executions"),
1742
+ successRate: sql2`(CAST(SUM(CASE WHEN ${orchestrationSessionExec.execStatus} = 0 THEN 1 ELSE 0 END) AS FLOAT) / COUNT(*)) * 100`.as("success_rate")
1743
+ }).from(orchestrationSessionExec).groupBy(orchestrationSessionExec.execNature);
1744
+ });
1745
+ var orchestrationSessionSummary = sqliteView2("orchestration_session_summary").as((qb) => {
1746
+ return qb.select({
1747
+ issueType: orchestrationSessionIssue.issueType,
1748
+ issueCount: count(orchestrationSessionIssue.orchestrationSessionIssueId).as("issue_count")
1749
+ }).from(orchestrationSessionIssue).groupBy(orchestrationSessionIssue.issueType);
1750
+ });
1751
+ var orchestrationIssueRemediation = sqliteView2("orchestration_issue_remediation").as((qb) => {
1752
+ return qb.select({
1753
+ orchestrationSessionIssueId: orchestrationSessionIssue.orchestrationSessionIssueId,
1754
+ issueType: orchestrationSessionIssue.issueType,
1755
+ issueMessage: orchestrationSessionIssue.issueMessage,
1756
+ remediation: orchestrationSessionIssue.remediation
1757
+ }).from(orchestrationSessionIssue).where(sql2`${orchestrationSessionIssue.remediation} IS NOT NULL`);
1758
+ });
1759
+ var orchestrationLogsBySession = sqliteView2("orchestration_logs_by_session").as((qb) => {
1760
+ return qb.select({
1761
+ orchestrationSessionId: orchestrationSession.orchestrationSessionId,
1762
+ orchestrationNature: orchestrationNature.nature,
1763
+ category: orchestrationSessionLog.category,
1764
+ logCount: count(orchestrationSessionLog.orchestrationSessionLogId).as("log_count")
1765
+ }).from(orchestrationSession).innerJoin(orchestrationNature, eq(orchestrationSession.orchestrationNatureId, orchestrationNature.orchestrationNatureId)).innerJoin(orchestrationSessionExec, eq(orchestrationSession.orchestrationSessionId, orchestrationSessionExec.sessionId)).innerJoin(orchestrationSessionLog, eq(orchestrationSessionExec.orchestrationSessionExecId, orchestrationSessionLog.parentExecId)).groupBy(orchestrationSession.orchestrationSessionId, orchestrationNature.nature, orchestrationSessionLog.category);
1766
+ });
1767
+ var emailMessagesWithTimezone = sqliteView2("email_messages_with_timezone", {}).as(sql2`
1768
+ SELECT
1769
+ m.*,
1770
+ -- Smart timezone conversion based on original timezone
1771
+ CASE
1772
+ -- If already IST (+0530), just extract the time
1773
+ WHEN date LIKE '%+0530%' THEN substr(date, 18, 8)
1774
+ -- If UTC (+0000), convert to IST
1775
+ WHEN date LIKE '%+0000%' THEN time(substr(date, 18, 8), '+5 hours', '+30 minutes')
1776
+ -- If EST (-0500), convert to IST
1777
+ WHEN date LIKE '%-0500%' THEN time(substr(date, 18, 8), '+10 hours', '+30 minutes')
1778
+ -- If PST (-0800), convert to IST
1779
+ WHEN date LIKE '%-0800%' THEN time(substr(date, 18, 8), '+13 hours', '+30 minutes')
1780
+ -- Default: assume UTC and convert
1781
+ ELSE time(substr(date, 18, 8), '+5 hours', '+30 minutes')
1782
+ END as ist_time,
1783
+
1784
+ -- Always show UTC time (convert from any timezone to UTC first)
1785
+ CASE
1786
+ WHEN date LIKE '%+0530%' THEN time(substr(date, 18, 8), '-5 hours', '-30 minutes')
1787
+ WHEN date LIKE '%+0000%' THEN substr(date, 18, 8)
1788
+ WHEN date LIKE '%-0500%' THEN time(substr(date, 18, 8), '+5 hours')
1789
+ WHEN date LIKE '%-0800%' THEN time(substr(date, 18, 8), '+8 hours')
1790
+ ELSE substr(date, 18, 8)
1791
+ END as utc_time,
1792
+
1793
+ -- Detect original timezone more accurately
1794
+ CASE
1795
+ WHEN date LIKE '%+0530%' THEN 'IST'
1796
+ WHEN date LIKE '%+0000%' THEN 'UTC'
1797
+ WHEN date LIKE '%-0500%' THEN 'EST'
1798
+ WHEN date LIKE '%-0800%' THEN 'PST'
1799
+ ELSE 'Unknown'
1800
+ END as detected_timezone
1801
+ FROM ur_ingest_session_imap_acct_folder_message m`);
1802
+ var deviceGraphOverview = sqliteView2("device_graph_overview", {}).as(sql2`
1803
+ SELECT
1804
+ 'snmp_device' as device_type,
1805
+ sd.device_key as device_id,
1806
+ sd.snmp_host as primary_identifier,
1807
+ sd.device_type as device_category,
1808
+ sd.device_description as description,
1809
+ sd.status,
1810
+ sd.created_at,
1811
+ sd.updated_at,
1812
+ json_object(
1813
+ 'snmp_port', sd.snmp_port,
1814
+ 'snmp_community', sd.snmp_community,
1815
+ 'snmp_version', sd.snmp_version,
1816
+ 'snmp_timeout', sd.snmp_timeout,
1817
+ 'snmp_retries', sd.snmp_retries
1818
+ ) as device_metadata
1819
+ FROM surveilr_snmp_device sd
1820
+ WHERE sd.status = 'active'
1821
+
1822
+ UNION ALL
1823
+
1824
+ SELECT
1825
+ 'osquery_node' as device_type,
1826
+ osq.node_key as device_id,
1827
+ osq.host_identifier as primary_identifier,
1828
+ 'endpoint' as device_category,
1829
+ osq.os_version as description,
1830
+ osq.status,
1831
+ osq.created_at,
1832
+ osq.updated_at,
1833
+ json_object(
1834
+ 'last_seen', osq.last_seen,
1835
+ 'platform', osq.platform,
1836
+ 'osquery_version', osq.osquery_version,
1837
+ 'device_id', osq.device_id
1838
+ ) as device_metadata
1839
+ FROM surveilr_osquery_ms_node osq
1840
+ WHERE osq.status = 'active'`);
1841
+ var deviceGraphCorrelations = sqliteView2("device_graph_correlations", {}).as(sql2`
1842
+ SELECT DISTINCT
1843
+ ure1.node_id as snmp_device_key,
1844
+ ure1.uniform_resource_id as osquery_node_key,
1845
+ CASE
1846
+ WHEN ure1.nature LIKE '%ip_address_match%' THEN 'IP Address Match'
1847
+ WHEN ure1.nature LIKE '%hostname_match%' THEN 'Hostname Match'
1848
+ WHEN ure1.nature LIKE '%mac_address_match%' THEN 'MAC Address Match'
1849
+ WHEN ure1.nature LIKE '%network_topology%' THEN 'Network Topology'
1850
+ WHEN ure1.nature LIKE '%manual%' THEN 'Manual'
1851
+ ELSE 'Unknown'
1852
+ END as correlation_type,
1853
+ CASE
1854
+ WHEN ure1.nature LIKE '%ip_address_match%' THEN 0.95
1855
+ WHEN ure1.nature LIKE '%hostname_match%' THEN 0.85
1856
+ WHEN ure1.nature LIKE '%mac_address_match%' THEN 0.90
1857
+ WHEN ure1.nature LIKE '%network_topology%' THEN 0.70
1858
+ WHEN ure1.nature LIKE '%manual%' THEN 1.0
1859
+ ELSE 0.5
1860
+ END as confidence_score,
1861
+ json_extract(ure1.elaboration, '$.snmp_host') as snmp_host,
1862
+ json_extract(ure1.elaboration, '$.correlation_method') as correlation_method,
1863
+ ure1.elaboration as evidence
1864
+ FROM uniform_resource_edge ure1
1865
+ WHERE ure1.graph_name = 'device_graph'
1866
+ AND ure1.nature LIKE 'snmp_to_osquery_%'
1867
+ ORDER BY ure1.node_id, ure1.uniform_resource_id`);
1868
+ var snmpDeviceInventory = sqliteView2("snmp_device_inventory", {}).as(sql2`
1869
+ SELECT
1870
+ sd.device_key,
1871
+ sd.snmp_host,
1872
+ sd.snmp_port,
1873
+ sd.device_type,
1874
+ sd.device_description,
1875
+ sd.status,
1876
+ sd.created_at,
1877
+ COUNT(sc.surveilr_snmp_collection_id) as total_collections,
1878
+ MAX(sc.collected_at) as last_collection_time,
1879
+ COUNT(DISTINCT sc.oid) as unique_oids_collected,
1880
+ AVG(
1881
+ CASE
1882
+ WHEN sc.collected_at > datetime('now', '-1 hour') THEN 1
1883
+ ELSE 0
1884
+ END
1885
+ ) as recent_activity_score
1886
+ FROM surveilr_snmp_device sd
1887
+ LEFT JOIN surveilr_snmp_collection sc ON sd.device_key = sc.device_key
1888
+ GROUP BY sd.device_key, sd.snmp_host, sd.snmp_port, sd.device_type,
1889
+ sd.device_description, sd.status, sd.created_at
1890
+ ORDER BY sd.status, sd.snmp_host`);
1891
+ var snmpCollectionSummary = sqliteView2("snmp_collection_summary", {}).as(sql2`
1892
+ SELECT
1893
+ sc.device_key,
1894
+ sd.snmp_host,
1895
+ sc.oid_type,
1896
+ COUNT(*) as collection_count,
1897
+ COUNT(DISTINCT sc.oid) as unique_oids,
1898
+ MIN(sc.collected_at) as first_collection,
1899
+ MAX(sc.collected_at) as latest_collection,
1900
+ COUNT(DISTINCT DATE(sc.collected_at)) as collection_days
1901
+ FROM surveilr_snmp_collection sc
1902
+ JOIN surveilr_snmp_device sd ON sc.device_key = sd.device_key
1903
+ GROUP BY sc.device_key, sd.snmp_host, sc.oid_type
1904
+ ORDER BY sd.snmp_host, sc.oid_type`);
1905
+ var networkDeviceTopology = sqliteView2("network_device_topology", {}).as(sql2`
1906
+ SELECT
1907
+ sd.device_key,
1908
+ sd.snmp_host,
1909
+ sd.device_type,
1910
+ -- Extract network information from SNMP collections
1911
+ COALESCE(
1912
+ (SELECT sc.oid_value
1913
+ FROM surveilr_snmp_collection sc
1914
+ WHERE sc.device_key = sd.device_key
1915
+ AND sc.oid LIKE '%.1.3.6.1.2.1.1.1.%'
1916
+ LIMIT 1),
1917
+ 'Unknown'
1918
+ ) as system_description,
1919
+ COALESCE(
1920
+ (SELECT sc.oid_value
1921
+ FROM surveilr_snmp_collection sc
1922
+ WHERE sc.device_key = sd.device_key
1923
+ AND sc.oid LIKE '%.1.3.6.1.2.1.1.5.%'
1924
+ LIMIT 1),
1925
+ 'Unknown'
1926
+ ) as system_name,
1927
+ -- Count correlated devices
1928
+ (SELECT COUNT(*)
1929
+ FROM device_graph_correlations dgc
1930
+ WHERE dgc.snmp_device_key = sd.device_key
1931
+ ) as correlated_devices_count,
1932
+ sd.status,
1933
+ sd.created_at
1934
+ FROM surveilr_snmp_device sd
1935
+ WHERE sd.status = 'active'
1936
+ ORDER BY sd.snmp_host`);
1937
+ var deviceGraphAnalytics = sqliteView2("device_graph_analytics", {}).as(sql2`
1938
+ SELECT
1939
+ 'summary' as metric_type,
1940
+ 'total_snmp_devices' as metric_name,
1941
+ COUNT(*) as metric_value,
1942
+ NULL as additional_info
1943
+ FROM surveilr_snmp_device
1944
+ WHERE status = 'active'
1945
+
1946
+ UNION ALL
1947
+
1948
+ SELECT
1949
+ 'summary' as metric_type,
1950
+ 'total_osquery_nodes' as metric_name,
1951
+ COUNT(*) as metric_value,
1952
+ NULL as additional_info
1953
+ FROM surveilr_osquery_ms_node
1954
+ WHERE status = 'active'
1955
+
1956
+ UNION ALL
1957
+
1958
+ SELECT
1959
+ 'summary' as metric_type,
1960
+ 'total_correlations' as metric_name,
1961
+ COUNT(*) as metric_value,
1962
+ NULL as additional_info
1963
+ FROM device_graph_correlations
1964
+
1965
+ UNION ALL
1966
+
1967
+ SELECT
1968
+ 'summary' as metric_type,
1969
+ 'correlation_types' as metric_name,
1970
+ COUNT(DISTINCT correlation_type) as metric_value,
1971
+ GROUP_CONCAT(DISTINCT correlation_type) as additional_info
1972
+ FROM device_graph_correlations
1973
+
1974
+ UNION ALL
1975
+
1976
+ SELECT
1977
+ 'correlation_by_type' as metric_type,
1978
+ correlation_type as metric_name,
1979
+ COUNT(*) as metric_value,
1980
+ printf('avg_confidence: %.2f', AVG(confidence_score)) as additional_info
1981
+ FROM device_graph_correlations
1982
+ GROUP BY correlation_type
1983
+
1984
+ UNION ALL
1985
+
1986
+ SELECT
1987
+ 'collection_stats' as metric_type,
1988
+ 'total_snmp_collections' as metric_name,
1989
+ COUNT(*) as metric_value,
1990
+ printf('unique_devices: %d', COUNT(DISTINCT device_key)) as additional_info
1991
+ FROM surveilr_snmp_collection
1992
+
1993
+ UNION ALL
1994
+
1995
+ SELECT
1996
+ 'collection_stats' as metric_type,
1997
+ 'collection_activity_last_24h' as metric_name,
1998
+ COUNT(*) as metric_value,
1999
+ printf('devices_active: %d', COUNT(DISTINCT device_key)) as additional_info
2000
+ FROM surveilr_snmp_collection
2001
+ WHERE collected_at > datetime('now', '-24 hours')`);
2002
+ var snmpOidPerformance = sqliteView2("snmp_oid_performance", {}).as(sql2`
2003
+ SELECT
2004
+ sc.oid,
2005
+ sc.oid_type,
2006
+ COUNT(*) as total_collections,
2007
+ COUNT(DISTINCT sc.device_key) as devices_collecting,
2008
+ COUNT(DISTINCT DATE(sc.collected_at)) as collection_days,
2009
+ MIN(sc.collected_at) as first_seen,
2010
+ MAX(sc.collected_at) as last_seen,
2011
+ -- Calculate collection frequency (avoid nested aggregates)
2012
+ CAST(
2013
+ COUNT(*) * 1.0 /
2014
+ NULLIF(MAX(julianday(sc.collected_at)) - MIN(julianday(sc.collected_at)), 0)
2015
+ AS REAL) as avg_collections_per_day,
2016
+ -- Sample values for diversity analysis
2017
+ COUNT(DISTINCT sc.oid_value) as unique_values_count,
2018
+ GROUP_CONCAT(DISTINCT sc.oid_value) as sample_values
2019
+ FROM surveilr_snmp_collection sc
2020
+ GROUP BY sc.oid, sc.oid_type
2021
+ HAVING COUNT(*) > 0
2022
+ ORDER BY total_collections DESC, devices_collecting DESC`);
114
2023
 
115
- // relations.ts
2024
+ // ../../drizzle/relations.ts
116
2025
  import { relations } from "drizzle-orm/relations";
117
2026
  var codeNotebookCellRelations = relations(codeNotebookCell, ({ one, many }) => ({
118
2027
  codeNotebookKernel: one(codeNotebookKernel, {