@vrplatform/kysely 1.3.45-stage.5003 → 1.3.45-stage.5018
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
alter type audit.action_actor_type add value if not exists 'api_key';
|
|
7
|
+
`.execute(db);
|
|
8
|
+
|
|
9
|
+
await sql`
|
|
10
|
+
create type audit.source_type as enum (
|
|
11
|
+
'portal', 'api', 'integration', 'sync', 'automation', 'system'
|
|
12
|
+
);
|
|
13
|
+
`.execute(db);
|
|
14
|
+
await sql`
|
|
15
|
+
create type audit.public_event_operation as enum (
|
|
16
|
+
'create', 'update', 'delete', 'archive', 'restore', 'execute',
|
|
17
|
+
'recalculate'
|
|
18
|
+
);
|
|
19
|
+
`.execute(db);
|
|
20
|
+
await sql`
|
|
21
|
+
create type audit.public_event_accounting_status as enum (
|
|
22
|
+
'not_applicable', 'pending', 'unchanged', 'changed', 'blocked',
|
|
23
|
+
'failed', 'mixed'
|
|
24
|
+
);
|
|
25
|
+
`.execute(db);
|
|
26
|
+
|
|
27
|
+
// actor_id stays uuid: every writer supplies a user or token-row UUID, and
|
|
28
|
+
// retyping to text would rewrite the multi-GB action table under lock.
|
|
29
|
+
await sql`
|
|
30
|
+
alter table audit.action
|
|
31
|
+
add column actor_name text,
|
|
32
|
+
add column actor_email text,
|
|
33
|
+
add column actor_label text,
|
|
34
|
+
add column source_type audit.source_type;
|
|
35
|
+
`.execute(db);
|
|
36
|
+
|
|
37
|
+
await sql`
|
|
38
|
+
alter table audit.effect
|
|
39
|
+
add column accounting_relevant boolean not null default false;
|
|
40
|
+
`.execute(db);
|
|
41
|
+
|
|
42
|
+
// capture_order uses a nullable column plus a sequence default instead of
|
|
43
|
+
// an identity column: identity backfills every existing row, which rewrites
|
|
44
|
+
// the 100M+-row mutation table under an access-exclusive lock. Rows written
|
|
45
|
+
// before this migration keep null; only post-cutover mutations are ever
|
|
46
|
+
// projected, and those all receive sequence values.
|
|
47
|
+
await sql`
|
|
48
|
+
alter table audit.mutation
|
|
49
|
+
add column accounting_relevant boolean not null default false,
|
|
50
|
+
add column public_changes jsonb not null default '[]'::jsonb,
|
|
51
|
+
add column capture_order bigint;
|
|
52
|
+
`.execute(db);
|
|
53
|
+
await sql`
|
|
54
|
+
create sequence audit.mutation_capture_order_seq
|
|
55
|
+
owned by audit.mutation.capture_order;
|
|
56
|
+
`.execute(db);
|
|
57
|
+
await sql`
|
|
58
|
+
alter table audit.mutation
|
|
59
|
+
alter column capture_order
|
|
60
|
+
set default nextval('audit.mutation_capture_order_seq');
|
|
61
|
+
`.execute(db);
|
|
62
|
+
|
|
63
|
+
await sql`
|
|
64
|
+
alter table audit.journal_delta
|
|
65
|
+
add column currency_before text,
|
|
66
|
+
add column currency_after text,
|
|
67
|
+
add column ledger_before text,
|
|
68
|
+
add column ledger_after text,
|
|
69
|
+
add column account_name_before text,
|
|
70
|
+
add column account_name_after text,
|
|
71
|
+
add column account_category_id_before uuid,
|
|
72
|
+
add column account_category_id_after uuid,
|
|
73
|
+
add column account_category_name_before text,
|
|
74
|
+
add column account_category_name_after text,
|
|
75
|
+
add column account_classification_before text,
|
|
76
|
+
add column account_classification_after text;
|
|
77
|
+
`.execute(db);
|
|
78
|
+
|
|
79
|
+
await sql`
|
|
80
|
+
create table audit.public_event (
|
|
81
|
+
id uuid primary key default gen_random_uuid(),
|
|
82
|
+
tenant_id uuid not null,
|
|
83
|
+
action_id uuid not null,
|
|
84
|
+
root_entity_type text not null,
|
|
85
|
+
root_entity_id uuid not null,
|
|
86
|
+
revision integer not null default 1 check (revision >= 1),
|
|
87
|
+
occurred_at timestamptz not null,
|
|
88
|
+
updated_at timestamptz not null default now(),
|
|
89
|
+
team_unique_ref text,
|
|
90
|
+
team_name text not null,
|
|
91
|
+
actor_type audit.action_actor_type not null,
|
|
92
|
+
actor_id text,
|
|
93
|
+
actor_name text,
|
|
94
|
+
actor_email text,
|
|
95
|
+
actor_label text,
|
|
96
|
+
source_type audit.source_type not null,
|
|
97
|
+
request_id text,
|
|
98
|
+
action_code text not null,
|
|
99
|
+
action_summary text not null,
|
|
100
|
+
entity_unique_ref text,
|
|
101
|
+
entity_name text,
|
|
102
|
+
operation audit.public_event_operation not null,
|
|
103
|
+
entity_changes jsonb not null default '[]'::jsonb,
|
|
104
|
+
accounting_status audit.public_event_accounting_status not null,
|
|
105
|
+
changed_dimensions text[] not null default '{}',
|
|
106
|
+
affected_account_ids uuid[] not null default '{}',
|
|
107
|
+
affected_accounts jsonb not null default '[]'::jsonb,
|
|
108
|
+
affected_periods text[] not null default '{}',
|
|
109
|
+
affected_ownership_period_ids uuid[] not null default '{}',
|
|
110
|
+
affected_owner_statement_ids uuid[] not null default '{}',
|
|
111
|
+
projection_fingerprint text not null,
|
|
112
|
+
unique (tenant_id, action_id, root_entity_type, root_entity_id)
|
|
113
|
+
);
|
|
114
|
+
`.execute(db);
|
|
115
|
+
|
|
116
|
+
await sql`
|
|
117
|
+
create table audit.public_event_posting_change (
|
|
118
|
+
id uuid primary key default gen_random_uuid(),
|
|
119
|
+
event_id uuid not null references audit.public_event(id) on delete cascade,
|
|
120
|
+
tenant_id uuid not null,
|
|
121
|
+
account_id uuid,
|
|
122
|
+
account_name text,
|
|
123
|
+
account_category_id uuid,
|
|
124
|
+
account_category_name text,
|
|
125
|
+
account_classification text,
|
|
126
|
+
party text,
|
|
127
|
+
currency text,
|
|
128
|
+
posting_date date,
|
|
129
|
+
ledger text,
|
|
130
|
+
status text,
|
|
131
|
+
ownership_period_id uuid,
|
|
132
|
+
owner_statement_id uuid,
|
|
133
|
+
before_cent_total bigint,
|
|
134
|
+
after_cent_total bigint,
|
|
135
|
+
check (
|
|
136
|
+
before_cent_total is not null or after_cent_total is not null
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
`.execute(db);
|
|
140
|
+
|
|
141
|
+
await sql`
|
|
142
|
+
create table audit.public_event_projection_state (
|
|
143
|
+
singleton boolean primary key default true check (singleton),
|
|
144
|
+
cutover_at timestamptz not null default now(),
|
|
145
|
+
last_recovered_at timestamptz,
|
|
146
|
+
retained_from timestamptz
|
|
147
|
+
);
|
|
148
|
+
`.execute(db);
|
|
149
|
+
await sql`
|
|
150
|
+
insert into audit.public_event_projection_state default values;
|
|
151
|
+
`.execute(db);
|
|
152
|
+
|
|
153
|
+
await sql`
|
|
154
|
+
create index public_event_tenant_updated_idx
|
|
155
|
+
on audit.public_event (tenant_id, updated_at, id);
|
|
156
|
+
`.execute(db);
|
|
157
|
+
await sql`
|
|
158
|
+
create index public_event_tenant_entity_updated_idx
|
|
159
|
+
on audit.public_event (
|
|
160
|
+
tenant_id, root_entity_type, root_entity_id, updated_at, id
|
|
161
|
+
);
|
|
162
|
+
`.execute(db);
|
|
163
|
+
await sql`
|
|
164
|
+
create index public_event_updated_idx
|
|
165
|
+
on audit.public_event (updated_at, id);
|
|
166
|
+
`.execute(db);
|
|
167
|
+
await sql`
|
|
168
|
+
create index public_event_actor_idx
|
|
169
|
+
on audit.public_event (tenant_id, actor_type, actor_id, updated_at, id);
|
|
170
|
+
`.execute(db);
|
|
171
|
+
await sql`
|
|
172
|
+
create index public_event_action_idx
|
|
173
|
+
on audit.public_event (tenant_id, action_id);
|
|
174
|
+
`.execute(db);
|
|
175
|
+
await sql`
|
|
176
|
+
create index public_event_affected_accounts_idx
|
|
177
|
+
on audit.public_event using gin (affected_account_ids);
|
|
178
|
+
`.execute(db);
|
|
179
|
+
await sql`
|
|
180
|
+
create index public_event_posting_change_event_idx
|
|
181
|
+
on audit.public_event_posting_change (event_id, tenant_id);
|
|
182
|
+
`.execute(db);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
186
|
+
await sql`
|
|
187
|
+
drop table if exists audit.public_event_projection_state;
|
|
188
|
+
`.execute(db);
|
|
189
|
+
await sql`
|
|
190
|
+
drop table if exists audit.public_event_posting_change;
|
|
191
|
+
`.execute(db);
|
|
192
|
+
await sql`
|
|
193
|
+
drop table if exists audit.public_event;
|
|
194
|
+
`.execute(db);
|
|
195
|
+
|
|
196
|
+
await sql`
|
|
197
|
+
alter table audit.journal_delta
|
|
198
|
+
drop column if exists account_classification_after,
|
|
199
|
+
drop column if exists account_classification_before,
|
|
200
|
+
drop column if exists account_category_name_after,
|
|
201
|
+
drop column if exists account_category_name_before,
|
|
202
|
+
drop column if exists account_category_id_after,
|
|
203
|
+
drop column if exists account_category_id_before,
|
|
204
|
+
drop column if exists account_name_after,
|
|
205
|
+
drop column if exists account_name_before,
|
|
206
|
+
drop column if exists ledger_after,
|
|
207
|
+
drop column if exists ledger_before,
|
|
208
|
+
drop column if exists currency_after,
|
|
209
|
+
drop column if exists currency_before;
|
|
210
|
+
`.execute(db);
|
|
211
|
+
|
|
212
|
+
await sql`
|
|
213
|
+
alter table audit.mutation
|
|
214
|
+
drop column if exists capture_order,
|
|
215
|
+
drop column if exists public_changes,
|
|
216
|
+
drop column if exists accounting_relevant;
|
|
217
|
+
`.execute(db);
|
|
218
|
+
|
|
219
|
+
await sql`
|
|
220
|
+
alter table audit.effect
|
|
221
|
+
drop column if exists accounting_relevant;
|
|
222
|
+
`.execute(db);
|
|
223
|
+
|
|
224
|
+
await sql`
|
|
225
|
+
alter table audit.action
|
|
226
|
+
drop column if exists source_type,
|
|
227
|
+
drop column if exists actor_label,
|
|
228
|
+
drop column if exists actor_email,
|
|
229
|
+
drop column if exists actor_name;
|
|
230
|
+
`.execute(db);
|
|
231
|
+
|
|
232
|
+
await sql`
|
|
233
|
+
drop type if exists audit.public_event_accounting_status;
|
|
234
|
+
`.execute(db);
|
|
235
|
+
await sql`
|
|
236
|
+
drop type if exists audit.public_event_operation;
|
|
237
|
+
`.execute(db);
|
|
238
|
+
await sql`
|
|
239
|
+
drop type if exists audit.source_type;
|
|
240
|
+
`.execute(db);
|
|
241
|
+
}
|
|
@@ -6,10 +6,13 @@ import type { ColumnType } from "kysely";
|
|
|
6
6
|
export type AccountingJournalEntryInactiveReason = "cancelledReservationLine" | "currencyMismatch" | "generalLedgerStartAt" | "inactiveAccount" | "listingInactive" | "nonPostingAccount" | "reservationGeneralLedgerStatusInactive" | "transactionInactive" | "unknownInactiveReason";
|
|
7
7
|
export type AccountingJournalEntryLedger = "historical" | "operating" | "trust";
|
|
8
8
|
export type AccountingTransactionAttachmentStatus = "attached" | "deleting" | "ready" | "uploading";
|
|
9
|
-
export type AuditActionActorType = "automation" | "sync" | "system" | "user";
|
|
9
|
+
export type AuditActionActorType = "api_key" | "automation" | "sync" | "system" | "user";
|
|
10
10
|
export type AuditEffectAttemptStatus = "completed" | "failed" | "running" | "skipped_locked";
|
|
11
11
|
export type AuditEffectStatus = "claimed" | "completed" | "dead_letter" | "failed" | "pending" | "running";
|
|
12
12
|
export type AuditJournalDeltaOperation = "delete" | "insert" | "update";
|
|
13
|
+
export type AuditPublicEventAccountingStatus = "blocked" | "changed" | "failed" | "mixed" | "not_applicable" | "pending" | "unchanged";
|
|
14
|
+
export type AuditPublicEventOperation = "archive" | "create" | "delete" | "execute" | "recalculate" | "restore" | "update";
|
|
15
|
+
export type AuditSourceType = "api" | "automation" | "integration" | "portal" | "sync" | "system";
|
|
13
16
|
export type HealthTenantIssueCategory = "criticalToSystem" | "criticalToUser";
|
|
14
17
|
export type HealthTenantIssueCode = "brokenConnections" | "cancelledReservationPaidWithoutAdjustment" | "closedPeriodUnattachedJournalEntries" | "duplicatedPayments" | "endedOwnershipNonZeroBalance" | "listingOwnershipPeriodNotFoundOnActiveJournals" | "missingOwnershipOrDeactivation" | "operatingBankAccountsWithoutOpex" | "outdatedConnections" | "partnerBillingInactive" | "partnerInactive" | "pmsMissingAccountingStart" | "publishedStatementUnpaid" | "reservationCurrencyMismatch" | "reservationGuestTotalsMismatch" | "reservationPaymentProjectionMismatch" | "teamInactive" | "unbalancedJournalEntries" | "unbalancedTransactionJournalEntries" | "unpaidReservations";
|
|
15
18
|
export type HealthTenantIssueSeverity = "error" | "warning";
|
|
@@ -451,7 +454,10 @@ export interface AccountingTransactionType {
|
|
|
451
454
|
}
|
|
452
455
|
export interface AuditAction {
|
|
453
456
|
actionType: string;
|
|
457
|
+
actorEmail: string | null;
|
|
454
458
|
actorId: string | null;
|
|
459
|
+
actorLabel: string | null;
|
|
460
|
+
actorName: string | null;
|
|
455
461
|
actorType: AuditActionActorType;
|
|
456
462
|
apiVersion: string;
|
|
457
463
|
createdAt: Generated<Timestamp>;
|
|
@@ -463,10 +469,12 @@ export interface AuditAction {
|
|
|
463
469
|
rootEntityId: string | null;
|
|
464
470
|
rootEntityType: string | null;
|
|
465
471
|
source: string | null;
|
|
472
|
+
sourceType: AuditSourceType | null;
|
|
466
473
|
tenantId: string;
|
|
467
474
|
traceId: string | null;
|
|
468
475
|
}
|
|
469
476
|
export interface AuditEffect {
|
|
477
|
+
accountingRelevant: Generated<boolean>;
|
|
470
478
|
actionId: string;
|
|
471
479
|
claimedAt: Timestamp | null;
|
|
472
480
|
claimedBy: string | null;
|
|
@@ -504,8 +512,16 @@ export interface AuditEffectAttempt {
|
|
|
504
512
|
workerId: string | null;
|
|
505
513
|
}
|
|
506
514
|
export interface AuditJournalDelta {
|
|
515
|
+
accountCategoryIdAfter: string | null;
|
|
516
|
+
accountCategoryIdBefore: string | null;
|
|
517
|
+
accountCategoryNameAfter: string | null;
|
|
518
|
+
accountCategoryNameBefore: string | null;
|
|
519
|
+
accountClassificationAfter: string | null;
|
|
520
|
+
accountClassificationBefore: string | null;
|
|
507
521
|
accountIdAfter: string | null;
|
|
508
522
|
accountIdBefore: string | null;
|
|
523
|
+
accountNameAfter: string | null;
|
|
524
|
+
accountNameBefore: string | null;
|
|
509
525
|
actionId: string;
|
|
510
526
|
apiVersion: string;
|
|
511
527
|
attachedToOwnerStatementIdAfter: string | null;
|
|
@@ -514,10 +530,14 @@ export interface AuditJournalDelta {
|
|
|
514
530
|
centTotalBefore: Int8 | null;
|
|
515
531
|
changedAt: Generated<Timestamp>;
|
|
516
532
|
changedFields: Generated<string[]>;
|
|
533
|
+
currencyAfter: string | null;
|
|
534
|
+
currencyBefore: string | null;
|
|
517
535
|
diffJson: Json | null;
|
|
518
536
|
effectId: string | null;
|
|
519
537
|
id: Generated<string>;
|
|
520
538
|
journalEntryId: string;
|
|
539
|
+
ledgerAfter: string | null;
|
|
540
|
+
ledgerBefore: string | null;
|
|
521
541
|
listingOwnershipPeriodIdAfter: string | null;
|
|
522
542
|
listingOwnershipPeriodIdBefore: string | null;
|
|
523
543
|
mutationId: string | null;
|
|
@@ -533,18 +553,79 @@ export interface AuditJournalDelta {
|
|
|
533
553
|
txnAtBefore: Timestamp | null;
|
|
534
554
|
}
|
|
535
555
|
export interface AuditMutation {
|
|
556
|
+
accountingRelevant: Generated<boolean>;
|
|
536
557
|
actionId: string;
|
|
558
|
+
captureOrder: Generated<Int8 | null>;
|
|
537
559
|
changeRecord: Json;
|
|
538
560
|
createdAt: Generated<Timestamp>;
|
|
539
561
|
effectId: string | null;
|
|
540
562
|
id: Generated<string>;
|
|
541
563
|
op: string;
|
|
564
|
+
publicChanges: Generated<Json>;
|
|
542
565
|
rootEntityId: string | null;
|
|
543
566
|
rootEntityType: string | null;
|
|
544
567
|
subjectId: string;
|
|
545
568
|
subjectType: string;
|
|
546
569
|
tenantId: string;
|
|
547
570
|
}
|
|
571
|
+
export interface AuditPublicEvent {
|
|
572
|
+
accountingStatus: AuditPublicEventAccountingStatus;
|
|
573
|
+
actionCode: string;
|
|
574
|
+
actionId: string;
|
|
575
|
+
actionSummary: string;
|
|
576
|
+
actorEmail: string | null;
|
|
577
|
+
actorId: string | null;
|
|
578
|
+
actorLabel: string | null;
|
|
579
|
+
actorName: string | null;
|
|
580
|
+
actorType: AuditActionActorType;
|
|
581
|
+
affectedAccountIds: Generated<string[]>;
|
|
582
|
+
affectedAccounts: Generated<Json>;
|
|
583
|
+
affectedOwnerStatementIds: Generated<string[]>;
|
|
584
|
+
affectedOwnershipPeriodIds: Generated<string[]>;
|
|
585
|
+
affectedPeriods: Generated<string[]>;
|
|
586
|
+
changedDimensions: Generated<string[]>;
|
|
587
|
+
entityChanges: Generated<Json>;
|
|
588
|
+
entityName: string | null;
|
|
589
|
+
entityUniqueRef: string | null;
|
|
590
|
+
id: Generated<string>;
|
|
591
|
+
occurredAt: Timestamp;
|
|
592
|
+
operation: AuditPublicEventOperation;
|
|
593
|
+
projectionFingerprint: string;
|
|
594
|
+
requestId: string | null;
|
|
595
|
+
revision: Generated<number>;
|
|
596
|
+
rootEntityId: string;
|
|
597
|
+
rootEntityType: string;
|
|
598
|
+
sourceType: AuditSourceType;
|
|
599
|
+
teamName: string;
|
|
600
|
+
teamUniqueRef: string | null;
|
|
601
|
+
tenantId: string;
|
|
602
|
+
updatedAt: Generated<Timestamp>;
|
|
603
|
+
}
|
|
604
|
+
export interface AuditPublicEventPostingChange {
|
|
605
|
+
accountCategoryId: string | null;
|
|
606
|
+
accountCategoryName: string | null;
|
|
607
|
+
accountClassification: string | null;
|
|
608
|
+
accountId: string | null;
|
|
609
|
+
accountName: string | null;
|
|
610
|
+
afterCentTotal: Int8 | null;
|
|
611
|
+
beforeCentTotal: Int8 | null;
|
|
612
|
+
currency: string | null;
|
|
613
|
+
eventId: string;
|
|
614
|
+
id: Generated<string>;
|
|
615
|
+
ledger: string | null;
|
|
616
|
+
ownerStatementId: string | null;
|
|
617
|
+
ownershipPeriodId: string | null;
|
|
618
|
+
party: string | null;
|
|
619
|
+
postingDate: Timestamp | null;
|
|
620
|
+
status: string | null;
|
|
621
|
+
tenantId: string;
|
|
622
|
+
}
|
|
623
|
+
export interface AuditPublicEventProjectionState {
|
|
624
|
+
cutoverAt: Generated<Timestamp>;
|
|
625
|
+
lastRecoveredAt: Timestamp | null;
|
|
626
|
+
retainedFrom: Timestamp | null;
|
|
627
|
+
singleton: Generated<boolean>;
|
|
628
|
+
}
|
|
548
629
|
export interface CoreActiveStatus {
|
|
549
630
|
name: string;
|
|
550
631
|
}
|
|
@@ -2066,6 +2147,9 @@ export interface DB {
|
|
|
2066
2147
|
"audit.effectAttempt": AuditEffectAttempt;
|
|
2067
2148
|
"audit.journalDelta": AuditJournalDelta;
|
|
2068
2149
|
"audit.mutation": AuditMutation;
|
|
2150
|
+
"audit.publicEvent": AuditPublicEvent;
|
|
2151
|
+
"audit.publicEventPostingChange": AuditPublicEventPostingChange;
|
|
2152
|
+
"audit.publicEventProjectionState": AuditPublicEventProjectionState;
|
|
2069
2153
|
"core.activeStatus": CoreActiveStatus;
|
|
2070
2154
|
"core.change": CoreChange;
|
|
2071
2155
|
"core.changeEntityType": CoreChangeEntityType;
|