@vrplatform/kysely 1.3.45-422 → 1.3.45-42593357829
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 +2 -2
- package/build/main/camel-case/index.d.ts +4 -4
- package/build/main/camel-case/index.js +2 -1
- package/build/main/camel-case/index.js.map +1 -1
- package/build/main/connect-handoff.d.ts +12 -0
- package/build/main/connect-handoff.js +73 -0
- package/build/main/connect-handoff.js.map +1 -0
- package/build/main/control-plane/index.d.ts +22 -1
- package/build/main/control-plane/index.js +10 -0
- package/build/main/control-plane/index.js.map +1 -1
- package/build/main/index.d.ts +46 -2
- package/build/main/index.js +384 -59
- package/build/main/index.js.map +1 -1
- package/build/main/isomorphic.d.ts +1 -1
- package/build/main/isomorphic.js +3 -1
- package/build/main/isomorphic.js.map +1 -1
- package/build/main/local/generate.js +4 -3
- package/build/main/local/generate.js.map +1 -1
- package/build/main/local/index.js +34 -10
- package/build/main/local/index.js.map +1 -1
- package/build/main/migration-source.d.ts +4 -0
- package/build/main/migration-source.js +45 -0
- package/build/main/migration-source.js.map +1 -0
- package/build/main/pganalyze-comment-plugin/comment-transformer.js +3 -1
- package/build/main/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/main/postgres-error.d.ts +1 -0
- package/build/main/postgres-error.js +12 -6
- package/build/main/postgres-error.js.map +1 -1
- package/build/main/query/listing/status.js +6 -2
- package/build/main/query/listing/status.js.map +1 -1
- package/build/main/query/tenant/feature-enabled.d.ts +6 -0
- package/build/main/query/tenant/feature-enabled.js +30 -0
- package/build/main/query/tenant/feature-enabled.js.map +1 -0
- package/build/main/query/tenant/index.d.ts +2 -0
- package/build/main/query/tenant/index.js +2 -0
- package/build/main/query/tenant/index.js.map +1 -1
- package/build/main/query/tenant/status.d.ts +1 -6
- package/build/main/query/tenant/status.js +4 -12
- package/build/main/query/tenant/status.js.map +1 -1
- package/build/main/query/tenant/where-uuid-in.d.ts +2 -0
- package/build/main/query/tenant/where-uuid-in.js +14 -0
- package/build/main/query/tenant/where-uuid-in.js.map +1 -0
- package/build/main/regional.d.ts +1 -0
- package/build/main/regional.js +1 -0
- package/build/main/regional.js.map +1 -1
- package/build/main/test/index.d.ts +7 -9
- package/build/main/test/index.js +11 -14
- package/build/main/test/index.js.map +1 -1
- package/build/main/v1.generated.d.ts +373 -73
- package/build/main/v1.generated.js.map +1 -1
- package/build/migrations-v2/0000000000033-plaid-connect-session-telemetry.ts +31 -0
- package/build/migrations-v2/0000000000050-connection-oauth-state.ts +43 -0
- package/build/migrations-v2/0000000000051-owner-statement-email-delivery.ts +134 -0
- package/build/migrations-v2/0000000000052-fee-journal-lock-skip-operations.ts +59 -0
- package/build/migrations-v2/0000000000053-fee-journal-lock-skip-null-attempt.ts +44 -0
- package/build/migrations-v2/0000000000054-journal-refresh-issue-codes.ts +16 -0
- package/build/migrations-v2/0000000000055-tenant-billing-subscription.ts +8 -0
- package/build/migrations-v2/0000000000056-journal-operation-failure-precedence.ts +306 -0
- package/build/migrations-v2/0000000000057-journal-invalidation-failure-code.ts +28 -0
- package/build/migrations-v2/0000000000058-journal-invalidation-locked-failure.ts +16 -0
- package/build/migrations-v2/0000000000059-billing-active-listing-cross-region-partner.ts +135 -0
- package/build/migrations-v2/0000000000060-accounting-integrity-change-driven.ts +99 -0
- package/build/migrations-v2/0000000000061-tenant-pending-onboarding-status.ts +37 -0
- package/build/migrations-v2/0000000000062-statement-payout-operations.ts +16 -0
- package/build/migrations-v2/0000000000063-missing-account-assignments-issue-code.ts +13 -0
- package/build/migrations-v2/0000000000064-journal-invalidation-source-lookup-index.ts +26 -0
- package/build/migrations-v2/0000000000065-hasura-connection-event-credentials.ts +42 -0
- package/build/migrations-v2/0000000000066-recurring-fee-listing-subscription-match-by.ts +51 -0
- package/build/migrations-v2/0000000000067-connection-credential-metadata.ts +60 -0
- package/build/migrations-v2/0000000000068-connection-credential-version.ts +34 -0
- package/build/migrations-v2/0000000000069-owner-statement-contact-email-delivery.ts +84 -0
- package/build/migrations-v2/0000000000070-payment-writer-compatibility.ts +69 -0
- package/build/migrations-v2/0000000000071-payments.ts +532 -0
- package/build/migrations-v2/0000000000072-journal-entry-payment-index.ts +21 -0
- package/build/migrations-v2/0000000000073-batch-invalidation-operation-registration.ts +74 -0
- package/build/migrations-v2/0000000000074-owner-statement-email-history.ts +34 -0
- package/build/migrations-v2/0000000000075-tenant-deletion-lookup-indexes.ts +46 -0
- package/build/migrations-v2/0000000000076-tenant-onboarding-not-null.ts +23 -0
- package/build/migrations-v2/0000000000077-payment-writer-statement-attachment.ts +92 -0
- package/build/migrations-v2/0000000000078-trigger-timeout-indexes.ts +44 -0
- package/build/migrations-v2/0000000000079-core-change-tenant-statistics.ts +26 -0
- package/build/migrations-v2/0000000000080-drop-legacy-tracking-event.ts +60 -0
- package/build/migrations-v2/0000000000081-recurring-fee-planner-operation-status.ts +35 -0
- package/build/migrations-v2/0000000000082-reservation-search-trigram-indexes.ts +54 -0
- package/build/migrations-v2/0000000000083-journal-entry-deposit-lookup-index.ts +31 -0
- package/build/migrations-v2/0000000000084-journal-entry-reservation-revenue-indexes.ts +57 -0
- package/build/migrations-v2/0000000000085-owner-statement-link-email-template.ts +23 -0
- package/build/migrations-v2/0000000000086-contact-payment-setup.ts +72 -0
- package/build/migrations-v2/0000000000087-address-delete-fk-indexes.ts +30 -0
- package/build/migrations-v2/0000000000088-owner-statement-email-switch.ts +76 -0
- package/build/migrations-v2/0000000000089-contact-bank-details-requested-at.ts +21 -0
- package/build/migrations-v2/0000000000090-contact-bank-account-api-key.ts +22 -0
- package/build/migrations-v2/0000000000091-contact-bank-details-request.ts +78 -0
- package/build/migrations-v2/0000000000092-payment-provider-reference.ts +22 -0
- package/build/migrations-v2/0000000000093-payment-reversal-offline-undo.ts +18 -0
- package/build/migrations-v2/0000000000094-reservation-status-checkout-index.ts +37 -0
- package/build/migrations-v2/0000000000095-payment-batches.ts +196 -0
- package/build/migrations-v2/0000000000096-guide-ongoing-tasks-issue-codes.ts +26 -0
- package/build/migrations-v2/0000000000097-reservation-line-mapping-suggestions.ts +53 -0
- package/build/migrations-v2/0000000000098-cancelled-reservation-balances-issue-code.ts +13 -0
- package/build/migrations-v2/0000000000099-contact-bank-account-request-source.ts +28 -0
- package/build/migrations-v2/0000000000100-drop-regional-feature-flags.ts +105 -0
- package/build/migrations-v2/0000000000101-bank-record-match-source.ts +45 -0
- package/build/migrations-v2/0000000000102-owner-statement-email-one-template.ts +63 -0
- package/build/migrations-v2/0000000000103-reservation-line-mapping-update-operation.ts +10 -0
- package/build/migrations-v2/0000000000104-export-job-payment-batch-pdf.ts +12 -0
- package/build/migrations-v2/0000000000105-drop-regional-token.ts +60 -0
- package/build/migrations-v2/0000000000106-incremental-audit-action-source.ts +158 -0
- package/build/migrations-v2/0000000000107-audit-mutation-transaction-insert-index.ts +44 -0
- package/build/migrations-v2/0000000000108-reservation-stay-type.ts +24 -0
- package/build/migrations-v2/0000000000109-long-term-liabilities-category-order.ts +21 -0
- package/build/migrations-v2/0000000000110-pms-sync-failures-issue-code.ts +13 -0
- package/build/migrations-v2/0000000000110-reservation-line-type-taxable.ts +21 -0
- package/build/migrations-v2/0000000000111-reservation-line-type-suggestion-taxable.ts +20 -0
- package/build/migrations-v2/0000000000112-contact-payment-method-outside-default.ts +44 -0
- package/build/migrations-v2/0000000000113-merchant-fee-reference-assignment.ts +25 -0
- package/build/migrations-v2/0000000000114-recurring-fee-nights-filter.ts +32 -0
- package/build/migrations-v2/0000000000115-bank-records-with-suggested-rule-issue-code.ts +13 -0
- package/build/migrations-v2/0000000000119-chart-of-accounts-classifications.ts +46 -0
- package/build/module/camel-case/index.d.ts +4 -4
- package/build/module/camel-case/index.js +3 -2
- package/build/module/camel-case/index.js.map +1 -1
- package/build/module/connect-handoff.d.ts +12 -0
- package/build/module/connect-handoff.js +70 -0
- package/build/module/connect-handoff.js.map +1 -0
- package/build/module/control-plane/index.d.ts +22 -1
- package/build/module/control-plane/index.js +9 -0
- package/build/module/control-plane/index.js.map +1 -1
- package/build/module/index.d.ts +46 -2
- package/build/module/index.js +382 -59
- package/build/module/index.js.map +1 -1
- package/build/module/isomorphic.d.ts +1 -1
- package/build/module/isomorphic.js +1 -1
- package/build/module/isomorphic.js.map +1 -1
- package/build/module/local/generate.js +4 -3
- package/build/module/local/generate.js.map +1 -1
- package/build/module/local/index.js +34 -10
- package/build/module/local/index.js.map +1 -1
- package/build/module/migration-source.d.ts +4 -0
- package/build/module/migration-source.js +42 -0
- package/build/module/migration-source.js.map +1 -0
- package/build/module/pganalyze-comment-plugin/comment-transformer.js +3 -1
- package/build/module/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/module/postgres-error.d.ts +1 -0
- package/build/module/postgres-error.js +11 -6
- package/build/module/postgres-error.js.map +1 -1
- package/build/module/query/listing/status.js +6 -2
- package/build/module/query/listing/status.js.map +1 -1
- package/build/module/query/tenant/feature-enabled.d.ts +6 -0
- package/build/module/query/tenant/feature-enabled.js +27 -0
- package/build/module/query/tenant/feature-enabled.js.map +1 -0
- package/build/module/query/tenant/index.d.ts +2 -0
- package/build/module/query/tenant/index.js +2 -0
- package/build/module/query/tenant/index.js.map +1 -1
- package/build/module/query/tenant/status.d.ts +1 -6
- package/build/module/query/tenant/status.js +4 -11
- package/build/module/query/tenant/status.js.map +1 -1
- package/build/module/query/tenant/where-uuid-in.d.ts +2 -0
- package/build/module/query/tenant/where-uuid-in.js +11 -0
- package/build/module/query/tenant/where-uuid-in.js.map +1 -0
- package/build/module/regional.d.ts +1 -0
- package/build/module/regional.js +1 -0
- package/build/module/regional.js.map +1 -1
- package/build/module/test/index.d.ts +7 -9
- package/build/module/test/index.js +11 -14
- package/build/module/test/index.js.map +1 -1
- package/build/module/v1.generated.d.ts +373 -73
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19721: feature flags are read from the control plane only. The regional
|
|
5
|
+
// copy and its catalog have no reader or writer left, so they are dropped
|
|
6
|
+
// without cascade: a missed dependency fails the migration.
|
|
7
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
8
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
9
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
10
|
+
|
|
11
|
+
await sql`drop table public.feature_enabled_team`.execute(db);
|
|
12
|
+
await sql`drop table public.feature_approval`.execute(db);
|
|
13
|
+
await sql`drop table public.feature`.execute(db);
|
|
14
|
+
await sql`drop table public.feature_approval_status`.execute(db);
|
|
15
|
+
await sql`drop table public.feature_status`.execute(db);
|
|
16
|
+
await sql`
|
|
17
|
+
delete from public.control_plane_projection_event
|
|
18
|
+
where aggregate_type = 'feature'
|
|
19
|
+
`.execute(db);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Recreates the tables as the baseline defined them, with the status reference
|
|
23
|
+
// rows. Flag rows and projection history are not restored.
|
|
24
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
25
|
+
await sql`
|
|
26
|
+
create table public.feature_status (name text primary key)
|
|
27
|
+
`.execute(db);
|
|
28
|
+
await sql`
|
|
29
|
+
create table public.feature_approval_status (name text primary key)
|
|
30
|
+
`.execute(db);
|
|
31
|
+
await sql`
|
|
32
|
+
insert into public.feature_status (name)
|
|
33
|
+
values ('deployed'), ('ready'), ('testing')
|
|
34
|
+
`.execute(db);
|
|
35
|
+
await sql`
|
|
36
|
+
insert into public.feature_approval_status (name)
|
|
37
|
+
values ('all'), ('disabled'), ('partially')
|
|
38
|
+
`.execute(db);
|
|
39
|
+
await sql`
|
|
40
|
+
create table public.feature (
|
|
41
|
+
id uuid primary key default gen_random_uuid(),
|
|
42
|
+
created_at timestamptz not null default now(),
|
|
43
|
+
updated_at timestamptz not null default now(),
|
|
44
|
+
title text not null,
|
|
45
|
+
url text,
|
|
46
|
+
description text,
|
|
47
|
+
issue_url text,
|
|
48
|
+
tenant_id uuid,
|
|
49
|
+
required_approvals jsonb default jsonb_build_array(),
|
|
50
|
+
status text default 'testing' references public.feature_status (name)
|
|
51
|
+
on update restrict on delete restrict,
|
|
52
|
+
constraint feature_required_approvals_array_check check (
|
|
53
|
+
required_approvals is null
|
|
54
|
+
or jsonb_typeof(required_approvals) = 'array'
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
`.execute(db);
|
|
58
|
+
await sql`
|
|
59
|
+
create table public.feature_approval (
|
|
60
|
+
id uuid primary key default gen_random_uuid(),
|
|
61
|
+
feature_id uuid not null references public.feature (id)
|
|
62
|
+
on update restrict on delete cascade,
|
|
63
|
+
user_id uuid not null references public."user" (id)
|
|
64
|
+
on update restrict on delete cascade,
|
|
65
|
+
created_at timestamptz not null default now(),
|
|
66
|
+
updated_at timestamptz not null default now(),
|
|
67
|
+
status text default 'disabled' references public.feature_approval_status (name)
|
|
68
|
+
on update restrict on delete restrict,
|
|
69
|
+
constraint feature_approval_feature_id_user_id_key unique (feature_id, user_id)
|
|
70
|
+
)
|
|
71
|
+
`.execute(db);
|
|
72
|
+
await sql`
|
|
73
|
+
create table public.feature_enabled_team (
|
|
74
|
+
id uuid primary key default gen_random_uuid(),
|
|
75
|
+
tenant_id uuid not null references public.tenant (id)
|
|
76
|
+
on update restrict on delete cascade,
|
|
77
|
+
feature_id uuid not null references public.feature (id)
|
|
78
|
+
on update restrict on delete cascade,
|
|
79
|
+
created_at timestamptz not null default now(),
|
|
80
|
+
updated_at timestamptz not null default now(),
|
|
81
|
+
status text default 'disabled' references public.feature_approval_status (name)
|
|
82
|
+
on update restrict on delete restrict,
|
|
83
|
+
constraint feature_enabled_team_tenant_id_feature_id_key
|
|
84
|
+
unique (tenant_id, feature_id)
|
|
85
|
+
)
|
|
86
|
+
`.execute(db);
|
|
87
|
+
await sql`create index feature_status_idx on public.feature (status)`.execute(
|
|
88
|
+
db
|
|
89
|
+
);
|
|
90
|
+
await sql`
|
|
91
|
+
create index feature_approval_status_idx on public.feature_approval (status)
|
|
92
|
+
`.execute(db);
|
|
93
|
+
await sql`
|
|
94
|
+
create index idx_feature_enabled_team_status
|
|
95
|
+
on public.feature_enabled_team (tenant_id, status)
|
|
96
|
+
where status = any (array['all', 'partially'])
|
|
97
|
+
`.execute(db);
|
|
98
|
+
for (const table of ['feature', 'feature_approval', 'feature_enabled_team']) {
|
|
99
|
+
await sql
|
|
100
|
+
.raw(
|
|
101
|
+
`create trigger set_public_${table}_updated_at before update on public.${table} for each row execute function set_current_timestamp_updated_at()`
|
|
102
|
+
)
|
|
103
|
+
.execute(db);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19733: record how each bank record was matched. Expand only: both columns are nullable
|
|
5
|
+
// and no writer needs them, so older deployments keep inserting matches with null (unknown).
|
|
6
|
+
// The table has about 150k rows in the largest region, so the constraint and index scans are
|
|
7
|
+
// sub-second under the lock timeouts below.
|
|
8
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
9
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
10
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
11
|
+
|
|
12
|
+
await sql`
|
|
13
|
+
create type accounting.bank_record_match_source as enum (
|
|
14
|
+
'manual', 'suggestion', 'rule', 'autoRule'
|
|
15
|
+
)
|
|
16
|
+
`.execute(db);
|
|
17
|
+
await sql`
|
|
18
|
+
alter table accounting.bank_record_transaction_payment
|
|
19
|
+
add column match_source accounting.bank_record_match_source null,
|
|
20
|
+
add column bank_rule_id uuid null
|
|
21
|
+
references accounting.bank_rule (id) on update restrict on delete set null,
|
|
22
|
+
add constraint bank_record_transaction_payment_bank_rule_source_check
|
|
23
|
+
check (bank_rule_id is null or match_source in ('rule', 'autoRule'))
|
|
24
|
+
`.execute(db);
|
|
25
|
+
await sql`
|
|
26
|
+
create index bank_record_transaction_payment_bank_rule_id_idx
|
|
27
|
+
on accounting.bank_record_transaction_payment (bank_rule_id)
|
|
28
|
+
where bank_rule_id is not null
|
|
29
|
+
`.execute(db);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
33
|
+
await sql`
|
|
34
|
+
drop index if exists accounting.bank_record_transaction_payment_bank_rule_id_idx
|
|
35
|
+
`.execute(db);
|
|
36
|
+
await sql`
|
|
37
|
+
alter table accounting.bank_record_transaction_payment
|
|
38
|
+
drop constraint if exists bank_record_transaction_payment_bank_rule_source_check,
|
|
39
|
+
drop column if exists bank_rule_id,
|
|
40
|
+
drop column if exists match_source
|
|
41
|
+
`.execute(db);
|
|
42
|
+
await sql`drop type if exists accounting.bank_record_match_source`.execute(
|
|
43
|
+
db
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// VRT-795: owner contacts and viewers share one owner statement email,
|
|
5
|
+
// `ownerStatement_owner`. Teams have edited that template since 2024; the
|
|
6
|
+
// link template is the copy migration 088 made, and no team had edited it by
|
|
7
|
+
// 2026-10-22. So each team keeps its `ownerStatement_owner` text. A link
|
|
8
|
+
// template replaces it only where the team saved the link template after the
|
|
9
|
+
// copy and after its last viewer edit, or saved no viewer template. The
|
|
10
|
+
// no-login preview line that migration 088 wrote then takes the default that
|
|
11
|
+
// names no login, because viewers log in. Link rows stay until every
|
|
12
|
+
// deployment reads the one template; deployed code still reads them.
|
|
13
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
14
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
15
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
16
|
+
|
|
17
|
+
await sql`
|
|
18
|
+
insert into public.email_template (tenant_id, type, data_json)
|
|
19
|
+
select
|
|
20
|
+
link.tenant_id,
|
|
21
|
+
'ownerStatement_owner',
|
|
22
|
+
case
|
|
23
|
+
when link.data_json ->> 'shortDescription'
|
|
24
|
+
= 'Your owner statement is ready. Open it with one click, no login needed.'
|
|
25
|
+
then link.data_json || jsonb_build_object(
|
|
26
|
+
'shortDescription',
|
|
27
|
+
'Your owner statement is ready to view.'
|
|
28
|
+
)
|
|
29
|
+
else link.data_json
|
|
30
|
+
end
|
|
31
|
+
from public.email_template link
|
|
32
|
+
left join public.email_template viewer
|
|
33
|
+
on viewer.tenant_id = link.tenant_id
|
|
34
|
+
and viewer.type = 'ownerStatement_owner'
|
|
35
|
+
where link.type = 'ownerStatementLink_owner'
|
|
36
|
+
and (
|
|
37
|
+
viewer.id is null
|
|
38
|
+
or (
|
|
39
|
+
link.updated_at > link.created_at
|
|
40
|
+
and link.updated_at > viewer.updated_at
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
on conflict (tenant_id, type) do update
|
|
44
|
+
set data_json = excluded.data_json
|
|
45
|
+
`.execute(db);
|
|
46
|
+
|
|
47
|
+
// Most saved templates still carry the old default preview line, which
|
|
48
|
+
// tells owners to log in. Teams never edited it, so it takes the new
|
|
49
|
+
// default; preview lines teams wrote stay.
|
|
50
|
+
await sql`
|
|
51
|
+
update public.email_template
|
|
52
|
+
set data_json = data_json || jsonb_build_object(
|
|
53
|
+
'shortDescription',
|
|
54
|
+
'Your owner statement is ready to view.'
|
|
55
|
+
)
|
|
56
|
+
where type = 'ownerStatement_owner'
|
|
57
|
+
and data_json ->> 'shortDescription'
|
|
58
|
+
~ '^An owner statement is ready for you\\. Log in to [^.]+ now to view it\\.\\s*$'
|
|
59
|
+
`.execute(db);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Replaced viewer text is gone, and the kept text is team data by now.
|
|
63
|
+
export async function down(_db: Kysely<unknown>): Promise<void> {}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await sql`alter type core.operation_type add value if not exists 'reservation-line-mapping-update'`.execute(
|
|
5
|
+
db
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// PostgreSQL enum additions are retained so historical operations remain readable.
|
|
10
|
+
export async function down(_db: Kysely<unknown>): Promise<void> {}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
// Expand storage only: the Trigger task and the API producer ship after it.
|
|
6
|
+
await sql`alter type core.export_job_task_id add value if not exists 'api/export-payment-batch-pdf'`.execute(
|
|
7
|
+
db
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// PostgreSQL enum additions are retained so historical export jobs stay readable.
|
|
12
|
+
export async function down(_db: Kysely<unknown>): Promise<void> {}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19885: authentication reads tokens only from control_plane.token. The
|
|
5
|
+
// regional table has no reader or writer left. Crunchy keeps its frozen copy:
|
|
6
|
+
// it is the only database that holds VRIntegrations teams, and the only one
|
|
7
|
+
// where the baseline partner is not the sole team with that realm. Dropped
|
|
8
|
+
// without cascade, so a missed dependency fails the migration.
|
|
9
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
10
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
11
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
12
|
+
|
|
13
|
+
const holdsVrIntegrationTeams = await sql<{ holds: boolean }>`
|
|
14
|
+
select exists (
|
|
15
|
+
select 1
|
|
16
|
+
from public.tenant
|
|
17
|
+
where storage_realm = 'vrintegration'
|
|
18
|
+
and id <> 'd6ab2bbe-e0fc-48d9-89a3-c3c05f4e79b5'
|
|
19
|
+
) as holds
|
|
20
|
+
`.execute(db);
|
|
21
|
+
if (holdsVrIntegrationTeams.rows[0]?.holds) return;
|
|
22
|
+
|
|
23
|
+
await sql`drop table public.token`.execute(db);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Recreates the empty table as the baseline defined it. Rows are not restored.
|
|
27
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
28
|
+
await sql`
|
|
29
|
+
create table if not exists public.token (
|
|
30
|
+
id text primary key default gen_random_uuid(),
|
|
31
|
+
payload jsonb not null default jsonb_build_object(),
|
|
32
|
+
created_at timestamptz not null default now(),
|
|
33
|
+
expires_at timestamptz,
|
|
34
|
+
type text,
|
|
35
|
+
nano_id text not null default gen_random_uuid(),
|
|
36
|
+
tenant_id uuid references public.tenant (id)
|
|
37
|
+
on update restrict on delete set null,
|
|
38
|
+
user_id uuid references public."user" (id)
|
|
39
|
+
on update restrict on delete set null
|
|
40
|
+
)
|
|
41
|
+
`.execute(db);
|
|
42
|
+
await sql`
|
|
43
|
+
create index if not exists token_id_type_idx on public.token (id, type)
|
|
44
|
+
`.execute(db);
|
|
45
|
+
await sql`
|
|
46
|
+
create index if not exists token_nano_id_idx on public.token (nano_id)
|
|
47
|
+
`.execute(db);
|
|
48
|
+
await sql`
|
|
49
|
+
create unique index if not exists token_partner_secret_unique_idx
|
|
50
|
+
on public.token (nano_id)
|
|
51
|
+
where type = any (array['partner_api_key', 'embedded_bootstrap'])
|
|
52
|
+
`.execute(db);
|
|
53
|
+
await sql`
|
|
54
|
+
create index if not exists token_tenant_id_id_type_idx
|
|
55
|
+
on public.token (tenant_id, id, type)
|
|
56
|
+
`.execute(db);
|
|
57
|
+
await sql`
|
|
58
|
+
create index if not exists token_tenant_id_key on public.token (tenant_id)
|
|
59
|
+
`.execute(db);
|
|
60
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// Every effect, attempt and invalidation write refreshed the action's operation
|
|
5
|
+
// source by aggregating all effects of the action (5,000 to 13,500 rows, 300 ms
|
|
6
|
+
// for the largest Panhandle action), about five times per effect (PRO-19919).
|
|
7
|
+
// While an unapplied effect is still queued or running, the source is only
|
|
8
|
+
// queued or running, so an existence lookup on the partial index decides it.
|
|
9
|
+
// Only the transition into a settled action runs the full aggregation.
|
|
10
|
+
// refresh_audit_action_source (fast path) and recompute_audit_action_source
|
|
11
|
+
// (full) both encode the running and queued conditions: change them together.
|
|
12
|
+
export async function up<Database>(db: Kysely<Database>): Promise<void> {
|
|
13
|
+
// The regional databases got this index concurrently beforehand. Even with
|
|
14
|
+
// `if not exists`, create index takes a share lock on audit.effect first and
|
|
15
|
+
// queues every effect write behind it, so skip the statement when it exists.
|
|
16
|
+
await sql`
|
|
17
|
+
do $$
|
|
18
|
+
begin
|
|
19
|
+
if not exists (
|
|
20
|
+
select 1 from pg_indexes
|
|
21
|
+
where schemaname = 'audit'
|
|
22
|
+
and indexname = 'audit_effect_action_active_idx'
|
|
23
|
+
) then
|
|
24
|
+
create index audit_effect_action_active_idx
|
|
25
|
+
on audit.effect (action_id)
|
|
26
|
+
where status in ('pending', 'claimed', 'running', 'failed');
|
|
27
|
+
end if;
|
|
28
|
+
end;
|
|
29
|
+
$$
|
|
30
|
+
`.execute(db);
|
|
31
|
+
|
|
32
|
+
await sql`
|
|
33
|
+
alter function core.refresh_audit_action_source(uuid)
|
|
34
|
+
rename to recompute_audit_action_source
|
|
35
|
+
`.execute(db);
|
|
36
|
+
|
|
37
|
+
await sql`
|
|
38
|
+
create function core.refresh_audit_action_source(target_action_id uuid)
|
|
39
|
+
returns void
|
|
40
|
+
language plpgsql
|
|
41
|
+
as $$
|
|
42
|
+
declare
|
|
43
|
+
source_row record;
|
|
44
|
+
next_status core.operation_status;
|
|
45
|
+
begin
|
|
46
|
+
select
|
|
47
|
+
source.operation_id,
|
|
48
|
+
source.started_at,
|
|
49
|
+
operation.type,
|
|
50
|
+
operation.public_id_format
|
|
51
|
+
into source_row
|
|
52
|
+
from core.operation_source as source
|
|
53
|
+
inner join core.operation as operation
|
|
54
|
+
on operation.id = source.operation_id
|
|
55
|
+
where source.source_type = 'audit-action'
|
|
56
|
+
and source.source_id = target_action_id;
|
|
57
|
+
|
|
58
|
+
if found
|
|
59
|
+
and source_row.type = 'reservation-journal-refresh'
|
|
60
|
+
and source_row.started_at is not null then
|
|
61
|
+
select
|
|
62
|
+
case
|
|
63
|
+
when exists (
|
|
64
|
+
select 1
|
|
65
|
+
from audit.effect as effect
|
|
66
|
+
left join accounting.reservation_journal_invalidation as invalidation
|
|
67
|
+
on invalidation.tenant_id = effect.tenant_id
|
|
68
|
+
and invalidation.effect_id = effect.id
|
|
69
|
+
where effect.action_id = target_action_id
|
|
70
|
+
and effect.status in ('claimed', 'running')
|
|
71
|
+
and (invalidation.id is null or invalidation.applied_at is null)
|
|
72
|
+
and (
|
|
73
|
+
source_row.public_id_format = 'legacy'
|
|
74
|
+
or (
|
|
75
|
+
effect.effect_type in (
|
|
76
|
+
'REFRESH_RESERVATION_JOURNAL',
|
|
77
|
+
'REFRESH_RECURRING_FEE_RESERVATIONS'
|
|
78
|
+
)
|
|
79
|
+
and effect.entity_type in ('reservation', 'recurringFee')
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
) then 'running'
|
|
83
|
+
when exists (
|
|
84
|
+
select 1
|
|
85
|
+
from audit.effect as effect
|
|
86
|
+
left join accounting.reservation_journal_invalidation as invalidation
|
|
87
|
+
on invalidation.tenant_id = effect.tenant_id
|
|
88
|
+
and invalidation.effect_id = effect.id
|
|
89
|
+
where effect.action_id = target_action_id
|
|
90
|
+
and (
|
|
91
|
+
effect.status = 'pending'
|
|
92
|
+
or (
|
|
93
|
+
effect.status = 'failed'
|
|
94
|
+
and effect.retry_count < effect.max_retries
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
and (invalidation.id is null or invalidation.applied_at is null)
|
|
98
|
+
and (
|
|
99
|
+
source_row.public_id_format = 'legacy'
|
|
100
|
+
or (
|
|
101
|
+
effect.effect_type in (
|
|
102
|
+
'REFRESH_RESERVATION_JOURNAL',
|
|
103
|
+
'REFRESH_RECURRING_FEE_RESERVATIONS'
|
|
104
|
+
)
|
|
105
|
+
and effect.entity_type in ('reservation', 'recurringFee')
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
) then 'queued'
|
|
109
|
+
end::core.operation_status
|
|
110
|
+
into next_status;
|
|
111
|
+
|
|
112
|
+
if next_status is not null then
|
|
113
|
+
update core.operation_source as source
|
|
114
|
+
set
|
|
115
|
+
status = next_status,
|
|
116
|
+
finished_at = null,
|
|
117
|
+
source_version = source.source_version + 1
|
|
118
|
+
where source.operation_id = source_row.operation_id
|
|
119
|
+
and source.source_type = 'audit-action'
|
|
120
|
+
and source.source_id = target_action_id
|
|
121
|
+
and (
|
|
122
|
+
source.status is distinct from next_status
|
|
123
|
+
or source.finished_at is not null
|
|
124
|
+
);
|
|
125
|
+
perform core.refresh_operation_state(source_row.operation_id);
|
|
126
|
+
return;
|
|
127
|
+
end if;
|
|
128
|
+
end if;
|
|
129
|
+
|
|
130
|
+
perform core.recompute_audit_action_source(target_action_id);
|
|
131
|
+
end;
|
|
132
|
+
$$
|
|
133
|
+
`.execute(db);
|
|
134
|
+
|
|
135
|
+
await sql`
|
|
136
|
+
do $$
|
|
137
|
+
begin
|
|
138
|
+
if exists (select 1 from pg_roles where rolname = 'application') then
|
|
139
|
+
grant execute on function
|
|
140
|
+
core.refresh_audit_action_source(uuid),
|
|
141
|
+
core.recompute_audit_action_source(uuid)
|
|
142
|
+
to application;
|
|
143
|
+
end if;
|
|
144
|
+
end;
|
|
145
|
+
$$
|
|
146
|
+
`.execute(db);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function down<Database>(db: Kysely<Database>): Promise<void> {
|
|
150
|
+
await sql`drop function core.refresh_audit_action_source(uuid)`.execute(db);
|
|
151
|
+
await sql`
|
|
152
|
+
alter function core.recompute_audit_action_source(uuid)
|
|
153
|
+
rename to refresh_audit_action_source
|
|
154
|
+
`.execute(db);
|
|
155
|
+
await sql`drop index if exists audit.audit_effect_action_active_idx`.execute(
|
|
156
|
+
db
|
|
157
|
+
);
|
|
158
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// GET /transactions looks up who created each listed transaction in
|
|
5
|
+
// audit.mutation. The general subject index forces a heap read for every
|
|
6
|
+
// mutation of the transaction (updates included) before the INSERT filter, and
|
|
7
|
+
// cold reads took 330-445 ms for 100 rows on the largest teams. This partial index holds only the
|
|
8
|
+
// creation rows and carries the columns the lookup reads. On large databases
|
|
9
|
+
// run scripts/ben-2/pro-19855-create-audit-index.ts first: it builds the index
|
|
10
|
+
// concurrently, and this migration then skips it. The lookup must
|
|
11
|
+
// keep `subject_type` and `op` as constants so a generic plan can use the index.
|
|
12
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
13
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
14
|
+
await sql`set local statement_timeout = '30min'`.execute(db);
|
|
15
|
+
const existing = await sql<{ valid: boolean }>`
|
|
16
|
+
select (i.indisvalid and i.indisready) as valid
|
|
17
|
+
from pg_index as i
|
|
18
|
+
inner join pg_class as index_class on index_class.oid = i.indexrelid
|
|
19
|
+
where index_class.relname = 'audit_mutation_transaction_insert_idx'
|
|
20
|
+
`.execute(db);
|
|
21
|
+
// `create index if not exists` locks the table before it finds the index, which
|
|
22
|
+
// times out on a busy database, so skip a valid pre-built index here.
|
|
23
|
+
if (existing.rows[0]?.valid) return;
|
|
24
|
+
// A failed concurrent build leaves an invalid index that `if not exists`
|
|
25
|
+
// would keep, so drop it first.
|
|
26
|
+
if (existing.rows[0]) {
|
|
27
|
+
await sql`
|
|
28
|
+
drop index audit.audit_mutation_transaction_insert_idx
|
|
29
|
+
`.execute(db);
|
|
30
|
+
}
|
|
31
|
+
await sql`
|
|
32
|
+
create index audit_mutation_transaction_insert_idx
|
|
33
|
+
on audit.mutation (tenant_id, subject_id) include (action_id, created_at)
|
|
34
|
+
where subject_type = 'transaction' and op = 'INSERT'
|
|
35
|
+
`.execute(db);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
39
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
40
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
41
|
+
await sql`
|
|
42
|
+
drop index if exists audit.audit_mutation_transaction_insert_idx
|
|
43
|
+
`.execute(db);
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// GRO-1875: tell owner and friends & family stays apart from guest bookings. The
|
|
5
|
+
// constant default makes the column a catalog-only change, and older writers
|
|
6
|
+
// that omit it keep inserting guest stays.
|
|
7
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
8
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
9
|
+
|
|
10
|
+
await sql`
|
|
11
|
+
create type public.reservation_stay_type as enum ('guest', 'owner', 'ownerGuest')
|
|
12
|
+
`.execute(db);
|
|
13
|
+
await sql`
|
|
14
|
+
alter table public.reservation
|
|
15
|
+
add column stay_type public.reservation_stay_type not null default 'guest'
|
|
16
|
+
`.execute(db);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
20
|
+
await sql`
|
|
21
|
+
alter table public.reservation drop column if exists stay_type
|
|
22
|
+
`.execute(db);
|
|
23
|
+
await sql`drop type if exists public.reservation_stay_type`.execute(db);
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19960: Long-term Liabilities shared index 32 with Other Current
|
|
5
|
+
// Liabilities, so the name tiebreak listed it first. Current comes before
|
|
6
|
+
// long-term, as on a balance sheet.
|
|
7
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
8
|
+
await sql`
|
|
9
|
+
update accounting.account_category
|
|
10
|
+
set "index" = 33
|
|
11
|
+
where id = '3022ebdd-3673-448c-a15d-eaa16a5a4a43'::uuid
|
|
12
|
+
`.execute(db);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
16
|
+
await sql`
|
|
17
|
+
update accounting.account_category
|
|
18
|
+
set "index" = 32
|
|
19
|
+
where id = '3022ebdd-3673-448c-a15d-eaa16a5a4a43'::uuid
|
|
20
|
+
`.execute(db);
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
// Expand storage only. The code must be writable on every channel before
|
|
6
|
+
// API producers mark it dirty in shared regional databases.
|
|
7
|
+
await sql`alter type health.tenant_issue_code add value if not exists 'pmsSyncFailures'`.execute(
|
|
8
|
+
db
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// PostgreSQL enum additions are retained so historical issues remain readable.
|
|
13
|
+
export async function down(_db: Kysely<unknown>): Promise<void> {}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19939: taxability is stored once per line type on the base mapping row.
|
|
5
|
+
// The constant default makes the column a catalog-only change, and older
|
|
6
|
+
// writers that omit it keep inserting untaxed line types.
|
|
7
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
8
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
9
|
+
|
|
10
|
+
await sql`
|
|
11
|
+
alter table accounting.account_reservation_line_type
|
|
12
|
+
add column taxable boolean not null default false
|
|
13
|
+
`.execute(db);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await sql`
|
|
18
|
+
alter table accounting.account_reservation_line_type
|
|
19
|
+
drop column if exists taxable
|
|
20
|
+
`.execute(db);
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19939: a VRPilot suggestion may carry no taxable opinion, which the
|
|
5
|
+
// not null `taxable` column cannot store. Only suggestion rows use this column.
|
|
6
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
7
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
8
|
+
|
|
9
|
+
await sql`
|
|
10
|
+
alter table accounting.account_reservation_line_type
|
|
11
|
+
add column suggestion_taxable boolean
|
|
12
|
+
`.execute(db);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
16
|
+
await sql`
|
|
17
|
+
alter table accounting.account_reservation_line_type
|
|
18
|
+
drop column if exists suggestion_taxable
|
|
19
|
+
`.execute(db);
|
|
20
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19798: every contact starts on "outside" and a default never points at
|
|
5
|
+
// a method whose details are missing. ACH via Ramp needs bank details in VRT
|
|
6
|
+
// or at Ramp, ACH via Nacha needs bank details in VRT, check needs an address.
|
|
7
|
+
// Deployed writers may still store null, so NOT NULL waits for a later migration.
|
|
8
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
9
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
10
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
11
|
+
|
|
12
|
+
await sql`
|
|
13
|
+
alter table accounting.contact
|
|
14
|
+
alter column default_payment_method set default 'outside'
|
|
15
|
+
`.execute(db);
|
|
16
|
+
// The backfill is not an edit: keep updated_at and skip audit triggers.
|
|
17
|
+
await sql`alter table accounting.contact disable trigger user`.execute(db);
|
|
18
|
+
await sql`
|
|
19
|
+
update accounting.contact contact
|
|
20
|
+
set default_payment_method = 'outside'
|
|
21
|
+
where default_payment_method is null
|
|
22
|
+
or (
|
|
23
|
+
default_payment_method = 'check'
|
|
24
|
+
and coalesce(trim(address_data->>'line1'), '') = ''
|
|
25
|
+
)
|
|
26
|
+
or (
|
|
27
|
+
default_payment_method in ('rampAch', 'nachaAch')
|
|
28
|
+
and not exists (
|
|
29
|
+
select 1 from accounting.contact_bank_account bank
|
|
30
|
+
where bank.contact_id = contact.id
|
|
31
|
+
)
|
|
32
|
+
and (default_payment_method = 'nachaAch' or ramp_last4_digits is null)
|
|
33
|
+
)
|
|
34
|
+
`.execute(db);
|
|
35
|
+
await sql`alter table accounting.contact enable trigger user`.execute(db);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Backfilled and chosen "outside" values are indistinguishable, so they stay.
|
|
39
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
40
|
+
await sql`
|
|
41
|
+
alter table accounting.contact
|
|
42
|
+
alter column default_payment_method drop default
|
|
43
|
+
`.execute(db);
|
|
44
|
+
}
|