@vrplatform/kysely 1.3.45-6090 → 1.3.45-61
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/control-plane/index.d.ts +175 -0
- package/build/main/control-plane/index.js.map +1 -1
- package/build/main/index.d.ts +2 -2
- package/build/main/index.js +111 -22
- package/build/main/index.js.map +1 -1
- package/build/main/local/generate.js +2 -0
- package/build/main/local/generate.js.map +1 -1
- package/build/main/local/index.js +12 -0
- package/build/main/local/index.js.map +1 -1
- package/build/main/query/listing/status.js +2 -6
- package/build/main/query/listing/status.js.map +1 -1
- package/build/main/query/tenant/status.js +2 -2
- package/build/main/query/tenant/status.js.map +1 -1
- package/build/main/test/index.d.ts +0 -3
- package/build/main/test/index.js +0 -9
- package/build/main/test/index.js.map +1 -1
- package/build/main/v1.generated.d.ts +253 -2
- package/build/main/v1.generated.js.map +1 -1
- package/build/migrations-v2/0000000000015-durable-flow-events.ts +163 -0
- package/build/migrations-v2/0000000000016-billing-listing-facts.ts +539 -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/0000000000017-webhook-secret-reencryption-failures.ts +18 -0
- package/build/migrations-v2/0000000000018-accounting-integrity-monitoring.ts +276 -0
- package/build/migrations-v2/0000000000018-durable-flow-event-sensitive-input.ts +28 -0
- package/build/migrations-v2/0000000000019-accounting-integrity-run-shards.ts +26 -0
- package/build/migrations-v2/0000000000019-asynchronous-operations.ts +736 -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/migrations-v2/0000000000031-ui-permission-role-simplification.ts +70 -0
- package/build/migrations-v2/0000000000032-tenant-delete-ownership-cascades.ts +44 -0
- package/build/module/control-plane/index.d.ts +175 -0
- package/build/module/control-plane/index.js.map +1 -1
- package/build/module/index.d.ts +2 -2
- package/build/module/index.js +113 -23
- package/build/module/index.js.map +1 -1
- package/build/module/local/generate.js +2 -0
- package/build/module/local/generate.js.map +1 -1
- package/build/module/local/index.js +12 -0
- package/build/module/local/index.js.map +1 -1
- package/build/module/query/listing/status.js +2 -6
- package/build/module/query/listing/status.js.map +1 -1
- package/build/module/query/tenant/status.js +2 -2
- package/build/module/query/tenant/status.js.map +1 -1
- package/build/module/test/index.d.ts +0 -3
- package/build/module/test/index.js +0 -9
- package/build/module/test/index.js.map +1 -1
- package/build/module/v1.generated.d.ts +253 -2
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<Record<string, never>>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
alter table public.tenant
|
|
7
|
+
add column migration_status text not null default 'active',
|
|
8
|
+
add column migrated_to_region text null,
|
|
9
|
+
add column migrated_at timestamp with time zone null,
|
|
10
|
+
add constraint tenant_migration_status_check
|
|
11
|
+
check (migration_status in ('active', 'frozen', 'migrated')),
|
|
12
|
+
add constraint tenant_migrated_target_check
|
|
13
|
+
check (
|
|
14
|
+
(migration_status = 'migrated' and migrated_to_region is not null and migrated_at is not null)
|
|
15
|
+
or
|
|
16
|
+
(migration_status <> 'migrated' and migrated_to_region is null and migrated_at is null)
|
|
17
|
+
),
|
|
18
|
+
add constraint tenant_migrated_to_region_check
|
|
19
|
+
check (
|
|
20
|
+
migrated_to_region is null
|
|
21
|
+
or migrated_to_region in ('ap', 'crunchy', 'eu', 'hostaway', 'us')
|
|
22
|
+
);
|
|
23
|
+
`.execute(db);
|
|
24
|
+
|
|
25
|
+
await sql`
|
|
26
|
+
do $$
|
|
27
|
+
declare
|
|
28
|
+
constraint_row record;
|
|
29
|
+
begin
|
|
30
|
+
for constraint_row in
|
|
31
|
+
select
|
|
32
|
+
namespace.nspname as schema_name,
|
|
33
|
+
class.relname as table_name,
|
|
34
|
+
constraint_record.conname as constraint_name
|
|
35
|
+
from pg_constraint constraint_record
|
|
36
|
+
inner join pg_class class on class.oid = constraint_record.conrelid
|
|
37
|
+
inner join pg_namespace namespace on namespace.oid = class.relnamespace
|
|
38
|
+
where constraint_record.contype = 'f'
|
|
39
|
+
and not constraint_record.condeferrable
|
|
40
|
+
and namespace.nspname in (
|
|
41
|
+
'accounting',
|
|
42
|
+
'audit',
|
|
43
|
+
'core',
|
|
44
|
+
'health',
|
|
45
|
+
'public',
|
|
46
|
+
'tracking',
|
|
47
|
+
'webhook'
|
|
48
|
+
)
|
|
49
|
+
loop
|
|
50
|
+
execute format(
|
|
51
|
+
'alter table %I.%I alter constraint %I deferrable initially immediate',
|
|
52
|
+
constraint_row.schema_name,
|
|
53
|
+
constraint_row.table_name,
|
|
54
|
+
constraint_row.constraint_name
|
|
55
|
+
);
|
|
56
|
+
end loop;
|
|
57
|
+
end
|
|
58
|
+
$$;
|
|
59
|
+
`.execute(db);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function down(db: Kysely<Record<string, never>>): Promise<void> {
|
|
63
|
+
await sql`
|
|
64
|
+
do $$
|
|
65
|
+
declare
|
|
66
|
+
constraint_row record;
|
|
67
|
+
begin
|
|
68
|
+
for constraint_row in
|
|
69
|
+
select
|
|
70
|
+
namespace.nspname as schema_name,
|
|
71
|
+
class.relname as table_name,
|
|
72
|
+
constraint_record.conname as constraint_name
|
|
73
|
+
from pg_constraint constraint_record
|
|
74
|
+
inner join pg_class class on class.oid = constraint_record.conrelid
|
|
75
|
+
inner join pg_namespace namespace on namespace.oid = class.relnamespace
|
|
76
|
+
where constraint_record.contype = 'f'
|
|
77
|
+
and constraint_record.condeferrable
|
|
78
|
+
and namespace.nspname in (
|
|
79
|
+
'accounting',
|
|
80
|
+
'audit',
|
|
81
|
+
'core',
|
|
82
|
+
'health',
|
|
83
|
+
'public',
|
|
84
|
+
'tracking',
|
|
85
|
+
'webhook'
|
|
86
|
+
)
|
|
87
|
+
loop
|
|
88
|
+
execute format(
|
|
89
|
+
'alter table %I.%I alter constraint %I not deferrable',
|
|
90
|
+
constraint_row.schema_name,
|
|
91
|
+
constraint_row.table_name,
|
|
92
|
+
constraint_row.constraint_name
|
|
93
|
+
);
|
|
94
|
+
end loop;
|
|
95
|
+
end
|
|
96
|
+
$$;
|
|
97
|
+
`.execute(db);
|
|
98
|
+
|
|
99
|
+
await sql`
|
|
100
|
+
alter table public.tenant
|
|
101
|
+
drop constraint tenant_migrated_to_region_check,
|
|
102
|
+
drop constraint tenant_migrated_target_check,
|
|
103
|
+
drop constraint tenant_migration_status_check,
|
|
104
|
+
drop column migrated_at,
|
|
105
|
+
drop column migrated_to_region,
|
|
106
|
+
drop column migration_status;
|
|
107
|
+
`.execute(db);
|
|
108
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
alter table public.tenant
|
|
8
|
+
alter column partner_denied_permissions
|
|
9
|
+
set default array['ach-payments:execute']::text[]
|
|
10
|
+
`.execute(db);
|
|
11
|
+
await sql`alter table public.tenant disable trigger user`.execute(db);
|
|
12
|
+
await sql`
|
|
13
|
+
update public.tenant
|
|
14
|
+
set partner_denied_permissions = array_append(
|
|
15
|
+
partner_denied_permissions,
|
|
16
|
+
'ach-payments:execute'
|
|
17
|
+
)
|
|
18
|
+
where not ('ach-payments:execute' = any(partner_denied_permissions))
|
|
19
|
+
`.execute(db);
|
|
20
|
+
await sql`alter table public.tenant enable trigger user`.execute(db);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
24
|
+
// Preserve stored denials because migrated defaults and explicit choices
|
|
25
|
+
// are indistinguishable after the up migration.
|
|
26
|
+
await sql`
|
|
27
|
+
alter table public.tenant
|
|
28
|
+
alter column partner_denied_permissions set default '{}'
|
|
29
|
+
`.execute(db);
|
|
30
|
+
}
|
|
@@ -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
|
+
}
|