@coffre/db 0.14.5 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/change-records-_fKvahvs.js +55 -0
- package/dist/connect.d.ts +22 -10
- package/dist/connect.js +74 -12
- package/dist/database-CVteLhp1.d.ts +410 -0
- package/dist/{database-BadNeeN-.js → database-D55ENPX-.js} +46 -25
- package/dist/dialect.d.ts +4 -3
- package/dist/dialect.js +14 -5
- package/dist/grants.d.ts +4 -4
- package/dist/grants.js +4 -4
- package/dist/hyperdrive.d.ts +48 -23
- package/dist/hyperdrive.js +168 -91
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/log-DaD7fyUq.d.ts +722 -0
- package/dist/log.d.ts +2 -622
- package/dist/log.js +178 -13
- package/dist/migrate.d.ts +43 -3
- package/dist/migrate.js +149 -29
- package/dist/migrations/postgres/0022_log_015.sql +672 -0
- package/dist/migrations/postgres/0023_change_path.sql +153 -0
- package/dist/migrations/postgres/0024_use_015.sql +556 -0
- package/dist/migrations/postgres/0025_app_change.sql +221 -0
- package/dist/migrations/postgres/0026_issue_lock.sql +106 -0
- package/dist/migrations/postgres/0027_retention.sql +118 -0
- package/dist/migrations/postgres/0028_use_stalls.sql +594 -0
- package/dist/migrations/postgres/0029_use_objects.sql +887 -0
- package/dist/migrations/postgres/0030_unarchive_restores.sql +259 -0
- package/dist/migrations/postgres/0031_app_read.sql +65 -0
- package/dist/migrations/postgres/0032_secrets_live_index.sql +4 -0
- package/dist/migrations/postgres/0033_use_generations.sql +582 -0
- package/dist/migrations/postgres/0034_vault_credentials.sql +153 -0
- package/dist/migrations/postgres/0035_first_days.sql +3 -0
- package/dist/migrations/postgres/0036_vault_issues.sql +91 -0
- package/dist/migrations/postgres/0037_vault_bindings.sql +271 -0
- package/dist/migrations/postgres/0040_binding_origin.sql +159 -0
- package/dist/migrations/postgres/0041_cutover.sql +132 -0
- package/dist/migrations/postgres/0042_sign_in_index.sql +7 -0
- package/dist/migrations/postgres/0043_issue_revoke_index.sql +4 -0
- package/dist/migrations/postgres/0044_use_by_name.sql +705 -0
- package/dist/migrations/postgres/0045_decide_first.sql +878 -0
- package/dist/migrations/postgres/0046_way_in_uses.sql +1149 -0
- package/dist/migrations/postgres/0047_cutover_finish.sql +268 -0
- package/dist/migrations/postgres/0048_use_batch.sql +59 -0
- package/dist/migrations/postgres/0049_reads.sql +171 -0
- package/dist/migrations/postgres/meta/0022_snapshot.json +3831 -0
- package/dist/migrations/postgres/meta/0023_snapshot.json +3831 -0
- package/dist/migrations/postgres/meta/0024_snapshot.json +3831 -0
- package/dist/migrations/postgres/meta/0025_snapshot.json +3831 -0
- package/dist/migrations/postgres/meta/0026_snapshot.json +3831 -0
- package/dist/migrations/postgres/meta/0027_snapshot.json +3853 -0
- package/dist/migrations/postgres/meta/0028_snapshot.json +3853 -0
- package/dist/migrations/postgres/meta/0029_snapshot.json +3859 -0
- package/dist/migrations/postgres/meta/0030_snapshot.json +3859 -0
- package/dist/migrations/postgres/meta/0031_snapshot.json +3859 -0
- package/dist/migrations/postgres/meta/0032_snapshot.json +3875 -0
- package/dist/migrations/postgres/meta/0033_snapshot.json +3875 -0
- package/dist/migrations/postgres/meta/0034_snapshot.json +3875 -0
- package/dist/migrations/postgres/meta/0035_snapshot.json +3875 -0
- package/dist/migrations/postgres/meta/0036_snapshot.json +3875 -0
- package/dist/migrations/postgres/meta/0037_snapshot.json +3875 -0
- package/dist/migrations/postgres/meta/0038_snapshot.json +3881 -0
- package/dist/migrations/postgres/meta/0039_snapshot.json +3881 -0
- package/dist/migrations/postgres/meta/0040_snapshot.json +3931 -0
- package/dist/migrations/postgres/meta/0041_snapshot.json +3981 -0
- package/dist/migrations/postgres/meta/0042_snapshot.json +3981 -0
- package/dist/migrations/postgres/meta/0043_snapshot.json +3981 -0
- package/dist/migrations/postgres/meta/0044_snapshot.json +3991 -0
- package/dist/migrations/postgres/meta/0045_snapshot.json +3997 -0
- package/dist/migrations/postgres/meta/0046_snapshot.json +3997 -0
- package/dist/migrations/postgres/meta/0047_snapshot.json +4234 -0
- package/dist/migrations/postgres/meta/_journal.json +182 -0
- package/dist/migrations/sqlite/0018_log_015.sql +84 -0
- package/dist/migrations/sqlite/0019_retention.sql +2 -0
- package/dist/migrations/sqlite/0020_ended_references.sql +1 -0
- package/dist/migrations/sqlite/0021_secrets_live_index.sql +1 -0
- package/dist/migrations/sqlite/0022_binding_origin.sql +1 -0
- package/dist/migrations/sqlite/0023_sign_in_index.sql +2 -0
- package/dist/migrations/sqlite/0024_issue_revoke_index.sql +2 -0
- package/dist/migrations/sqlite/0025_way_in_uses.sql +42 -0
- package/dist/migrations/sqlite/0026_cutover_finish.sql +11 -0
- package/dist/migrations/sqlite/0027_reads.sql +38 -0
- package/dist/migrations/sqlite/meta/0018_snapshot.json +3529 -0
- package/dist/migrations/sqlite/meta/0019_snapshot.json +3538 -0
- package/dist/migrations/sqlite/meta/0020_snapshot.json +3545 -0
- package/dist/migrations/sqlite/meta/0021_snapshot.json +3553 -0
- package/dist/migrations/sqlite/meta/0022_snapshot.json +3560 -0
- package/dist/migrations/sqlite/meta/0023_snapshot.json +3579 -0
- package/dist/migrations/sqlite/meta/0024_snapshot.json +3598 -0
- package/dist/migrations/sqlite/meta/0025_snapshot.json +3609 -0
- package/dist/migrations/sqlite/meta/0026_snapshot.json +3616 -0
- package/dist/migrations/sqlite/meta/0027_snapshot.json +3834 -0
- package/dist/migrations/sqlite/meta/_journal.json +70 -0
- package/dist/platform-Y3gICK6n.d.ts +58 -0
- package/dist/portable.d.ts +2 -2
- package/dist/postgres-BI3xTnyw.js +1718 -0
- package/dist/postgres-platform-node.d.ts +14 -0
- package/dist/postgres-platform-node.js +21 -0
- package/dist/postgres-platform-workerd.d.ts +61 -0
- package/dist/postgres-platform-workerd.js +163 -0
- package/dist/{schema-BfQEBqFv.d.ts → schema-DgoPqqsI.d.ts} +1326 -7
- package/dist/schema-sqlite.d.ts +1306 -6
- package/dist/schema-sqlite.js +154 -18
- package/dist/schema-version.d.ts +1 -1
- package/dist/schema-version.js +254 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +226 -20
- package/package.json +13 -5
- package/src/active-subject.ts +9 -0
- package/src/change-records.ts +38 -0
- package/src/connect.ts +67 -13
- package/src/database.ts +67 -51
- package/src/dialect.ts +17 -8
- package/src/grants.ts +3 -3
- package/src/hyperdrive.ts +181 -104
- package/src/log.ts +196 -15
- package/src/migrate.ts +157 -30
- package/src/migrations/postgres/0022_log_015.sql +672 -0
- package/src/migrations/postgres/0023_change_path.sql +153 -0
- package/src/migrations/postgres/0024_use_015.sql +556 -0
- package/src/migrations/postgres/0025_app_change.sql +221 -0
- package/src/migrations/postgres/0026_issue_lock.sql +106 -0
- package/src/migrations/postgres/0027_retention.sql +118 -0
- package/src/migrations/postgres/0028_use_stalls.sql +594 -0
- package/src/migrations/postgres/0029_use_objects.sql +887 -0
- package/src/migrations/postgres/0030_unarchive_restores.sql +259 -0
- package/src/migrations/postgres/0031_app_read.sql +65 -0
- package/src/migrations/postgres/0032_secrets_live_index.sql +4 -0
- package/src/migrations/postgres/0033_use_generations.sql +582 -0
- package/src/migrations/postgres/0034_vault_credentials.sql +153 -0
- package/src/migrations/postgres/0035_first_days.sql +3 -0
- package/src/migrations/postgres/0036_vault_issues.sql +91 -0
- package/src/migrations/postgres/0037_vault_bindings.sql +271 -0
- package/src/migrations/postgres/0040_binding_origin.sql +159 -0
- package/src/migrations/postgres/0041_cutover.sql +132 -0
- package/src/migrations/postgres/0042_sign_in_index.sql +7 -0
- package/src/migrations/postgres/0043_issue_revoke_index.sql +4 -0
- package/src/migrations/postgres/0044_use_by_name.sql +705 -0
- package/src/migrations/postgres/0045_decide_first.sql +878 -0
- package/src/migrations/postgres/0046_way_in_uses.sql +1149 -0
- package/src/migrations/postgres/0047_cutover_finish.sql +268 -0
- package/src/migrations/postgres/0048_use_batch.sql +59 -0
- package/src/migrations/postgres/0049_reads.sql +171 -0
- package/src/migrations/postgres/meta/0022_snapshot.json +3831 -0
- package/src/migrations/postgres/meta/0023_snapshot.json +3831 -0
- package/src/migrations/postgres/meta/0024_snapshot.json +3831 -0
- package/src/migrations/postgres/meta/0025_snapshot.json +3831 -0
- package/src/migrations/postgres/meta/0026_snapshot.json +3831 -0
- package/src/migrations/postgres/meta/0027_snapshot.json +3853 -0
- package/src/migrations/postgres/meta/0028_snapshot.json +3853 -0
- package/src/migrations/postgres/meta/0029_snapshot.json +3859 -0
- package/src/migrations/postgres/meta/0030_snapshot.json +3859 -0
- package/src/migrations/postgres/meta/0031_snapshot.json +3859 -0
- package/src/migrations/postgres/meta/0032_snapshot.json +3875 -0
- package/src/migrations/postgres/meta/0033_snapshot.json +3875 -0
- package/src/migrations/postgres/meta/0034_snapshot.json +3875 -0
- package/src/migrations/postgres/meta/0035_snapshot.json +3875 -0
- package/src/migrations/postgres/meta/0036_snapshot.json +3875 -0
- package/src/migrations/postgres/meta/0037_snapshot.json +3875 -0
- package/src/migrations/postgres/meta/0038_snapshot.json +3881 -0
- package/src/migrations/postgres/meta/0039_snapshot.json +3881 -0
- package/src/migrations/postgres/meta/0040_snapshot.json +3931 -0
- package/src/migrations/postgres/meta/0041_snapshot.json +3981 -0
- package/src/migrations/postgres/meta/0042_snapshot.json +3981 -0
- package/src/migrations/postgres/meta/0043_snapshot.json +3981 -0
- package/src/migrations/postgres/meta/0044_snapshot.json +3991 -0
- package/src/migrations/postgres/meta/0045_snapshot.json +3997 -0
- package/src/migrations/postgres/meta/0046_snapshot.json +3997 -0
- package/src/migrations/postgres/meta/0047_snapshot.json +4234 -0
- package/src/migrations/postgres/meta/_journal.json +182 -0
- package/src/migrations/sqlite/0018_log_015.sql +84 -0
- package/src/migrations/sqlite/0019_retention.sql +2 -0
- package/src/migrations/sqlite/0020_ended_references.sql +1 -0
- package/src/migrations/sqlite/0021_secrets_live_index.sql +1 -0
- package/src/migrations/sqlite/0022_binding_origin.sql +1 -0
- package/src/migrations/sqlite/0023_sign_in_index.sql +2 -0
- package/src/migrations/sqlite/0024_issue_revoke_index.sql +2 -0
- package/src/migrations/sqlite/0025_way_in_uses.sql +42 -0
- package/src/migrations/sqlite/0026_cutover_finish.sql +11 -0
- package/src/migrations/sqlite/0027_reads.sql +38 -0
- package/src/migrations/sqlite/meta/0018_snapshot.json +3529 -0
- package/src/migrations/sqlite/meta/0019_snapshot.json +3538 -0
- package/src/migrations/sqlite/meta/0020_snapshot.json +3545 -0
- package/src/migrations/sqlite/meta/0021_snapshot.json +3553 -0
- package/src/migrations/sqlite/meta/0022_snapshot.json +3560 -0
- package/src/migrations/sqlite/meta/0023_snapshot.json +3579 -0
- package/src/migrations/sqlite/meta/0024_snapshot.json +3598 -0
- package/src/migrations/sqlite/meta/0025_snapshot.json +3609 -0
- package/src/migrations/sqlite/meta/0026_snapshot.json +3616 -0
- package/src/migrations/sqlite/meta/0027_snapshot.json +3834 -0
- package/src/migrations/sqlite/meta/_journal.json +70 -0
- package/src/postgres-js/README.md +183 -0
- package/src/postgres-js/UNLICENSE +24 -0
- package/src/postgres-js/bytes.ts +89 -0
- package/src/postgres-js/connection.ts +882 -0
- package/src/postgres-js/errors.ts +84 -0
- package/src/postgres-js/index.ts +516 -0
- package/src/postgres-js/platform.node.ts +29 -0
- package/src/postgres-js/platform.ts +60 -0
- package/src/postgres-js/platform.workerd.ts +225 -0
- package/src/postgres-js/query.ts +123 -0
- package/src/postgres-js/queue.ts +42 -0
- package/src/postgres-js/result.ts +46 -0
- package/src/postgres-js/types.ts +52 -0
- package/src/postgres.ts +375 -26
- package/src/schema-version.ts +2 -2
- package/src/schema.sqlite.ts +198 -7
- package/src/schema.ts +291 -6
- package/src/verify-runtime.ts +18 -29
- package/LICENSE +0 -21
- package/dist/database-wq1AVRAP.d.ts +0 -73
- package/dist/postgres-Bmar8y0q.js +0 -29
- package/dist/relations-BfR3JjT1.js +0 -38
- package/src/relations.ts +0 -40
package/src/schema.sqlite.ts
CHANGED
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
type AnySQLiteColumn,
|
|
15
15
|
} from 'drizzle-orm/sqlite-core';
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { ACTIVE_SUBJECT } from './active-subject.ts';
|
|
18
|
+
import { recorded } from './change-records.ts';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* The schema in schema.ts, for SQLite (through libsql). Same tables,
|
|
@@ -86,8 +86,12 @@ export const environments = sqliteTable(
|
|
|
86
86
|
archivedAt: time('archived_at'),
|
|
87
87
|
parentId: text('parent_id'),
|
|
88
88
|
owner: text(),
|
|
89
|
+
protected: flag('protected'),
|
|
90
|
+
// 0.15's seal (schema.ts).
|
|
91
|
+
seal: bytes('seal'),
|
|
89
92
|
},
|
|
90
93
|
(table) => [
|
|
94
|
+
check('environments_seal_check', sql`${table.seal} IS NULL OR octet_length(${table.seal}) = 16`),
|
|
91
95
|
unique('environments_project_id_slug_key').on(table.projectId, table.slug),
|
|
92
96
|
unique('environments_project_scoped').on(table.id, table.projectId),
|
|
93
97
|
check('environments_slug_check', isPlaceSlug(table.slug)),
|
|
@@ -125,8 +129,11 @@ export const secrets = sqliteTable(
|
|
|
125
129
|
currentVersion: integer('current_version').notNull().default(0),
|
|
126
130
|
archivedAt: time('archived_at'),
|
|
127
131
|
folder: text(),
|
|
132
|
+
// 0.15's seal (schema.ts).
|
|
133
|
+
seal: bytes('seal'),
|
|
128
134
|
},
|
|
129
135
|
(table) => [
|
|
136
|
+
check('secrets_seal_check', sql`${table.seal} IS NULL OR octet_length(${table.seal}) = 16`),
|
|
130
137
|
unique('secrets_project_id_environment_id_key_key').on(table.projectId, table.environmentId, table.key),
|
|
131
138
|
check(
|
|
132
139
|
'secrets_key_check',
|
|
@@ -149,6 +156,8 @@ export const secrets = sqliteTable(
|
|
|
149
156
|
foreignColumns: [environments.id, environments.projectId],
|
|
150
157
|
}),
|
|
151
158
|
index('secrets_lookup_idx').on(table.projectId, table.environmentId, table.key),
|
|
159
|
+
// The live keys of an environment, which a read by environment alone (the places tree's counts, `liveKeysIn`) walks without the archived ones beside them; the one above leads with the project (T152, 0032).
|
|
160
|
+
index('secrets_live_idx').on(table.environmentId).where(sql`${table.archivedAt} IS NULL`),
|
|
152
161
|
],
|
|
153
162
|
);
|
|
154
163
|
|
|
@@ -240,8 +249,11 @@ export const vaultMembers = sqliteTable(
|
|
|
240
249
|
statusChangedBy: text('status_changed_by').notNull(),
|
|
241
250
|
accessSeq: int64('access_seq').notNull(),
|
|
242
251
|
mac: bytes('mac').notNull(),
|
|
252
|
+
// 0.15's seal (schema.ts).
|
|
253
|
+
seal: bytes('seal'),
|
|
243
254
|
},
|
|
244
255
|
(table) => [
|
|
256
|
+
check('vault_members_seal_check', sql`${table.seal} IS NULL OR octet_length(${table.seal}) = 16`),
|
|
245
257
|
check('vault_members_mac_check', sql`octet_length(${table.mac}) = 32`),
|
|
246
258
|
// `^(user|token):[^[:space:]:][^[:space:]]*$`, without regular expressions.
|
|
247
259
|
check(
|
|
@@ -357,6 +369,8 @@ export const auditLog = sqliteTable(
|
|
|
357
369
|
prevHash: bytes('prev_hash').notNull(),
|
|
358
370
|
mac: bytes('mac').notNull(),
|
|
359
371
|
hash: bytes('hash').notNull(),
|
|
372
|
+
// Set on every entry a writer under 0.15's log appends (schema.ts says why).
|
|
373
|
+
log015: flag('log015'),
|
|
360
374
|
},
|
|
361
375
|
(table) => [
|
|
362
376
|
check('audit_log_author_check', sql`${table.author} IN ('app', 'vault')`),
|
|
@@ -451,6 +465,10 @@ export const secretReferences = sqliteTable(
|
|
|
451
465
|
createdSeq: int64('created_seq').notNull(),
|
|
452
466
|
createdAt: createdAt(),
|
|
453
467
|
createdBy: text('created_by').notNull(),
|
|
468
|
+
// 0.15's end of the reference (0028): when its holder stopped reading its source, broken, replaced or cut, written
|
|
469
|
+
// with 0.14's `reference.end` in the vault's decision. The holder's object reads its newest row's source only while
|
|
470
|
+
// this is null. Null on rows 0.14 ended: 0.14's log holds those ends, which the cutover (plan PR 9) writes here.
|
|
471
|
+
endedAt: time('ended_at'),
|
|
454
472
|
},
|
|
455
473
|
(table) => [
|
|
456
474
|
unique('secret_references_created_seq_key').on(table.createdSeq),
|
|
@@ -546,14 +564,19 @@ export const serviceBindings = sqliteTable(
|
|
|
546
564
|
scope: text(),
|
|
547
565
|
// What a workload's binding says beyond its claims (`BindingPolicy`), canonical JSON: null on a binding `/api/auth/oidc` takes, never on another (docs/design/workload-access.md, section 11).
|
|
548
566
|
policy: text(),
|
|
567
|
+
// The instance it was made on (schema.ts).
|
|
568
|
+
origin: text(),
|
|
549
569
|
label: text(),
|
|
550
570
|
createdAt: createdAt(),
|
|
551
571
|
createdBy: text('created_by').notNull(),
|
|
552
572
|
lastUsedAt: time('last_used_at'),
|
|
553
573
|
revokedAt: time('revoked_at'),
|
|
554
574
|
revokedBy: text('revoked_by'),
|
|
575
|
+
// 0.15's seal (schema.ts).
|
|
576
|
+
seal: bytes('seal'),
|
|
555
577
|
},
|
|
556
578
|
(table) => [
|
|
579
|
+
check('service_bindings_seal_check', sql`${table.seal} IS NULL OR octet_length(${table.seal}) = 16`),
|
|
557
580
|
check('service_bindings_principal_check', sql`${table.principal} LIKE 'token:%'`),
|
|
558
581
|
check('service_bindings_auth_mac_check', sql`octet_length(${table.authMac}) = 32`),
|
|
559
582
|
check('service_bindings_claims_check', sql`json_valid(${table.claims})`),
|
|
@@ -651,8 +674,11 @@ export const mcpConnections = sqliteTable(
|
|
|
651
674
|
lastUsedIp: text('last_used_ip'),
|
|
652
675
|
revokedAt: time('revoked_at'),
|
|
653
676
|
revokedBy: text('revoked_by'),
|
|
677
|
+
// 0.15's seal (schema.ts).
|
|
678
|
+
seal: bytes('seal'),
|
|
654
679
|
},
|
|
655
680
|
(table) => [
|
|
681
|
+
check('mcp_connections_seal_check', sql`${table.seal} IS NULL OR octet_length(${table.seal}) = 16`),
|
|
656
682
|
check('mcp_connections_principal_check', sql`${table.principal} LIKE 'user:%'`),
|
|
657
683
|
check('mcp_connections_registration_check', sql`${table.registration} IN ('cimd', 'dcr')`),
|
|
658
684
|
check('mcp_connections_auth_mac_check', sql`octet_length(${table.authMac}) = 32`),
|
|
@@ -778,8 +804,11 @@ export const credentials = sqliteTable(
|
|
|
778
804
|
enrollmentId: text('enrollment_id'),
|
|
779
805
|
approvedAt: time('approved_at'),
|
|
780
806
|
approvedBy: text('approved_by'),
|
|
807
|
+
// 0.15's seal (schema.ts).
|
|
808
|
+
seal: bytes('seal'),
|
|
781
809
|
},
|
|
782
810
|
(table) => [
|
|
811
|
+
check('credentials_seal_check', sql`${table.seal} IS NULL OR octet_length(${table.seal}) = 16`),
|
|
783
812
|
unique('credentials_token_hash_key').on(table.tokenHash),
|
|
784
813
|
check('credentials_kind_check', sql`${table.kind} IN ('browser', 'cli', 'service', 'personal', 'handle', 'workload')`),
|
|
785
814
|
check('credentials_principal_check', sql`${table.principal} LIKE 'user:%' OR ${table.principal} LIKE 'token:%'`),
|
|
@@ -858,9 +887,171 @@ export const deviceAuthorizations = sqliteTable(
|
|
|
858
887
|
],
|
|
859
888
|
);
|
|
860
889
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
890
|
+
/** 0.15's configuration objects (schema.ts). */
|
|
891
|
+
export const logConfig = sqliteTable(
|
|
892
|
+
'log_config',
|
|
893
|
+
{
|
|
894
|
+
name: text().primaryKey(),
|
|
895
|
+
value: text().notNull(),
|
|
896
|
+
seal: bytes('seal'),
|
|
897
|
+
},
|
|
898
|
+
(table) => [
|
|
899
|
+
check('log_config_name_check', sql`${table.name} IN ('policy', 'roles')`),
|
|
900
|
+
check('log_config_value_check', sql`json_valid(${table.value})`),
|
|
901
|
+
check('log_config_seal_check', sql`${table.seal} IS NULL OR octet_length(${table.seal}) = 16`),
|
|
902
|
+
],
|
|
903
|
+
);
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* 0.15's log (schema.ts). SQLite has one writer, so the fence is implicit,
|
|
907
|
+
* and nothing is partitioned: uses and tiles are one table each.
|
|
908
|
+
*/
|
|
909
|
+
export const logChanges = sqliteTable(
|
|
910
|
+
'log_changes',
|
|
911
|
+
{
|
|
912
|
+
number: int64('number').primaryKey(),
|
|
913
|
+
at: integer({ mode: 'number' }).notNull(),
|
|
914
|
+
requestId: text('request_id').notNull(),
|
|
915
|
+
object: text().notNull(),
|
|
916
|
+
actor: text().notNull(),
|
|
917
|
+
payload: text().notNull(),
|
|
918
|
+
seal: bytes('seal'),
|
|
919
|
+
mac: bytes('mac').notNull(),
|
|
920
|
+
},
|
|
921
|
+
(table) => [
|
|
922
|
+
unique('log_changes_request_id_key').on(table.requestId),
|
|
923
|
+
check('log_changes_seal_check', sql`${table.seal} IS NULL OR octet_length(${table.seal}) = 16`),
|
|
924
|
+
check('log_changes_mac_check', sql`octet_length(${table.mac}) = 16`),
|
|
925
|
+
index('log_changes_object_idx').on(table.object, table.number),
|
|
926
|
+
// The sign-ins through trust bindings (schema.ts).
|
|
927
|
+
index('log_changes_sign_in_idx').on(table.at, table.number).where(recorded('sqlite', table.payload, 'signIn')),
|
|
928
|
+
index('log_changes_sign_in_actor_idx').on(table.actor, table.at, table.number).where(recorded('sqlite', table.payload, 'signIn')),
|
|
929
|
+
// The vault's token issues, revokes and sign-outs (schema.ts).
|
|
930
|
+
index('log_changes_issue_revoke_idx').on(table.at, table.number).where(recorded('sqlite', table.payload, 'issue', 'revoke', 'signOut')),
|
|
931
|
+
index('log_changes_issue_revoke_actor_idx').on(table.actor, table.at, table.number).where(recorded('sqlite', table.payload, 'issue', 'revoke', 'signOut')),
|
|
932
|
+
],
|
|
933
|
+
);
|
|
934
|
+
|
|
935
|
+
export const logUses = sqliteTable(
|
|
936
|
+
'log_uses',
|
|
937
|
+
{
|
|
938
|
+
number: int64('number').notNull(),
|
|
939
|
+
at: integer({ mode: 'number' }).notNull(),
|
|
940
|
+
requestId: int64('request_id').notNull(),
|
|
941
|
+
credential: text().notNull(),
|
|
942
|
+
secret: text().notNull(),
|
|
943
|
+
purpose: integer().notNull(),
|
|
944
|
+
mac: bytes('mac').notNull(),
|
|
945
|
+
place: text(),
|
|
946
|
+
},
|
|
947
|
+
(table) => [
|
|
948
|
+
check('log_uses_mac_check', sql`octet_length(${table.mac}) = 16`),
|
|
949
|
+
uniqueIndex('log_uses_request_idx').on(table.at, table.requestId),
|
|
950
|
+
],
|
|
951
|
+
);
|
|
952
|
+
|
|
953
|
+
/** 0.15's reads as the audit pages list them (schema.ts). */
|
|
954
|
+
export const logReads = sqliteTable(
|
|
955
|
+
'log_reads',
|
|
956
|
+
{
|
|
957
|
+
number: int64('number').notNull(),
|
|
958
|
+
at: integer({ mode: 'number' }).notNull(),
|
|
959
|
+
credential: text().notNull(),
|
|
960
|
+
purpose: integer().notNull(),
|
|
961
|
+
principal: text().notNull(),
|
|
962
|
+
secret: text().notNull(),
|
|
963
|
+
environment: text().notNull(),
|
|
964
|
+
project: text().notNull(),
|
|
965
|
+
place: text(),
|
|
966
|
+
source: text(),
|
|
967
|
+
sourceEnvironment: text('source_environment'),
|
|
968
|
+
sourceProject: text('source_project'),
|
|
969
|
+
version: text(),
|
|
970
|
+
mac: bytes('mac').notNull(),
|
|
971
|
+
},
|
|
972
|
+
(table) => [
|
|
973
|
+
check('log_reads_mac_check', sql`octet_length(${table.mac}) = 16`),
|
|
974
|
+
uniqueIndex('log_reads_number_idx').on(table.at, table.number),
|
|
975
|
+
index('log_reads_principal_idx').on(table.principal, table.at, table.number),
|
|
976
|
+
],
|
|
977
|
+
);
|
|
978
|
+
|
|
979
|
+
/** The days each member's reads are in (`log_reads`), so that a page of theirs reads those days alone: the projector writes them with the reads. */
|
|
980
|
+
export const logReadDays = sqliteTable(
|
|
981
|
+
'log_read_days',
|
|
982
|
+
{ principal: text().notNull(), day: integer({ mode: 'number' }).notNull() },
|
|
983
|
+
(table) => [primaryKey({ name: 'log_read_days_pkey', columns: [table.principal, table.day] })],
|
|
984
|
+
);
|
|
985
|
+
|
|
986
|
+
/** How far the projector has gone (schema.ts). */
|
|
987
|
+
export const logReadsCursor = sqliteTable(
|
|
988
|
+
'log_reads_cursor',
|
|
989
|
+
{
|
|
990
|
+
onlyRow: flag('only_row').primaryKey().default(true),
|
|
991
|
+
through: int64('through').notNull(),
|
|
992
|
+
pair: int64('pair').notNull(),
|
|
993
|
+
at: integer({ mode: 'number' }).notNull(),
|
|
994
|
+
mac: bytes('mac'),
|
|
995
|
+
},
|
|
996
|
+
(table) => [
|
|
997
|
+
check('log_reads_cursor_only_row_check', sql`${table.onlyRow}`),
|
|
998
|
+
check('log_reads_cursor_mac_check', sql`${table.mac} IS NULL OR octet_length(${table.mac}) = 16`),
|
|
999
|
+
],
|
|
1000
|
+
);
|
|
1001
|
+
|
|
1002
|
+
export const logBulk = sqliteTable(
|
|
1003
|
+
'log_bulk',
|
|
1004
|
+
{
|
|
1005
|
+
principal: text().notNull(),
|
|
1006
|
+
secret: text().notNull(),
|
|
1007
|
+
last: integer({ mode: 'number' }).notNull(),
|
|
1008
|
+
},
|
|
1009
|
+
(table) => [primaryKey({ name: 'log_bulk_pkey', columns: [table.principal, table.secret] })],
|
|
1010
|
+
);
|
|
1011
|
+
|
|
1012
|
+
export const logFence = sqliteTable(
|
|
1013
|
+
'log_fence',
|
|
1014
|
+
{
|
|
1015
|
+
onlyRow: flag('only_row').primaryKey().default(true),
|
|
1016
|
+
atFloor: integer('at_floor', { mode: 'number' }).notNull(),
|
|
1017
|
+
},
|
|
1018
|
+
(table) => [check('log_fence_only_row_check', sql`${table.onlyRow}`)],
|
|
1019
|
+
);
|
|
1020
|
+
|
|
1021
|
+
export const logCheckpoints = sqliteTable(
|
|
1022
|
+
'log_checkpoints',
|
|
1023
|
+
{
|
|
1024
|
+
upto: int64('upto').primaryKey(),
|
|
1025
|
+
at: integer({ mode: 'number' }).notNull(),
|
|
1026
|
+
atFloor: integer('at_floor', { mode: 'number' }).notNull(),
|
|
1027
|
+
changesSize: int64('changes_size').notNull(),
|
|
1028
|
+
changesRoot: bytes('changes_root').notNull(),
|
|
1029
|
+
changesNote: text('changes_note').notNull(),
|
|
1030
|
+
usesSize: int64('uses_size').notNull(),
|
|
1031
|
+
usesRoot: bytes('uses_root').notNull(),
|
|
1032
|
+
usesNote: text('uses_note').notNull(),
|
|
1033
|
+
},
|
|
1034
|
+
(table) => [
|
|
1035
|
+
check('log_checkpoints_changes_root_check', sql`octet_length(${table.changesRoot}) = 32`),
|
|
1036
|
+
check('log_checkpoints_uses_root_check', sql`octet_length(${table.usesRoot}) = 32`),
|
|
1037
|
+
index('log_checkpoints_floor_idx').on(table.atFloor, table.upto),
|
|
1038
|
+
],
|
|
1039
|
+
);
|
|
1040
|
+
|
|
1041
|
+
export const logTiles = sqliteTable(
|
|
1042
|
+
'log_tiles',
|
|
1043
|
+
{
|
|
1044
|
+
tree: text().notNull(),
|
|
1045
|
+
level: integer().notNull(),
|
|
1046
|
+
leaf: int64('leaf').notNull(),
|
|
1047
|
+
hashes: bytes('hashes').notNull(),
|
|
1048
|
+
},
|
|
1049
|
+
(table) => [
|
|
1050
|
+
primaryKey({ name: 'log_tiles_pkey', columns: [table.tree, table.level, table.leaf] }),
|
|
1051
|
+
check('log_tiles_tree_check', sql`${table.tree} IN ('changes', 'uses')`),
|
|
1052
|
+
check('log_tiles_level_check', sql`${table.level} BETWEEN 0 AND 7`),
|
|
1053
|
+
// 256^8 is past 64 bits: the top level's one tile starts at 0.
|
|
1054
|
+
check('log_tiles_leaf_check', sql`${table.leaf} >= 0 AND ((${table.level} = 7 AND ${table.leaf} = 0) OR (${table.level} < 7 AND ${table.leaf} % (1 << (8 * (${table.level} + 1))) = 0))`),
|
|
1055
|
+
check('log_tiles_hashes_check', sql`octet_length(${table.hashes}) BETWEEN 32 AND 8192 AND octet_length(${table.hashes}) % 32 = 0`),
|
|
1056
|
+
],
|
|
866
1057
|
);
|