@vrplatform/kysely 1.3.41 → 1.3.45-1
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/build/.data.tar +0 -0
- package/build/main/camel-case/index.js +1 -1
- package/build/main/camel-case/index.js.map +1 -1
- package/build/main/control-plane/index.d.ts +368 -0
- package/build/main/control-plane/index.js +64 -0
- package/build/main/control-plane/index.js.map +1 -0
- package/build/main/domain.d.ts +4 -0
- package/build/main/domain.js +3 -0
- package/build/main/domain.js.map +1 -0
- package/build/main/error.d.ts +2 -1
- package/build/main/error.js +2 -1
- package/build/main/error.js.map +1 -1
- package/build/main/index.d.ts +13 -16
- package/build/main/index.js +145 -65
- package/build/main/index.js.map +1 -1
- package/build/main/isomorphic.d.ts +5 -5
- package/build/main/isomorphic.js +4 -10
- package/build/main/isomorphic.js.map +1 -1
- package/build/main/local/digest.d.ts +3 -3
- package/build/main/local/digest.js.map +1 -1
- package/build/main/local/generate.js +10 -10
- package/build/main/local/generate.js.map +1 -1
- package/build/main/local/index.d.ts +5 -1
- package/build/main/local/index.js +215 -6
- package/build/main/local/index.js.map +1 -1
- package/build/main/local/prune-pulled-schema.js +4 -1
- package/build/main/local/prune-pulled-schema.js.map +1 -1
- package/build/main/migration.d.ts +7 -0
- package/build/main/migration.js +11 -0
- package/build/main/migration.js.map +1 -0
- package/build/main/pganalyze-comment-plugin/comment-transformer.js +0 -1
- package/build/main/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/main/pganalyze-comment-plugin/index.js +16 -3
- package/build/main/pganalyze-comment-plugin/index.js.map +1 -1
- package/build/main/plugins.d.ts +2 -2
- package/build/main/plugins.js.map +1 -1
- package/build/main/postgres-error.d.ts +8 -0
- package/build/main/postgres-error.js +21 -0
- package/build/main/postgres-error.js.map +1 -0
- package/build/main/query/index.d.ts +1 -0
- package/build/main/query/index.js +1 -0
- package/build/main/query/index.js.map +1 -1
- package/build/main/query/listing/status.d.ts +2 -12
- package/build/main/query/listing/status.js +31 -19
- package/build/main/query/listing/status.js.map +1 -1
- package/build/main/query/tenant/billing-partner.d.ts +4 -0
- package/build/main/query/tenant/billing-partner.js +8 -0
- package/build/main/query/tenant/billing-partner.js.map +1 -0
- package/build/main/query/tenant/index.d.ts +2 -0
- package/build/main/query/tenant/index.js +19 -0
- package/build/main/query/tenant/index.js.map +1 -0
- package/build/main/query/tenant/status.d.ts +14 -0
- package/build/main/query/tenant/status.js +40 -0
- package/build/main/query/tenant/status.js.map +1 -0
- package/build/main/regional.d.ts +60 -0
- package/build/main/regional.js +205 -0
- package/build/main/regional.js.map +1 -0
- package/build/main/test/index.d.ts +3 -14
- package/build/main/test/index.js +0 -23
- package/build/main/test/index.js.map +1 -1
- package/build/main/transaction.d.ts +3 -3
- package/build/main/transaction.js.map +1 -1
- package/build/main/v1.generated.d.ts +593 -23
- package/build/main/v1.generated.js.map +1 -1
- package/build/migrations-v2/0000000000000-baseline.ts +5 -0
- package/build/migrations-v2/0000000000001-public-audit-events-v2.ts +137 -0
- package/build/migrations-v2/0000000000002-audit-recovery-watermarks.ts +30 -0
- package/build/migrations-v2/0000000000003-audit-effect-recovery-watermark.ts +13 -0
- package/build/migrations-v2/0000000000004-audit-event-projected-at.ts +15 -0
- package/build/migrations-v2/0000000000005-audit-recovery-indexes.ts +63 -0
- package/build/migrations-v2/0000000000006-audit-action-public-event-projected-at.ts +22 -0
- package/build/migrations-v2/0000000000007-audit-action-public-event-projected-at-backfill.ts +35 -0
- package/build/migrations-v2/0000000000008-global-user-attribution.ts +33 -0
- package/build/migrations-v2/0000000000008-team-issue-rule-state.ts +52 -0
- package/build/migrations-v2/0000000000009-reservation-issue-projections.ts +45 -0
- package/build/migrations-v2/0000000000010-bank-rule-application-bank-record-delete-cascade.ts +26 -0
- package/build/migrations-v2/0000000000011-guest-balance-journal-entry-lookup-index.ts +25 -0
- package/build/migrations-v2/0000000000012-trial-free-analytics-billing-status.ts +72 -0
- package/build/migrations-v2/0000000000013-ui-permission-bundles.ts +45 -0
- package/build/migrations-v2/0000000000014-ui-permission-bundle-top-up.ts +32 -0
- package/build/migrations-v2/0000000000016-managed-team-access.ts +34 -0
- package/build/migrations-v2/0000000000017-drop-trial-until.ts +42 -0
- package/build/migrations-v2/0000000000018-accounting-integrity-monitoring.ts +276 -0
- package/build/migrations-v2/0000000000019-accounting-integrity-run-shards.ts +26 -0
- package/build/migrations-v2/0000000000020-accounting-integrity-case-classification.ts +52 -0
- package/build/migrations-v2/0000000000021-payment-line-classification-monitor-indexes.ts +31 -0
- package/build/migrations-v2/0000000000022-accounting-integrity-controlled-repairs.ts +281 -0
- package/build/migrations-v2/0000000000023-line-classification-usage.ts +325 -0
- package/build/migrations-v2/0000000000024-tenant-region-migration.ts +108 -0
- package/build/migrations-v2/0000000000025-partner-ach-denial-default.ts +30 -0
- package/build/migrations-v2/0000000000026-line-classification-usage-capture.ts +399 -0
- package/build/migrations-v2/0000000000027-payout-replacement-chain.ts +27 -0
- package/build/migrations-v2/0000000000028-accounting-integrity-operator-workflow.ts +108 -0
- package/build/migrations-v2/0000000000029-accounting-integrity-definition-artifacts.ts +40 -0
- package/build/migrations-v2/0000000000030-accounting-integrity-review-metadata-compatibility.ts +49 -0
- package/build/module/camel-case/index.js +1 -1
- package/build/module/camel-case/index.js.map +1 -1
- package/build/module/control-plane/index.d.ts +368 -0
- package/build/module/control-plane/index.js +50 -0
- package/build/module/control-plane/index.js.map +1 -0
- package/build/module/domain.d.ts +4 -0
- package/build/module/domain.js +2 -0
- package/build/module/domain.js.map +1 -0
- package/build/module/error.d.ts +2 -1
- package/build/module/error.js +3 -1
- package/build/module/error.js.map +1 -1
- package/build/module/index.d.ts +13 -16
- package/build/module/index.js +146 -63
- package/build/module/index.js.map +1 -1
- package/build/module/isomorphic.d.ts +5 -5
- package/build/module/isomorphic.js +1 -6
- package/build/module/isomorphic.js.map +1 -1
- package/build/module/local/digest.d.ts +3 -3
- package/build/module/local/digest.js.map +1 -1
- package/build/module/local/generate.js +10 -10
- package/build/module/local/generate.js.map +1 -1
- package/build/module/local/index.d.ts +5 -1
- package/build/module/local/index.js +216 -7
- package/build/module/local/index.js.map +1 -1
- package/build/module/local/prune-pulled-schema.js +4 -1
- package/build/module/local/prune-pulled-schema.js.map +1 -1
- package/build/module/migration.d.ts +7 -0
- package/build/module/migration.js +8 -0
- package/build/module/migration.js.map +1 -0
- package/build/module/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/module/pganalyze-comment-plugin/index.js.map +1 -1
- package/build/module/plugins.d.ts +2 -2
- package/build/module/plugins.js.map +1 -1
- package/build/module/postgres-error.d.ts +8 -0
- package/build/module/postgres-error.js +18 -0
- package/build/module/postgres-error.js.map +1 -0
- package/build/module/query/index.d.ts +1 -0
- package/build/module/query/index.js +1 -0
- package/build/module/query/index.js.map +1 -1
- package/build/module/query/listing/status.d.ts +2 -12
- package/build/module/query/listing/status.js +31 -17
- package/build/module/query/listing/status.js.map +1 -1
- package/build/module/query/tenant/billing-partner.d.ts +4 -0
- package/build/module/query/tenant/billing-partner.js +5 -0
- package/build/module/query/tenant/billing-partner.js.map +1 -0
- package/build/module/query/tenant/index.d.ts +2 -0
- package/build/module/query/tenant/index.js +3 -0
- package/build/module/query/tenant/index.js.map +1 -0
- package/build/module/query/tenant/status.d.ts +14 -0
- package/build/module/query/tenant/status.js +35 -0
- package/build/module/query/tenant/status.js.map +1 -0
- package/build/module/regional.d.ts +60 -0
- package/build/module/regional.js +162 -0
- package/build/module/regional.js.map +1 -0
- package/build/module/test/index.d.ts +3 -14
- package/build/module/test/index.js +1 -23
- package/build/module/test/index.js.map +1 -1
- package/build/module/transaction.d.ts +3 -3
- package/build/module/transaction.js.map +1 -1
- package/build/module/v1.generated.d.ts +593 -23
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +18 -9
- package/build/main/tsconfig.main.tsbuildinfo +0 -1
- package/build/module/tsconfig.esm.tsbuildinfo +0 -1
|
@@ -0,0 +1,399 @@
|
|
|
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`set local lock_timeout = '5s'`.execute(db);
|
|
6
|
+
await sql`
|
|
7
|
+
create table public.line_classification_usage_capture (
|
|
8
|
+
id uuid primary key default gen_random_uuid(),
|
|
9
|
+
tenant_id uuid not null references public.tenant(id) on delete cascade,
|
|
10
|
+
kind text not null,
|
|
11
|
+
name text not null,
|
|
12
|
+
first_seen_at timestamptz,
|
|
13
|
+
last_seen_at timestamptz,
|
|
14
|
+
created_at timestamptz not null default now(),
|
|
15
|
+
constraint line_classification_usage_capture_kind_check
|
|
16
|
+
check (kind in ('paymentLine', 'reservationLine')),
|
|
17
|
+
constraint line_classification_usage_capture_observation_check
|
|
18
|
+
check (
|
|
19
|
+
(first_seen_at is null and last_seen_at is null) or
|
|
20
|
+
(
|
|
21
|
+
first_seen_at is not null and
|
|
22
|
+
last_seen_at is not null and
|
|
23
|
+
first_seen_at <= last_seen_at
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
`.execute(db);
|
|
28
|
+
|
|
29
|
+
await sql`
|
|
30
|
+
create index line_classification_usage_capture_drain_idx
|
|
31
|
+
on public.line_classification_usage_capture (created_at, id)
|
|
32
|
+
`.execute(db);
|
|
33
|
+
await sql`
|
|
34
|
+
create index line_classification_usage_capture_tenant_kind_name_idx
|
|
35
|
+
on public.line_classification_usage_capture (tenant_id, kind, name)
|
|
36
|
+
`.execute(db);
|
|
37
|
+
|
|
38
|
+
await sql`
|
|
39
|
+
create or replace function public.enqueue_line_classification_usage()
|
|
40
|
+
returns trigger
|
|
41
|
+
language plpgsql
|
|
42
|
+
as $$
|
|
43
|
+
begin
|
|
44
|
+
if tg_op = 'INSERT' then
|
|
45
|
+
insert into public.line_classification_usage_capture (
|
|
46
|
+
tenant_id,
|
|
47
|
+
kind,
|
|
48
|
+
name,
|
|
49
|
+
first_seen_at,
|
|
50
|
+
last_seen_at
|
|
51
|
+
)
|
|
52
|
+
select distinct
|
|
53
|
+
line.tenant_id,
|
|
54
|
+
case
|
|
55
|
+
when line.reservation_id is not null and line.payment_id is null
|
|
56
|
+
then 'reservationLine'
|
|
57
|
+
when line.payment_id is not null then 'paymentLine'
|
|
58
|
+
when classification.type in ('paymentLine', 'reservationLine')
|
|
59
|
+
then classification.type
|
|
60
|
+
end,
|
|
61
|
+
coalesce(line.effective_type, line.type),
|
|
62
|
+
statement_timestamp(),
|
|
63
|
+
statement_timestamp()
|
|
64
|
+
from new_payment_lines as line
|
|
65
|
+
left join public.payment_line_classification as classification
|
|
66
|
+
on classification.name = coalesce(line.effective_type, line.type)
|
|
67
|
+
where line.tenant_id is not null
|
|
68
|
+
and coalesce(line.effective_type, line.type) is not null
|
|
69
|
+
and coalesce(line.effective_type, line.type) != ''
|
|
70
|
+
and (
|
|
71
|
+
(line.reservation_id is not null and line.payment_id is null) or
|
|
72
|
+
line.payment_id is not null or
|
|
73
|
+
classification.type in ('paymentLine', 'reservationLine')
|
|
74
|
+
);
|
|
75
|
+
else
|
|
76
|
+
insert into public.line_classification_usage_capture (
|
|
77
|
+
tenant_id,
|
|
78
|
+
kind,
|
|
79
|
+
name,
|
|
80
|
+
first_seen_at,
|
|
81
|
+
last_seen_at
|
|
82
|
+
)
|
|
83
|
+
select distinct
|
|
84
|
+
line.tenant_id,
|
|
85
|
+
case
|
|
86
|
+
when line.reservation_id is not null and line.payment_id is null
|
|
87
|
+
then 'reservationLine'
|
|
88
|
+
when line.payment_id is not null then 'paymentLine'
|
|
89
|
+
when classification.type in ('paymentLine', 'reservationLine')
|
|
90
|
+
then classification.type
|
|
91
|
+
end,
|
|
92
|
+
coalesce(line.effective_type, line.type),
|
|
93
|
+
statement_timestamp(),
|
|
94
|
+
statement_timestamp()
|
|
95
|
+
from new_payment_lines as line
|
|
96
|
+
inner join old_payment_lines as old_line on old_line.id = line.id
|
|
97
|
+
left join public.payment_line_classification as classification
|
|
98
|
+
on classification.name = coalesce(line.effective_type, line.type)
|
|
99
|
+
where row(
|
|
100
|
+
line.tenant_id,
|
|
101
|
+
line.effective_type,
|
|
102
|
+
line.type,
|
|
103
|
+
line.reservation_id,
|
|
104
|
+
line.payment_id
|
|
105
|
+
) is distinct from row(
|
|
106
|
+
old_line.tenant_id,
|
|
107
|
+
old_line.effective_type,
|
|
108
|
+
old_line.type,
|
|
109
|
+
old_line.reservation_id,
|
|
110
|
+
old_line.payment_id
|
|
111
|
+
)
|
|
112
|
+
and line.tenant_id is not null
|
|
113
|
+
and coalesce(line.effective_type, line.type) is not null
|
|
114
|
+
and coalesce(line.effective_type, line.type) != ''
|
|
115
|
+
and (
|
|
116
|
+
(line.reservation_id is not null and line.payment_id is null) or
|
|
117
|
+
line.payment_id is not null or
|
|
118
|
+
classification.type in ('paymentLine', 'reservationLine')
|
|
119
|
+
);
|
|
120
|
+
end if;
|
|
121
|
+
return null;
|
|
122
|
+
end;
|
|
123
|
+
$$;
|
|
124
|
+
`.execute(db);
|
|
125
|
+
|
|
126
|
+
await sql`
|
|
127
|
+
create or replace function
|
|
128
|
+
public.enqueue_transaction_line_classification_usage()
|
|
129
|
+
returns trigger
|
|
130
|
+
language plpgsql
|
|
131
|
+
as $$
|
|
132
|
+
begin
|
|
133
|
+
if tg_op = 'INSERT' then
|
|
134
|
+
insert into public.line_classification_usage_capture (
|
|
135
|
+
tenant_id,
|
|
136
|
+
kind,
|
|
137
|
+
name,
|
|
138
|
+
first_seen_at,
|
|
139
|
+
last_seen_at
|
|
140
|
+
)
|
|
141
|
+
select distinct
|
|
142
|
+
line.tenant_id,
|
|
143
|
+
'paymentLine',
|
|
144
|
+
line.match_line_type_classification,
|
|
145
|
+
statement_timestamp(),
|
|
146
|
+
statement_timestamp()
|
|
147
|
+
from new_transaction_lines as line
|
|
148
|
+
where line.match_line_type_classification is not null
|
|
149
|
+
and line.match_line_type_classification != '';
|
|
150
|
+
else
|
|
151
|
+
insert into public.line_classification_usage_capture (
|
|
152
|
+
tenant_id,
|
|
153
|
+
kind,
|
|
154
|
+
name,
|
|
155
|
+
first_seen_at,
|
|
156
|
+
last_seen_at
|
|
157
|
+
)
|
|
158
|
+
select distinct
|
|
159
|
+
line.tenant_id,
|
|
160
|
+
'paymentLine',
|
|
161
|
+
line.match_line_type_classification,
|
|
162
|
+
statement_timestamp(),
|
|
163
|
+
statement_timestamp()
|
|
164
|
+
from new_transaction_lines as line
|
|
165
|
+
inner join old_transaction_lines as old_line on old_line.id = line.id
|
|
166
|
+
where row(
|
|
167
|
+
line.tenant_id,
|
|
168
|
+
line.match_line_type_classification
|
|
169
|
+
) is distinct from row(
|
|
170
|
+
old_line.tenant_id,
|
|
171
|
+
old_line.match_line_type_classification
|
|
172
|
+
)
|
|
173
|
+
and line.match_line_type_classification is not null
|
|
174
|
+
and line.match_line_type_classification != '';
|
|
175
|
+
end if;
|
|
176
|
+
return null;
|
|
177
|
+
end;
|
|
178
|
+
$$;
|
|
179
|
+
`.execute(db);
|
|
180
|
+
|
|
181
|
+
await sql`
|
|
182
|
+
create or replace function
|
|
183
|
+
public.enqueue_reservation_line_mapping_usage()
|
|
184
|
+
returns trigger
|
|
185
|
+
language plpgsql
|
|
186
|
+
as $$
|
|
187
|
+
begin
|
|
188
|
+
if tg_op = 'INSERT' then
|
|
189
|
+
insert into public.line_classification_usage_capture (
|
|
190
|
+
tenant_id,
|
|
191
|
+
kind,
|
|
192
|
+
name,
|
|
193
|
+
first_seen_at,
|
|
194
|
+
last_seen_at
|
|
195
|
+
)
|
|
196
|
+
select distinct
|
|
197
|
+
mapping.tenant_id,
|
|
198
|
+
'reservationLine',
|
|
199
|
+
mapping.line_type,
|
|
200
|
+
null::timestamptz,
|
|
201
|
+
null::timestamptz
|
|
202
|
+
from new_reservation_line_mappings as mapping
|
|
203
|
+
where mapping.booking_channel is null
|
|
204
|
+
and mapping.line_type is not null
|
|
205
|
+
and mapping.line_type != '';
|
|
206
|
+
elsif tg_op = 'UPDATE' then
|
|
207
|
+
insert into public.line_classification_usage_capture (
|
|
208
|
+
tenant_id,
|
|
209
|
+
kind,
|
|
210
|
+
name,
|
|
211
|
+
first_seen_at,
|
|
212
|
+
last_seen_at
|
|
213
|
+
)
|
|
214
|
+
select distinct
|
|
215
|
+
changed.tenant_id,
|
|
216
|
+
'reservationLine',
|
|
217
|
+
changed.line_type,
|
|
218
|
+
null::timestamptz,
|
|
219
|
+
null::timestamptz
|
|
220
|
+
from (
|
|
221
|
+
select
|
|
222
|
+
mapping.tenant_id,
|
|
223
|
+
mapping.line_type,
|
|
224
|
+
mapping.booking_channel
|
|
225
|
+
from new_reservation_line_mappings as mapping
|
|
226
|
+
inner join old_reservation_line_mappings as old_mapping
|
|
227
|
+
on old_mapping.id = mapping.id
|
|
228
|
+
where row(
|
|
229
|
+
mapping.tenant_id,
|
|
230
|
+
mapping.line_type,
|
|
231
|
+
mapping.booking_channel,
|
|
232
|
+
mapping.account_id
|
|
233
|
+
) is distinct from row(
|
|
234
|
+
old_mapping.tenant_id,
|
|
235
|
+
old_mapping.line_type,
|
|
236
|
+
old_mapping.booking_channel,
|
|
237
|
+
old_mapping.account_id
|
|
238
|
+
)
|
|
239
|
+
union
|
|
240
|
+
select
|
|
241
|
+
old_mapping.tenant_id,
|
|
242
|
+
old_mapping.line_type,
|
|
243
|
+
old_mapping.booking_channel
|
|
244
|
+
from old_reservation_line_mappings as old_mapping
|
|
245
|
+
inner join new_reservation_line_mappings as mapping
|
|
246
|
+
on mapping.id = old_mapping.id
|
|
247
|
+
where row(
|
|
248
|
+
mapping.tenant_id,
|
|
249
|
+
mapping.line_type,
|
|
250
|
+
mapping.booking_channel,
|
|
251
|
+
mapping.account_id
|
|
252
|
+
) is distinct from row(
|
|
253
|
+
old_mapping.tenant_id,
|
|
254
|
+
old_mapping.line_type,
|
|
255
|
+
old_mapping.booking_channel,
|
|
256
|
+
old_mapping.account_id
|
|
257
|
+
)
|
|
258
|
+
) as changed
|
|
259
|
+
where changed.booking_channel is null
|
|
260
|
+
and changed.line_type is not null
|
|
261
|
+
and changed.line_type != '';
|
|
262
|
+
else
|
|
263
|
+
insert into public.line_classification_usage_capture (
|
|
264
|
+
tenant_id,
|
|
265
|
+
kind,
|
|
266
|
+
name,
|
|
267
|
+
first_seen_at,
|
|
268
|
+
last_seen_at
|
|
269
|
+
)
|
|
270
|
+
select distinct
|
|
271
|
+
mapping.tenant_id,
|
|
272
|
+
'reservationLine',
|
|
273
|
+
mapping.line_type,
|
|
274
|
+
null::timestamptz,
|
|
275
|
+
null::timestamptz
|
|
276
|
+
from old_reservation_line_mappings as mapping
|
|
277
|
+
where mapping.booking_channel is null
|
|
278
|
+
and mapping.line_type is not null
|
|
279
|
+
and mapping.line_type != '';
|
|
280
|
+
end if;
|
|
281
|
+
return null;
|
|
282
|
+
end;
|
|
283
|
+
$$;
|
|
284
|
+
`.execute(db);
|
|
285
|
+
|
|
286
|
+
await sql`drop trigger payment_line_classification_usage_insert
|
|
287
|
+
on public.payment_line`.execute(db);
|
|
288
|
+
await sql`drop trigger payment_line_classification_usage_update
|
|
289
|
+
on public.payment_line`.execute(db);
|
|
290
|
+
await sql`drop trigger transaction_line_classification_usage_insert
|
|
291
|
+
on accounting.transaction_line`.execute(db);
|
|
292
|
+
await sql`drop trigger transaction_line_classification_usage_update
|
|
293
|
+
on accounting.transaction_line`.execute(db);
|
|
294
|
+
await sql`
|
|
295
|
+
create trigger payment_line_classification_usage_insert
|
|
296
|
+
after insert on public.payment_line
|
|
297
|
+
referencing new table as new_payment_lines
|
|
298
|
+
for each statement
|
|
299
|
+
execute function public.enqueue_line_classification_usage()
|
|
300
|
+
`.execute(db);
|
|
301
|
+
await sql`
|
|
302
|
+
create trigger payment_line_classification_usage_update
|
|
303
|
+
after update on public.payment_line
|
|
304
|
+
referencing old table as old_payment_lines new table as new_payment_lines
|
|
305
|
+
for each statement
|
|
306
|
+
execute function public.enqueue_line_classification_usage()
|
|
307
|
+
`.execute(db);
|
|
308
|
+
await sql`
|
|
309
|
+
create trigger transaction_line_classification_usage_insert
|
|
310
|
+
after insert on accounting.transaction_line
|
|
311
|
+
referencing new table as new_transaction_lines
|
|
312
|
+
for each statement
|
|
313
|
+
execute function public.enqueue_transaction_line_classification_usage()
|
|
314
|
+
`.execute(db);
|
|
315
|
+
await sql`
|
|
316
|
+
create trigger transaction_line_classification_usage_update
|
|
317
|
+
after update on accounting.transaction_line
|
|
318
|
+
referencing old table as old_transaction_lines
|
|
319
|
+
new table as new_transaction_lines
|
|
320
|
+
for each statement
|
|
321
|
+
execute function public.enqueue_transaction_line_classification_usage()
|
|
322
|
+
`.execute(db);
|
|
323
|
+
await sql`
|
|
324
|
+
create trigger reservation_line_mapping_usage_insert
|
|
325
|
+
after insert on accounting.account_reservation_line_type
|
|
326
|
+
referencing new table as new_reservation_line_mappings
|
|
327
|
+
for each statement
|
|
328
|
+
execute function public.enqueue_reservation_line_mapping_usage()
|
|
329
|
+
`.execute(db);
|
|
330
|
+
await sql`
|
|
331
|
+
create trigger reservation_line_mapping_usage_update
|
|
332
|
+
after update on accounting.account_reservation_line_type
|
|
333
|
+
referencing old table as old_reservation_line_mappings
|
|
334
|
+
new table as new_reservation_line_mappings
|
|
335
|
+
for each statement
|
|
336
|
+
execute function public.enqueue_reservation_line_mapping_usage()
|
|
337
|
+
`.execute(db);
|
|
338
|
+
await sql`
|
|
339
|
+
create trigger reservation_line_mapping_usage_delete
|
|
340
|
+
after delete on accounting.account_reservation_line_type
|
|
341
|
+
referencing old table as old_reservation_line_mappings
|
|
342
|
+
for each statement
|
|
343
|
+
execute function public.enqueue_reservation_line_mapping_usage()
|
|
344
|
+
`.execute(db);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
348
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
349
|
+
await sql`drop trigger reservation_line_mapping_usage_delete
|
|
350
|
+
on accounting.account_reservation_line_type`.execute(db);
|
|
351
|
+
await sql`drop trigger reservation_line_mapping_usage_update
|
|
352
|
+
on accounting.account_reservation_line_type`.execute(db);
|
|
353
|
+
await sql`drop trigger reservation_line_mapping_usage_insert
|
|
354
|
+
on accounting.account_reservation_line_type`.execute(db);
|
|
355
|
+
await sql`drop trigger payment_line_classification_usage_insert
|
|
356
|
+
on public.payment_line`.execute(db);
|
|
357
|
+
await sql`drop trigger payment_line_classification_usage_update
|
|
358
|
+
on public.payment_line`.execute(db);
|
|
359
|
+
await sql`drop trigger transaction_line_classification_usage_insert
|
|
360
|
+
on accounting.transaction_line`.execute(db);
|
|
361
|
+
await sql`drop trigger transaction_line_classification_usage_update
|
|
362
|
+
on accounting.transaction_line`.execute(db);
|
|
363
|
+
await sql`
|
|
364
|
+
create trigger payment_line_classification_usage_insert
|
|
365
|
+
after insert on public.payment_line
|
|
366
|
+
referencing new table as new_payment_lines
|
|
367
|
+
for each statement
|
|
368
|
+
execute function public.capture_line_classification_usage()
|
|
369
|
+
`.execute(db);
|
|
370
|
+
await sql`
|
|
371
|
+
create trigger payment_line_classification_usage_update
|
|
372
|
+
after update on public.payment_line
|
|
373
|
+
referencing new table as new_payment_lines
|
|
374
|
+
for each statement
|
|
375
|
+
execute function public.capture_line_classification_usage()
|
|
376
|
+
`.execute(db);
|
|
377
|
+
await sql`
|
|
378
|
+
create trigger transaction_line_classification_usage_insert
|
|
379
|
+
after insert on accounting.transaction_line
|
|
380
|
+
referencing new table as new_transaction_lines
|
|
381
|
+
for each statement
|
|
382
|
+
execute function public.capture_transaction_line_classification_usage()
|
|
383
|
+
`.execute(db);
|
|
384
|
+
await sql`
|
|
385
|
+
create trigger transaction_line_classification_usage_update
|
|
386
|
+
after update on accounting.transaction_line
|
|
387
|
+
referencing new table as new_transaction_lines
|
|
388
|
+
for each statement
|
|
389
|
+
execute function public.capture_transaction_line_classification_usage()
|
|
390
|
+
`.execute(db);
|
|
391
|
+
await sql`drop function
|
|
392
|
+
public.enqueue_reservation_line_mapping_usage()`.execute(db);
|
|
393
|
+
await sql`drop function
|
|
394
|
+
public.enqueue_transaction_line_classification_usage()`.execute(db);
|
|
395
|
+
await sql`drop function public.enqueue_line_classification_usage()`.execute(
|
|
396
|
+
db
|
|
397
|
+
);
|
|
398
|
+
await sql`drop table public.line_classification_usage_capture`.execute(db);
|
|
399
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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`set local lock_timeout = '5s'`.execute(db);
|
|
6
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
7
|
+
await sql`
|
|
8
|
+
alter table accounting.transaction
|
|
9
|
+
add column recreated_from_transaction_id uuid null
|
|
10
|
+
references accounting.transaction (id) on delete restrict
|
|
11
|
+
`.execute(db);
|
|
12
|
+
await sql`
|
|
13
|
+
create unique index transaction_recreated_from_unique_idx
|
|
14
|
+
on accounting.transaction (tenant_id, recreated_from_transaction_id)
|
|
15
|
+
where recreated_from_transaction_id is not null
|
|
16
|
+
`.execute(db);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
20
|
+
await sql`
|
|
21
|
+
drop index if exists accounting.transaction_recreated_from_unique_idx
|
|
22
|
+
`.execute(db);
|
|
23
|
+
await sql`
|
|
24
|
+
alter table accounting.transaction
|
|
25
|
+
drop column if exists recreated_from_transaction_id
|
|
26
|
+
`.execute(db);
|
|
27
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
5
|
+
await sql`
|
|
6
|
+
alter table health.accounting_integrity_case
|
|
7
|
+
add column assigned_to text,
|
|
8
|
+
add column assigned_at timestamptz,
|
|
9
|
+
add column reviewed_by text,
|
|
10
|
+
add column reviewed_at timestamptz,
|
|
11
|
+
add column review_rationale text,
|
|
12
|
+
add constraint accounting_integrity_case_assignment_check check (
|
|
13
|
+
(assigned_to is null) = (assigned_at is null)
|
|
14
|
+
),
|
|
15
|
+
add constraint accounting_integrity_case_review_metadata_check check (
|
|
16
|
+
(review_status = 'unreviewed' and reviewed_by is null and
|
|
17
|
+
reviewed_at is null and review_rationale is null)
|
|
18
|
+
or
|
|
19
|
+
(review_status <> 'unreviewed' and reviewed_by is not null and
|
|
20
|
+
reviewed_at is not null and nullif(trim(review_rationale), '')
|
|
21
|
+
is not null)
|
|
22
|
+
) not valid
|
|
23
|
+
`.execute(db);
|
|
24
|
+
await sql`
|
|
25
|
+
update health.accounting_integrity_case
|
|
26
|
+
set
|
|
27
|
+
reviewed_by = 'legacy-monitoring',
|
|
28
|
+
reviewed_at = last_changed_at,
|
|
29
|
+
review_rationale = 'Migrated from pre-operator review state.'
|
|
30
|
+
where review_status <> 'unreviewed'
|
|
31
|
+
`.execute(db);
|
|
32
|
+
await sql`
|
|
33
|
+
alter table health.accounting_integrity_case
|
|
34
|
+
validate constraint accounting_integrity_case_review_metadata_check
|
|
35
|
+
`.execute(db);
|
|
36
|
+
await sql`
|
|
37
|
+
create table health.accounting_integrity_operator_event (
|
|
38
|
+
id uuid primary key default gen_random_uuid(),
|
|
39
|
+
case_id uuid
|
|
40
|
+
references health.accounting_integrity_case(id) on delete cascade,
|
|
41
|
+
plan_id uuid
|
|
42
|
+
references health.accounting_integrity_repair_plan(id)
|
|
43
|
+
on delete cascade,
|
|
44
|
+
stage_id uuid
|
|
45
|
+
references health.accounting_integrity_repair_stage(id)
|
|
46
|
+
on delete cascade,
|
|
47
|
+
target_id uuid
|
|
48
|
+
references health.accounting_integrity_repair_target(id)
|
|
49
|
+
on delete cascade,
|
|
50
|
+
case_version bigint,
|
|
51
|
+
type text not null,
|
|
52
|
+
actor_id text not null,
|
|
53
|
+
client text not null,
|
|
54
|
+
request_id text not null,
|
|
55
|
+
idempotency_key text not null unique,
|
|
56
|
+
rationale text,
|
|
57
|
+
payload jsonb not null,
|
|
58
|
+
created_at timestamptz not null default now(),
|
|
59
|
+
constraint accounting_integrity_operator_event_scope_check check (
|
|
60
|
+
case_id is not null or plan_id is not null
|
|
61
|
+
),
|
|
62
|
+
constraint accounting_integrity_operator_event_client_check check (
|
|
63
|
+
client in ('mcp', 'portal', 'cli_break_glass', 'internal_service')
|
|
64
|
+
),
|
|
65
|
+
constraint accounting_integrity_operator_event_type_check check (
|
|
66
|
+
type in (
|
|
67
|
+
'case_claimed',
|
|
68
|
+
'case_released',
|
|
69
|
+
'case_reviewed',
|
|
70
|
+
'repair_plan_created',
|
|
71
|
+
'repair_approval_requested'
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
`.execute(db);
|
|
76
|
+
await sql`
|
|
77
|
+
create index accounting_integrity_operator_event_case_idx
|
|
78
|
+
on health.accounting_integrity_operator_event (
|
|
79
|
+
case_id,
|
|
80
|
+
created_at,
|
|
81
|
+
id
|
|
82
|
+
)
|
|
83
|
+
`.execute(db);
|
|
84
|
+
await sql`
|
|
85
|
+
create index accounting_integrity_operator_event_plan_idx
|
|
86
|
+
on health.accounting_integrity_operator_event (
|
|
87
|
+
plan_id,
|
|
88
|
+
created_at,
|
|
89
|
+
id
|
|
90
|
+
)
|
|
91
|
+
`.execute(db);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
95
|
+
await sql`
|
|
96
|
+
drop table if exists health.accounting_integrity_operator_event
|
|
97
|
+
`.execute(db);
|
|
98
|
+
await sql`
|
|
99
|
+
alter table health.accounting_integrity_case
|
|
100
|
+
drop constraint accounting_integrity_case_review_metadata_check,
|
|
101
|
+
drop constraint accounting_integrity_case_assignment_check,
|
|
102
|
+
drop column review_rationale,
|
|
103
|
+
drop column reviewed_at,
|
|
104
|
+
drop column reviewed_by,
|
|
105
|
+
drop column assigned_at,
|
|
106
|
+
drop column assigned_to
|
|
107
|
+
`.execute(db);
|
|
108
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
5
|
+
await sql`
|
|
6
|
+
alter table health.accounting_integrity_run
|
|
7
|
+
add column definition_version_id uuid,
|
|
8
|
+
add column definition_artifact_hash text,
|
|
9
|
+
add column definition_template_id text,
|
|
10
|
+
add column definition_template_version integer,
|
|
11
|
+
add column operator_definition_version integer,
|
|
12
|
+
add constraint accounting_integrity_run_definition_artifact_check check (
|
|
13
|
+
(
|
|
14
|
+
definition_version_id is null and
|
|
15
|
+
definition_artifact_hash is null and
|
|
16
|
+
definition_template_id is null and
|
|
17
|
+
definition_template_version is null and
|
|
18
|
+
operator_definition_version is null
|
|
19
|
+
) or (
|
|
20
|
+
definition_version_id is not null and
|
|
21
|
+
definition_artifact_hash is not null and
|
|
22
|
+
definition_template_id is not null and
|
|
23
|
+
definition_template_version > 0 and
|
|
24
|
+
operator_definition_version > 0
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
`.execute(db);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
31
|
+
await sql`
|
|
32
|
+
alter table health.accounting_integrity_run
|
|
33
|
+
drop constraint accounting_integrity_run_definition_artifact_check,
|
|
34
|
+
drop column operator_definition_version,
|
|
35
|
+
drop column definition_template_version,
|
|
36
|
+
drop column definition_template_id,
|
|
37
|
+
drop column definition_artifact_hash,
|
|
38
|
+
drop column definition_version_id
|
|
39
|
+
`.execute(db);
|
|
40
|
+
}
|
package/build/migrations-v2/0000000000030-accounting-integrity-review-metadata-compatibility.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
5
|
+
await sql`
|
|
6
|
+
alter table health.accounting_integrity_case
|
|
7
|
+
drop constraint accounting_integrity_case_review_metadata_check,
|
|
8
|
+
add constraint accounting_integrity_case_review_metadata_check check (
|
|
9
|
+
(
|
|
10
|
+
reviewed_by is null and reviewed_at is null and
|
|
11
|
+
review_rationale is null
|
|
12
|
+
) or (
|
|
13
|
+
reviewed_by is not null and reviewed_at is not null and
|
|
14
|
+
nullif(trim(review_rationale), '') is not null
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
`.execute(db);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
21
|
+
await sql`
|
|
22
|
+
update health.accounting_integrity_case
|
|
23
|
+
set reviewed_by = null, reviewed_at = null, review_rationale = null
|
|
24
|
+
where review_status = 'unreviewed'
|
|
25
|
+
`.execute(db);
|
|
26
|
+
await sql`
|
|
27
|
+
update health.accounting_integrity_case
|
|
28
|
+
set
|
|
29
|
+
reviewed_by = coalesce(reviewed_by, 'legacy-monitoring'),
|
|
30
|
+
reviewed_at = coalesce(reviewed_at, last_changed_at),
|
|
31
|
+
review_rationale = coalesce(
|
|
32
|
+
nullif(trim(review_rationale), ''),
|
|
33
|
+
'Migrated from compatibility review state.'
|
|
34
|
+
)
|
|
35
|
+
where review_status <> 'unreviewed'
|
|
36
|
+
`.execute(db);
|
|
37
|
+
await sql`
|
|
38
|
+
alter table health.accounting_integrity_case
|
|
39
|
+
drop constraint accounting_integrity_case_review_metadata_check,
|
|
40
|
+
add constraint accounting_integrity_case_review_metadata_check check (
|
|
41
|
+
(review_status = 'unreviewed' and reviewed_by is null and
|
|
42
|
+
reviewed_at is null and review_rationale is null)
|
|
43
|
+
or
|
|
44
|
+
(review_status <> 'unreviewed' and reviewed_by is not null and
|
|
45
|
+
reviewed_at is not null and nullif(trim(review_rationale), '')
|
|
46
|
+
is not null)
|
|
47
|
+
)
|
|
48
|
+
`.execute(db);
|
|
49
|
+
}
|
|
@@ -34,7 +34,7 @@ export class CustomCasePlugin extends CamelCasePlugin {
|
|
|
34
34
|
}
|
|
35
35
|
if (!alias.name.includes('_'))
|
|
36
36
|
continue;
|
|
37
|
-
throw new KyselyError(
|
|
37
|
+
throw new KyselyError('Alias contains underscore', { name: alias.name });
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
mapRow(row) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["camel-case/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,GAIhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IACnD,kDAAkD;IAClD
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["camel-case/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,GAIhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IACnD,kDAAkD;IAClD;QACE,KAAK,CAAC;YACJ,wBAAwB,EAAE,IAAI;SAC/B,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,IAAI;QAClB,OAAO,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,cAAc,CAAC,IAAI;QACjB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,WAAW,CAAC,IAAqB;QAC/B,IAAI,CAAC,IAAI,EAAE,UAAU;YAAE,OAAO;QAE9B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YACtC,MAAM,SAAS,GAAG,CAAC,CAAC,SAAsB,CAAC;YAC3C,IAAI,CAAC,SAAS,CAAC,KAAK;gBAAE,SAAS;YAC/B,MAAM,KAAK,GAAG,SAAS,CAAC,KAAuB,CAAC;YAEhD,0CAA0C;YAC1C,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBACtC,MAAM,OAAO,GAAG,SAAS,CAAC,IAAe,CAAC;gBAC1C,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;oBACzC,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;wBACjC,MAAM,eAAe,GAAG,CAAoB,CAAC;wBAC7C,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;oBACpC,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAAE,SAAS;YAExC,MAAM,IAAI,WAAW,CAAC,2BAA2B,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAES,MAAM,CAAC,GAAG;QAClB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG;YAAE,OAAO,GAAG,CAAC;QAEhD,MAAM,MAAM,GAAwB,EAAE,CAAC;QACvC,8GAA8G;QAC9G,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpC,iEAAiE;YACjE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7C,CAAC;YACD,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;QACzB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {\n type AliasNode,\n CamelCasePlugin,\n type IdentifierNode,\n type RawNode,\n type SelectQueryNode,\n} from 'kysely';\nimport { KyselyError } from '../error';\n\nexport class CustomCasePlugin extends CamelCasePlugin {\n // _excludedColumns: Record<string, boolean> = {};\n constructor() {\n super({\n maintainNestedObjectKeys: true,\n });\n }\n\n transformResult(args) {\n return super.transformResult(args);\n }\n\n transformQuery(args) {\n this.verifyAlias(args.node);\n return super.transformQuery(args);\n }\n\n verifyAlias(node: SelectQueryNode) {\n if (!node?.selections) return;\n\n for (const x of node.selections ?? []) {\n const selection = x.selection as AliasNode;\n if (!selection.alias) continue;\n const alias = selection.alias as IdentifierNode;\n\n // alias can be a raw node (jsonArrayFrom)\n if (selection.node.kind === 'RawNode') {\n const rawNode = selection.node as RawNode;\n for (const x of rawNode.parameters ?? []) {\n if (x.kind === 'SelectQueryNode') {\n const selectQueryNode = x as SelectQueryNode;\n this.verifyAlias(selectQueryNode);\n }\n }\n }\n\n if (!alias.name.includes('_')) continue;\n\n throw new KyselyError('Alias contains underscore', { name: alias.name });\n }\n }\n\n protected mapRow(row) {\n if (typeof row !== 'object' || !row) return row;\n\n const newRow: Record<string, any> = {};\n // we camel case on first layer, and nested ONLY if in an array (jsonArrayFrom), NOT if it's an object (jsonb)\n for (const key of Object.keys(row)) {\n let value = row[key];\n const newKey = super.camelCase(key);\n // array CAN be non object, so we need to check the first element\n if (Array.isArray(value)) {\n value = value.map((it) => this.mapRow(it));\n }\n newRow[newKey] = value;\n }\n return newRow;\n }\n}\n"]}
|