@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,325 @@
|
|
|
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
|
+
create table public.line_classification_usage (
|
|
7
|
+
tenant_id uuid not null references public.tenant(id) on delete cascade,
|
|
8
|
+
kind text not null,
|
|
9
|
+
name text not null,
|
|
10
|
+
app_id text,
|
|
11
|
+
mapping_status text,
|
|
12
|
+
first_seen_at timestamptz not null default now(),
|
|
13
|
+
last_seen_at timestamptz not null default now(),
|
|
14
|
+
revision integer not null default 1,
|
|
15
|
+
reported_revision integer not null default 0,
|
|
16
|
+
report_attempts integer not null default 0,
|
|
17
|
+
last_error text,
|
|
18
|
+
created_at timestamptz not null default now(),
|
|
19
|
+
updated_at timestamptz not null default now(),
|
|
20
|
+
primary key (tenant_id, kind, name),
|
|
21
|
+
constraint line_classification_usage_kind_check
|
|
22
|
+
check (kind in ('paymentLine', 'reservationLine')),
|
|
23
|
+
constraint line_classification_usage_mapping_status_check
|
|
24
|
+
check (
|
|
25
|
+
mapping_status is null or
|
|
26
|
+
mapping_status in ('excluded', 'mapped', 'unmapped')
|
|
27
|
+
),
|
|
28
|
+
constraint line_classification_usage_revision_check check (revision > 0),
|
|
29
|
+
constraint line_classification_usage_reported_revision_check
|
|
30
|
+
check (reported_revision >= 0 and reported_revision <= revision),
|
|
31
|
+
constraint line_classification_usage_report_attempts_check
|
|
32
|
+
check (report_attempts >= 0)
|
|
33
|
+
);
|
|
34
|
+
`.execute(db);
|
|
35
|
+
|
|
36
|
+
await sql`
|
|
37
|
+
create index line_classification_usage_pending_idx
|
|
38
|
+
on public.line_classification_usage (updated_at, tenant_id, kind, name)
|
|
39
|
+
where reported_revision < revision;
|
|
40
|
+
`.execute(db);
|
|
41
|
+
|
|
42
|
+
await sql`
|
|
43
|
+
create table public.line_classification_usage_backfill (
|
|
44
|
+
source text primary key,
|
|
45
|
+
cursor_id uuid,
|
|
46
|
+
completed_at timestamptz,
|
|
47
|
+
updated_at timestamptz not null default now(),
|
|
48
|
+
constraint line_classification_usage_backfill_source_check
|
|
49
|
+
check (source in ('paymentLine', 'transactionLine'))
|
|
50
|
+
);
|
|
51
|
+
`.execute(db);
|
|
52
|
+
|
|
53
|
+
await sql`
|
|
54
|
+
insert into public.line_classification_usage_backfill (source)
|
|
55
|
+
values ('paymentLine'), ('transactionLine');
|
|
56
|
+
`.execute(db);
|
|
57
|
+
|
|
58
|
+
await sql`
|
|
59
|
+
create or replace function public.capture_line_classification_usage()
|
|
60
|
+
returns trigger
|
|
61
|
+
language plpgsql
|
|
62
|
+
as $$
|
|
63
|
+
begin
|
|
64
|
+
insert into public.line_classification_usage (
|
|
65
|
+
tenant_id,
|
|
66
|
+
kind,
|
|
67
|
+
name,
|
|
68
|
+
app_id,
|
|
69
|
+
mapping_status,
|
|
70
|
+
first_seen_at,
|
|
71
|
+
last_seen_at
|
|
72
|
+
)
|
|
73
|
+
select distinct
|
|
74
|
+
line.tenant_id,
|
|
75
|
+
case
|
|
76
|
+
when line.reservation_id is not null and line.payment_id is null
|
|
77
|
+
then 'reservationLine'
|
|
78
|
+
when line.payment_id is not null then 'paymentLine'
|
|
79
|
+
when classification.type in ('paymentLine', 'reservationLine')
|
|
80
|
+
then classification.type
|
|
81
|
+
end,
|
|
82
|
+
coalesce(line.effective_type, line.type),
|
|
83
|
+
coalesce(
|
|
84
|
+
classification.app_id,
|
|
85
|
+
app.id
|
|
86
|
+
),
|
|
87
|
+
case
|
|
88
|
+
when (
|
|
89
|
+
line.reservation_id is not null and line.payment_id is null
|
|
90
|
+
) or classification.type = 'reservationLine' then
|
|
91
|
+
case
|
|
92
|
+
when mapping.id is null then 'unmapped'
|
|
93
|
+
when mapping.account_id is null then 'excluded'
|
|
94
|
+
else 'mapped'
|
|
95
|
+
end
|
|
96
|
+
else null
|
|
97
|
+
end,
|
|
98
|
+
now(),
|
|
99
|
+
now()
|
|
100
|
+
from new_payment_lines as line
|
|
101
|
+
left join public.payment_line_classification as classification
|
|
102
|
+
on classification.name = coalesce(line.effective_type, line.type)
|
|
103
|
+
left join public.app as app
|
|
104
|
+
on lower(app.id) = lower(
|
|
105
|
+
split_part(coalesce(line.effective_type, line.type), '_', 1)
|
|
106
|
+
)
|
|
107
|
+
and app.category = 'propertyManagementSystem'
|
|
108
|
+
left join accounting.account_reservation_line_type as mapping
|
|
109
|
+
on mapping.tenant_id = line.tenant_id
|
|
110
|
+
and mapping.line_type = coalesce(line.effective_type, line.type)
|
|
111
|
+
and mapping.booking_channel is null
|
|
112
|
+
where 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
|
+
on conflict (tenant_id, kind, name) do update
|
|
121
|
+
set
|
|
122
|
+
app_id = coalesce(
|
|
123
|
+
excluded.app_id,
|
|
124
|
+
public.line_classification_usage.app_id
|
|
125
|
+
),
|
|
126
|
+
mapping_status = excluded.mapping_status,
|
|
127
|
+
last_seen_at = case
|
|
128
|
+
when public.line_classification_usage.app_id is distinct from
|
|
129
|
+
coalesce(
|
|
130
|
+
excluded.app_id,
|
|
131
|
+
public.line_classification_usage.app_id
|
|
132
|
+
) or
|
|
133
|
+
public.line_classification_usage.mapping_status is distinct from
|
|
134
|
+
excluded.mapping_status or
|
|
135
|
+
public.line_classification_usage.last_seen_at <
|
|
136
|
+
excluded.last_seen_at - interval '1 hour'
|
|
137
|
+
then greatest(
|
|
138
|
+
public.line_classification_usage.last_seen_at,
|
|
139
|
+
excluded.last_seen_at
|
|
140
|
+
)
|
|
141
|
+
else public.line_classification_usage.last_seen_at
|
|
142
|
+
end,
|
|
143
|
+
revision = case
|
|
144
|
+
when public.line_classification_usage.app_id is distinct from
|
|
145
|
+
coalesce(
|
|
146
|
+
excluded.app_id,
|
|
147
|
+
public.line_classification_usage.app_id
|
|
148
|
+
) or
|
|
149
|
+
public.line_classification_usage.mapping_status is distinct from
|
|
150
|
+
excluded.mapping_status or
|
|
151
|
+
public.line_classification_usage.last_seen_at <
|
|
152
|
+
excluded.last_seen_at - interval '1 hour'
|
|
153
|
+
then public.line_classification_usage.revision + 1
|
|
154
|
+
else public.line_classification_usage.revision
|
|
155
|
+
end,
|
|
156
|
+
updated_at = case
|
|
157
|
+
when public.line_classification_usage.app_id is distinct from
|
|
158
|
+
coalesce(
|
|
159
|
+
excluded.app_id,
|
|
160
|
+
public.line_classification_usage.app_id
|
|
161
|
+
) or
|
|
162
|
+
public.line_classification_usage.mapping_status is distinct from
|
|
163
|
+
excluded.mapping_status or
|
|
164
|
+
public.line_classification_usage.last_seen_at <
|
|
165
|
+
excluded.last_seen_at - interval '1 hour'
|
|
166
|
+
then now()
|
|
167
|
+
else public.line_classification_usage.updated_at
|
|
168
|
+
end;
|
|
169
|
+
return null;
|
|
170
|
+
end;
|
|
171
|
+
$$;
|
|
172
|
+
`.execute(db);
|
|
173
|
+
|
|
174
|
+
await sql`
|
|
175
|
+
create trigger payment_line_classification_usage_insert
|
|
176
|
+
after insert on public.payment_line
|
|
177
|
+
referencing new table as new_payment_lines
|
|
178
|
+
for each statement
|
|
179
|
+
execute function public.capture_line_classification_usage();
|
|
180
|
+
`.execute(db);
|
|
181
|
+
|
|
182
|
+
await sql`
|
|
183
|
+
create trigger payment_line_classification_usage_update
|
|
184
|
+
after update on public.payment_line
|
|
185
|
+
referencing new table as new_payment_lines
|
|
186
|
+
for each statement
|
|
187
|
+
execute function public.capture_line_classification_usage();
|
|
188
|
+
`.execute(db);
|
|
189
|
+
|
|
190
|
+
await sql`
|
|
191
|
+
create or replace function public.capture_transaction_line_classification_usage()
|
|
192
|
+
returns trigger
|
|
193
|
+
language plpgsql
|
|
194
|
+
as $$
|
|
195
|
+
begin
|
|
196
|
+
insert into public.line_classification_usage (
|
|
197
|
+
tenant_id,
|
|
198
|
+
kind,
|
|
199
|
+
name,
|
|
200
|
+
app_id,
|
|
201
|
+
mapping_status,
|
|
202
|
+
first_seen_at,
|
|
203
|
+
last_seen_at
|
|
204
|
+
)
|
|
205
|
+
select
|
|
206
|
+
line.tenant_id,
|
|
207
|
+
'paymentLine',
|
|
208
|
+
line.match_line_type_classification,
|
|
209
|
+
coalesce(classification.app_id, app.id),
|
|
210
|
+
null,
|
|
211
|
+
min(line.created_at),
|
|
212
|
+
max(line.updated_at)
|
|
213
|
+
from new_transaction_lines as line
|
|
214
|
+
left join public.payment_line_classification as classification
|
|
215
|
+
on classification.name = line.match_line_type_classification
|
|
216
|
+
left join public.app as app
|
|
217
|
+
on lower(app.id) = lower(
|
|
218
|
+
split_part(line.match_line_type_classification, '_', 1)
|
|
219
|
+
)
|
|
220
|
+
and app.category = 'propertyManagementSystem'
|
|
221
|
+
where line.match_line_type_classification is not null
|
|
222
|
+
and line.match_line_type_classification != ''
|
|
223
|
+
group by
|
|
224
|
+
line.tenant_id,
|
|
225
|
+
line.match_line_type_classification,
|
|
226
|
+
coalesce(classification.app_id, app.id)
|
|
227
|
+
on conflict (tenant_id, kind, name) do update
|
|
228
|
+
set
|
|
229
|
+
app_id = coalesce(
|
|
230
|
+
excluded.app_id,
|
|
231
|
+
public.line_classification_usage.app_id
|
|
232
|
+
),
|
|
233
|
+
first_seen_at = least(
|
|
234
|
+
public.line_classification_usage.first_seen_at,
|
|
235
|
+
excluded.first_seen_at
|
|
236
|
+
),
|
|
237
|
+
last_seen_at = case
|
|
238
|
+
when public.line_classification_usage.app_id is distinct from
|
|
239
|
+
coalesce(
|
|
240
|
+
excluded.app_id,
|
|
241
|
+
public.line_classification_usage.app_id
|
|
242
|
+
) or
|
|
243
|
+
public.line_classification_usage.last_seen_at <
|
|
244
|
+
excluded.last_seen_at - interval '1 hour'
|
|
245
|
+
then greatest(
|
|
246
|
+
public.line_classification_usage.last_seen_at,
|
|
247
|
+
excluded.last_seen_at
|
|
248
|
+
)
|
|
249
|
+
else public.line_classification_usage.last_seen_at
|
|
250
|
+
end,
|
|
251
|
+
revision = case
|
|
252
|
+
when public.line_classification_usage.app_id is distinct from
|
|
253
|
+
coalesce(
|
|
254
|
+
excluded.app_id,
|
|
255
|
+
public.line_classification_usage.app_id
|
|
256
|
+
) or
|
|
257
|
+
public.line_classification_usage.last_seen_at <
|
|
258
|
+
excluded.last_seen_at - interval '1 hour'
|
|
259
|
+
then public.line_classification_usage.revision + 1
|
|
260
|
+
else public.line_classification_usage.revision
|
|
261
|
+
end,
|
|
262
|
+
updated_at = case
|
|
263
|
+
when public.line_classification_usage.app_id is distinct from
|
|
264
|
+
coalesce(
|
|
265
|
+
excluded.app_id,
|
|
266
|
+
public.line_classification_usage.app_id
|
|
267
|
+
) or
|
|
268
|
+
public.line_classification_usage.last_seen_at <
|
|
269
|
+
excluded.last_seen_at - interval '1 hour'
|
|
270
|
+
then now()
|
|
271
|
+
else public.line_classification_usage.updated_at
|
|
272
|
+
end;
|
|
273
|
+
return null;
|
|
274
|
+
end;
|
|
275
|
+
$$;
|
|
276
|
+
`.execute(db);
|
|
277
|
+
|
|
278
|
+
await sql`
|
|
279
|
+
create trigger transaction_line_classification_usage_insert
|
|
280
|
+
after insert on accounting.transaction_line
|
|
281
|
+
referencing new table as new_transaction_lines
|
|
282
|
+
for each statement
|
|
283
|
+
execute function public.capture_transaction_line_classification_usage();
|
|
284
|
+
`.execute(db);
|
|
285
|
+
|
|
286
|
+
await sql`
|
|
287
|
+
create trigger transaction_line_classification_usage_update
|
|
288
|
+
after update on accounting.transaction_line
|
|
289
|
+
referencing new table as new_transaction_lines
|
|
290
|
+
for each statement
|
|
291
|
+
execute function public.capture_transaction_line_classification_usage();
|
|
292
|
+
`.execute(db);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
296
|
+
await sql`
|
|
297
|
+
drop trigger if exists transaction_line_classification_usage_update
|
|
298
|
+
on accounting.transaction_line;
|
|
299
|
+
`.execute(db);
|
|
300
|
+
await sql`
|
|
301
|
+
drop trigger if exists transaction_line_classification_usage_insert
|
|
302
|
+
on accounting.transaction_line;
|
|
303
|
+
`.execute(db);
|
|
304
|
+
await sql`
|
|
305
|
+
drop function if exists
|
|
306
|
+
public.capture_transaction_line_classification_usage();
|
|
307
|
+
`.execute(db);
|
|
308
|
+
await sql`
|
|
309
|
+
drop trigger if exists payment_line_classification_usage_update
|
|
310
|
+
on public.payment_line;
|
|
311
|
+
`.execute(db);
|
|
312
|
+
await sql`
|
|
313
|
+
drop trigger if exists payment_line_classification_usage_insert
|
|
314
|
+
on public.payment_line;
|
|
315
|
+
`.execute(db);
|
|
316
|
+
await sql`
|
|
317
|
+
drop function if exists public.capture_line_classification_usage();
|
|
318
|
+
`.execute(db);
|
|
319
|
+
await sql`
|
|
320
|
+
drop table if exists public.line_classification_usage_backfill;
|
|
321
|
+
`.execute(db);
|
|
322
|
+
await sql`
|
|
323
|
+
drop table if exists public.line_classification_usage;
|
|
324
|
+
`.execute(db);
|
|
325
|
+
}
|
|
@@ -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
|
+
}
|