@vrplatform/kysely 1.3.45-391 → 1.3.45-39120281816
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 +19 -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 +38 -2
- package/build/main/index.js +323 -58
- package/build/main/index.js.map +1 -1
- package/build/main/isomorphic.d.ts +1 -1
- package/build/main/isomorphic.js +2 -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 +3 -0
- 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/query/listing/status.js +6 -2
- package/build/main/query/listing/status.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/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.js +4 -3
- package/build/main/test/index.js.map +1 -1
- package/build/main/v1.generated.d.ts +255 -19
- 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/0000000000049-queued-journal-operation-failures.ts +60 -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 +39 -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/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 +19 -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 +38 -2
- package/build/module/index.js +322 -58
- 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 +3 -0
- 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/query/listing/status.js +6 -2
- package/build/module/query/listing/status.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/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.js +4 -3
- package/build/module/test/index.js.map +1 -1
- package/build/module/v1.generated.d.ts +255 -19
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// CUS-2977: a billing partner homed in another data region has no row in this
|
|
5
|
+
// regional database. That absence is valid and must not make the team count
|
|
6
|
+
// zero active listings. Only a locally present, non-active billing partner
|
|
7
|
+
// does, matching kysely `whereTenantActive` (PRO-17712). `create or replace`
|
|
8
|
+
// keeps the existing grants.
|
|
9
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
10
|
+
await sql`
|
|
11
|
+
create or replace function billing.active_listing_count(
|
|
12
|
+
selected_tenant_id uuid
|
|
13
|
+
) returns integer
|
|
14
|
+
language sql
|
|
15
|
+
stable
|
|
16
|
+
as $$
|
|
17
|
+
select count(*)::integer
|
|
18
|
+
from public.listing as listing
|
|
19
|
+
inner join public.tenant as tenant
|
|
20
|
+
on tenant.id = listing.tenant_id
|
|
21
|
+
where listing.tenant_id = selected_tenant_id
|
|
22
|
+
and tenant.calculated_status = 'active'
|
|
23
|
+
and not exists (
|
|
24
|
+
select 1
|
|
25
|
+
from public.tenant as billing_partner
|
|
26
|
+
where billing_partner.id = coalesce(
|
|
27
|
+
tenant.calculated_billing_partner_id,
|
|
28
|
+
'7bfec41f-aa3f-4602-95d2-f7996e4f0e59'::uuid
|
|
29
|
+
)
|
|
30
|
+
and billing_partner.calculated_status is distinct from 'active'
|
|
31
|
+
)
|
|
32
|
+
and (
|
|
33
|
+
(
|
|
34
|
+
tenant.is_general_ledger = false
|
|
35
|
+
and listing.calculated_status = 'active'
|
|
36
|
+
) or (
|
|
37
|
+
tenant.is_general_ledger = true
|
|
38
|
+
and not exists (
|
|
39
|
+
select 1
|
|
40
|
+
from public.listing_ownership_period as ownership
|
|
41
|
+
where ownership.listing_id = coalesce(
|
|
42
|
+
listing.parent_id,
|
|
43
|
+
listing.id
|
|
44
|
+
)
|
|
45
|
+
and ownership.tenant_id = listing.tenant_id
|
|
46
|
+
and ownership.set_listing_inactive = true
|
|
47
|
+
and ownership.start_at <= current_date
|
|
48
|
+
and (
|
|
49
|
+
ownership.end_at is null
|
|
50
|
+
or ownership.end_at >= current_date
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
$$
|
|
56
|
+
`.execute(db);
|
|
57
|
+
|
|
58
|
+
// Append a corrected fact, effective now, for every active team whose
|
|
59
|
+
// billing partner has no local row. These are the only teams whose count
|
|
60
|
+
// changes. Completed-month billing reads the latest fact before the month
|
|
61
|
+
// ends, so applying this before the month closes corrects that month.
|
|
62
|
+
// Earlier wrong facts stay as recorded history.
|
|
63
|
+
await sql`
|
|
64
|
+
select billing.record_listing_facts(
|
|
65
|
+
array(
|
|
66
|
+
select tenant.id
|
|
67
|
+
from public.tenant as tenant
|
|
68
|
+
where tenant.type = 'propertyManager'
|
|
69
|
+
and tenant.calculated_status = 'active'
|
|
70
|
+
and tenant.calculated_billing_partner_id is not null
|
|
71
|
+
and not exists (
|
|
72
|
+
select 1
|
|
73
|
+
from public.tenant as billing_partner
|
|
74
|
+
where billing_partner.id = tenant.calculated_billing_partner_id
|
|
75
|
+
)
|
|
76
|
+
and exists (
|
|
77
|
+
select 1
|
|
78
|
+
from billing.listing_fact as fact
|
|
79
|
+
where fact.tenant_id = tenant.id
|
|
80
|
+
)
|
|
81
|
+
),
|
|
82
|
+
'daily_reconciliation',
|
|
83
|
+
gen_random_uuid(),
|
|
84
|
+
now(),
|
|
85
|
+
true
|
|
86
|
+
)
|
|
87
|
+
`.execute(db);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
91
|
+
await sql`
|
|
92
|
+
create or replace function billing.active_listing_count(
|
|
93
|
+
selected_tenant_id uuid
|
|
94
|
+
) returns integer
|
|
95
|
+
language sql
|
|
96
|
+
stable
|
|
97
|
+
as $$
|
|
98
|
+
select count(*)::integer
|
|
99
|
+
from public.listing as listing
|
|
100
|
+
inner join public.tenant as tenant
|
|
101
|
+
on tenant.id = listing.tenant_id
|
|
102
|
+
left join public.tenant as billing_partner
|
|
103
|
+
on billing_partner.id = tenant.calculated_billing_partner_id
|
|
104
|
+
where listing.tenant_id = selected_tenant_id
|
|
105
|
+
and tenant.calculated_status = 'active'
|
|
106
|
+
and (
|
|
107
|
+
tenant.calculated_billing_partner_id is null
|
|
108
|
+
or billing_partner.calculated_status = 'active'
|
|
109
|
+
)
|
|
110
|
+
and (
|
|
111
|
+
(
|
|
112
|
+
tenant.is_general_ledger = false
|
|
113
|
+
and listing.calculated_status = 'active'
|
|
114
|
+
) or (
|
|
115
|
+
tenant.is_general_ledger = true
|
|
116
|
+
and not exists (
|
|
117
|
+
select 1
|
|
118
|
+
from public.listing_ownership_period as ownership
|
|
119
|
+
where ownership.listing_id = coalesce(
|
|
120
|
+
listing.parent_id,
|
|
121
|
+
listing.id
|
|
122
|
+
)
|
|
123
|
+
and ownership.tenant_id = listing.tenant_id
|
|
124
|
+
and ownership.set_listing_inactive = true
|
|
125
|
+
and ownership.start_at <= current_date
|
|
126
|
+
and (
|
|
127
|
+
ownership.end_at is null
|
|
128
|
+
or ownership.end_at >= current_date
|
|
129
|
+
)
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
$$
|
|
134
|
+
`.execute(db);
|
|
135
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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 type health.accounting_integrity_dirty_record_type as enum (
|
|
7
|
+
'reservation',
|
|
8
|
+
'transaction'
|
|
9
|
+
)
|
|
10
|
+
`.execute(db);
|
|
11
|
+
|
|
12
|
+
await sql`
|
|
13
|
+
create table health.accounting_integrity_dirty_record (
|
|
14
|
+
tenant_id uuid not null references public.tenant(id) on delete cascade,
|
|
15
|
+
record_type health.accounting_integrity_dirty_record_type not null,
|
|
16
|
+
record_id uuid not null,
|
|
17
|
+
dirty_version bigint not null default 1,
|
|
18
|
+
computed_version bigint not null default 0,
|
|
19
|
+
dirty_at timestamptz not null default now(),
|
|
20
|
+
computed_at timestamptz,
|
|
21
|
+
claimed_until timestamptz,
|
|
22
|
+
claim_token uuid,
|
|
23
|
+
created_at timestamptz not null default now(),
|
|
24
|
+
updated_at timestamptz not null default now(),
|
|
25
|
+
constraint accounting_integrity_dirty_record_identity_key
|
|
26
|
+
primary key (tenant_id, record_type, record_id),
|
|
27
|
+
constraint accounting_integrity_dirty_record_version_check
|
|
28
|
+
check (dirty_version >= 0 and computed_version >= 0)
|
|
29
|
+
)
|
|
30
|
+
`.execute(db);
|
|
31
|
+
|
|
32
|
+
await sql`
|
|
33
|
+
create index accounting_integrity_dirty_record_pending_idx
|
|
34
|
+
on health.accounting_integrity_dirty_record (
|
|
35
|
+
dirty_at,
|
|
36
|
+
tenant_id,
|
|
37
|
+
record_type,
|
|
38
|
+
record_id,
|
|
39
|
+
claimed_until
|
|
40
|
+
)
|
|
41
|
+
where dirty_version > computed_version
|
|
42
|
+
`.execute(db);
|
|
43
|
+
|
|
44
|
+
await sql`
|
|
45
|
+
create table health.accounting_integrity_sweep_cursor (
|
|
46
|
+
record_type health.accounting_integrity_dirty_record_type primary key,
|
|
47
|
+
last_tenant_id uuid,
|
|
48
|
+
last_record_id uuid,
|
|
49
|
+
cycle_started_at timestamptz not null default now(),
|
|
50
|
+
last_cycle_completed_at timestamptz,
|
|
51
|
+
definitions_hash text,
|
|
52
|
+
created_at timestamptz not null default now(),
|
|
53
|
+
updated_at timestamptz not null default now()
|
|
54
|
+
)
|
|
55
|
+
`.execute(db);
|
|
56
|
+
|
|
57
|
+
await sql`
|
|
58
|
+
create table health.accounting_integrity_comparison_finding (
|
|
59
|
+
id uuid primary key default gen_random_uuid(),
|
|
60
|
+
data_region text not null,
|
|
61
|
+
code text not null,
|
|
62
|
+
tenant_id uuid not null references public.tenant(id) on delete cascade,
|
|
63
|
+
record_type health.accounting_integrity_dirty_record_type not null,
|
|
64
|
+
record_id uuid not null,
|
|
65
|
+
case_key text not null,
|
|
66
|
+
severity health.accounting_integrity_severity not null,
|
|
67
|
+
content_hash text not null,
|
|
68
|
+
first_seen_at timestamptz not null,
|
|
69
|
+
created_at timestamptz not null default now(),
|
|
70
|
+
updated_at timestamptz not null default now(),
|
|
71
|
+
constraint accounting_integrity_comparison_finding_identity_key
|
|
72
|
+
unique (data_region, code, tenant_id, case_key)
|
|
73
|
+
)
|
|
74
|
+
`.execute(db);
|
|
75
|
+
|
|
76
|
+
await sql`
|
|
77
|
+
create index accounting_integrity_comparison_finding_report_idx
|
|
78
|
+
on health.accounting_integrity_comparison_finding (
|
|
79
|
+
data_region,
|
|
80
|
+
code,
|
|
81
|
+
case_key
|
|
82
|
+
)
|
|
83
|
+
`.execute(db);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
87
|
+
await sql`
|
|
88
|
+
drop table if exists health.accounting_integrity_comparison_finding
|
|
89
|
+
`.execute(db);
|
|
90
|
+
await sql`
|
|
91
|
+
drop table if exists health.accounting_integrity_sweep_cursor
|
|
92
|
+
`.execute(db);
|
|
93
|
+
await sql`
|
|
94
|
+
drop table if exists health.accounting_integrity_dirty_record
|
|
95
|
+
`.execute(db);
|
|
96
|
+
await sql`
|
|
97
|
+
drop type if exists health.accounting_integrity_dirty_record_type
|
|
98
|
+
`.execute(db);
|
|
99
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 public.tenant
|
|
9
|
+
alter column calculated_status set expression as (
|
|
10
|
+
case
|
|
11
|
+
when status = 'active' and (
|
|
12
|
+
billing_subscription_status = 'active'
|
|
13
|
+
or billing_subscription_status is null
|
|
14
|
+
or (billing_subscription_status = 'pending' and is_onboarding = true)
|
|
15
|
+
) then 'active'
|
|
16
|
+
else 'inactive'
|
|
17
|
+
end
|
|
18
|
+
)
|
|
19
|
+
`.execute(db);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
23
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
24
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
25
|
+
await sql`
|
|
26
|
+
alter table public.tenant
|
|
27
|
+
alter column calculated_status set expression as (
|
|
28
|
+
case
|
|
29
|
+
when status = 'active' and (
|
|
30
|
+
billing_subscription_status = 'active'
|
|
31
|
+
or billing_subscription_status is null
|
|
32
|
+
) then 'active'
|
|
33
|
+
else 'inactive'
|
|
34
|
+
end
|
|
35
|
+
)
|
|
36
|
+
`.execute(db);
|
|
37
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await sql`alter table core.async_operation_result add column checkpoint jsonb`.execute(
|
|
5
|
+
db
|
|
6
|
+
);
|
|
7
|
+
await sql`alter type core.operation_type add value if not exists 'statement-payout'`.execute(
|
|
8
|
+
db
|
|
9
|
+
);
|
|
10
|
+
await sql`alter type core.operation_type add value if not exists 'statement-payout-preview'`.execute(
|
|
11
|
+
db
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// PostgreSQL enum additions are retained so historical operations remain readable.
|
|
16
|
+
export async function down(_db: Kysely<unknown>): Promise<void> {}
|
|
@@ -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 'missingAccountAssignments'`.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,26 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// The recurring-fee journal status joins invalidations by source resource,
|
|
5
|
+
// applied and pending. The existing source index is partial on pending rows, so
|
|
6
|
+
// the join scanned every invalidation of the tenant.
|
|
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 = '120s'`.execute(db);
|
|
10
|
+
|
|
11
|
+
await sql`
|
|
12
|
+
create index if not exists reservation_journal_invalidation_source_idx
|
|
13
|
+
on accounting.reservation_journal_invalidation (
|
|
14
|
+
tenant_id,
|
|
15
|
+
source_resource_type,
|
|
16
|
+
source_resource_id
|
|
17
|
+
)
|
|
18
|
+
where source_resource_id is not null
|
|
19
|
+
`.execute(db);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
23
|
+
await sql`
|
|
24
|
+
drop index if exists accounting.reservation_journal_invalidation_source_idx
|
|
25
|
+
`.execute(db);
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// Hasura's tracking_connection trigger copies the whole connection row,
|
|
5
|
+
// including credentials, into hdb_catalog.event_log. Hasura regenerates its own
|
|
6
|
+
// trigger functions from metadata, so the credentials are stripped on the
|
|
7
|
+
// event_log insert instead. The webhook consumer reads id, tenant_id, app_id and
|
|
8
|
+
// status only.
|
|
9
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
10
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
11
|
+
|
|
12
|
+
await sql`
|
|
13
|
+
create or replace function public.strip_connection_event_credentials()
|
|
14
|
+
returns trigger
|
|
15
|
+
language plpgsql
|
|
16
|
+
as $$
|
|
17
|
+
begin
|
|
18
|
+
new.payload := new.payload #- '{data,old,credentials}' #- '{data,new,credentials}';
|
|
19
|
+
return new;
|
|
20
|
+
end;
|
|
21
|
+
$$
|
|
22
|
+
`.execute(db);
|
|
23
|
+
await sql`
|
|
24
|
+
drop trigger if exists strip_connection_credentials on hdb_catalog.event_log
|
|
25
|
+
`.execute(db);
|
|
26
|
+
await sql`
|
|
27
|
+
create trigger strip_connection_credentials
|
|
28
|
+
before insert on hdb_catalog.event_log
|
|
29
|
+
for each row
|
|
30
|
+
when (new.schema_name = 'public' and new.table_name = 'connection')
|
|
31
|
+
execute function public.strip_connection_event_credentials()
|
|
32
|
+
`.execute(db);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
36
|
+
await sql`
|
|
37
|
+
drop trigger if exists strip_connection_credentials on hdb_catalog.event_log
|
|
38
|
+
`.execute(db);
|
|
39
|
+
await sql`
|
|
40
|
+
drop function if exists public.strip_connection_event_credentials()
|
|
41
|
+
`.execute(db);
|
|
42
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// Each listing period of a recurring fee chooses whether reservations match its
|
|
5
|
+
// dates by stay date (posting date of the fee) or by booked date. Expand only:
|
|
6
|
+
// existing rows default to stay date, which is today's behavior. A stay date
|
|
7
|
+
// and a booked date period of one fee and listing may start on the same date,
|
|
8
|
+
// so the unique start date includes the basis.
|
|
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 = '120s'`.execute(db);
|
|
12
|
+
|
|
13
|
+
await sql`
|
|
14
|
+
do $$
|
|
15
|
+
begin
|
|
16
|
+
create type public.recurring_fee_listing_subscription_match_by
|
|
17
|
+
as enum ('stayDate', 'bookedDate');
|
|
18
|
+
exception when duplicate_object then null;
|
|
19
|
+
end $$
|
|
20
|
+
`.execute(db);
|
|
21
|
+
|
|
22
|
+
await sql`
|
|
23
|
+
alter table public.recurring_fee_listing_subscription
|
|
24
|
+
add column if not exists match_by
|
|
25
|
+
public.recurring_fee_listing_subscription_match_by
|
|
26
|
+
not null default 'stayDate'
|
|
27
|
+
`.execute(db);
|
|
28
|
+
|
|
29
|
+
await sql`
|
|
30
|
+
alter table public.recurring_fee_listing_subscription
|
|
31
|
+
drop constraint recurring_fee_listing_subscription_recurring_fee_id_listing_id_,
|
|
32
|
+
add constraint recurring_fee_listing_subscription_recurring_fee_id_listing_id_
|
|
33
|
+
unique (recurring_fee_id, listing_id, match_by, start_at)
|
|
34
|
+
`.execute(db);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
38
|
+
await sql`
|
|
39
|
+
alter table public.recurring_fee_listing_subscription
|
|
40
|
+
drop constraint recurring_fee_listing_subscription_recurring_fee_id_listing_id_,
|
|
41
|
+
add constraint recurring_fee_listing_subscription_recurring_fee_id_listing_id_
|
|
42
|
+
unique (recurring_fee_id, listing_id, start_at)
|
|
43
|
+
`.execute(db);
|
|
44
|
+
await sql`
|
|
45
|
+
alter table public.recurring_fee_listing_subscription
|
|
46
|
+
drop column if exists match_by
|
|
47
|
+
`.execute(db);
|
|
48
|
+
await sql`
|
|
49
|
+
drop type if exists public.recurring_fee_listing_subscription_match_by
|
|
50
|
+
`.execute(db);
|
|
51
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(kysely: Kysely<unknown>) {
|
|
4
|
+
await sql`set local lock_timeout = '5s'`.execute(kysely);
|
|
5
|
+
await sql`alter table public.connection add column if not exists credential_metadata jsonb`.execute(
|
|
6
|
+
kysely
|
|
7
|
+
);
|
|
8
|
+
// The trigger covers deployed writers during the reader cutover. Only known
|
|
9
|
+
// environment labels and numeric expiry are metadata; provider payloads stay private.
|
|
10
|
+
await sql`
|
|
11
|
+
create or replace function public.connection_credential_metadata(value jsonb)
|
|
12
|
+
returns jsonb language sql immutable parallel safe as $function$
|
|
13
|
+
select case when value is null then null else jsonb_strip_nulls(jsonb_build_object(
|
|
14
|
+
'environment', case when value ->> 'environment' in ('sandbox', 'development', 'production', 'demo')
|
|
15
|
+
then value -> 'environment' else null end,
|
|
16
|
+
'invalidEnvironment', case when value ->> 'environment' is not null
|
|
17
|
+
and value ->> 'environment' not in ('sandbox', 'development', 'production', 'demo') then true else null end,
|
|
18
|
+
'_exposix', case when jsonb_typeof(value -> '_exposix') = 'number'
|
|
19
|
+
then value -> '_exposix' else null end
|
|
20
|
+
)) end
|
|
21
|
+
$function$
|
|
22
|
+
`.execute(kysely);
|
|
23
|
+
await sql`
|
|
24
|
+
create or replace function public.mirror_connection_credential_metadata()
|
|
25
|
+
returns trigger language plpgsql as $function$
|
|
26
|
+
begin
|
|
27
|
+
new.credential_metadata := public.connection_credential_metadata(new.credentials);
|
|
28
|
+
return new;
|
|
29
|
+
end;
|
|
30
|
+
$function$
|
|
31
|
+
`.execute(kysely);
|
|
32
|
+
await sql`drop trigger if exists mirror_connection_credential_metadata on public.connection`.execute(
|
|
33
|
+
kysely
|
|
34
|
+
);
|
|
35
|
+
await sql`create trigger mirror_connection_credential_metadata
|
|
36
|
+
before insert or update of credentials on public.connection
|
|
37
|
+
for each row execute function public.mirror_connection_credential_metadata()`.execute(
|
|
38
|
+
kysely
|
|
39
|
+
);
|
|
40
|
+
await sql`update public.connection
|
|
41
|
+
set credential_metadata = public.connection_credential_metadata(credentials)
|
|
42
|
+
where credential_metadata is distinct from public.connection_credential_metadata(credentials)`.execute(
|
|
43
|
+
kysely
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function down(kysely: Kysely<unknown>) {
|
|
48
|
+
await sql`drop trigger if exists mirror_connection_credential_metadata on public.connection`.execute(
|
|
49
|
+
kysely
|
|
50
|
+
);
|
|
51
|
+
await sql`drop function if exists public.mirror_connection_credential_metadata()`.execute(
|
|
52
|
+
kysely
|
|
53
|
+
);
|
|
54
|
+
await sql`drop function if exists public.connection_credential_metadata(jsonb)`.execute(
|
|
55
|
+
kysely
|
|
56
|
+
);
|
|
57
|
+
await sql`alter table public.connection drop column if exists credential_metadata`.execute(
|
|
58
|
+
kysely
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(kysely: Kysely<unknown>) {
|
|
4
|
+
await sql`set local lock_timeout = '5s'`.execute(kysely);
|
|
5
|
+
await sql`alter table public.connection add column if not exists credential_version bigint not null default 0`.execute(
|
|
6
|
+
kysely
|
|
7
|
+
);
|
|
8
|
+
await sql`create or replace function public.advance_connection_credential_version()
|
|
9
|
+
returns trigger language plpgsql as $function$
|
|
10
|
+
begin
|
|
11
|
+
new.credential_version := old.credential_version + 1;
|
|
12
|
+
return new;
|
|
13
|
+
end;
|
|
14
|
+
$function$`.execute(kysely);
|
|
15
|
+
await sql`drop trigger if exists advance_connection_credential_version on public.connection`.execute(
|
|
16
|
+
kysely
|
|
17
|
+
);
|
|
18
|
+
await sql`create trigger advance_connection_credential_version before update of credentials on public.connection
|
|
19
|
+
for each row execute function public.advance_connection_credential_version()`.execute(
|
|
20
|
+
kysely
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function down(kysely: Kysely<unknown>) {
|
|
25
|
+
await sql`drop trigger if exists advance_connection_credential_version on public.connection`.execute(
|
|
26
|
+
kysely
|
|
27
|
+
);
|
|
28
|
+
await sql`drop function if exists public.advance_connection_credential_version()`.execute(
|
|
29
|
+
kysely
|
|
30
|
+
);
|
|
31
|
+
await sql`alter table public.connection drop column if exists credential_version`.execute(
|
|
32
|
+
kysely
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// Expand only: deliveries can target an owner contact instead of a portal user,
|
|
5
|
+
// skipped owners get a terminal record, and contacts can opt out of statement
|
|
6
|
+
// emails. Every existing writer keeps setting user_id, which the new checks
|
|
7
|
+
// accept. The checks avoid the new enum values, which PostgreSQL forbids in
|
|
8
|
+
// the transaction that adds them.
|
|
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
|
+
await sql`
|
|
14
|
+
alter type core.email_delivery_status add value if not exists 'skipped'
|
|
15
|
+
`.execute(db);
|
|
16
|
+
await sql`
|
|
17
|
+
alter type core.email_delivery_failure_code
|
|
18
|
+
add value if not exists 'missing_email'
|
|
19
|
+
`.execute(db);
|
|
20
|
+
await sql`
|
|
21
|
+
alter type core.email_delivery_failure_code
|
|
22
|
+
add value if not exists 'unsubscribed'
|
|
23
|
+
`.execute(db);
|
|
24
|
+
|
|
25
|
+
await sql`
|
|
26
|
+
alter table core.email_delivery
|
|
27
|
+
alter column user_id drop not null,
|
|
28
|
+
add column if not exists contact_id uuid,
|
|
29
|
+
add column if not exists recipient_email text,
|
|
30
|
+
add constraint email_delivery_recipient_check check (
|
|
31
|
+
num_nonnulls(user_id, contact_id) = 1
|
|
32
|
+
),
|
|
33
|
+
drop constraint email_delivery_terminal_check,
|
|
34
|
+
add constraint email_delivery_terminal_check check (
|
|
35
|
+
(status in ('queued', 'sending', 'retrying')) = (finished_at is null)
|
|
36
|
+
),
|
|
37
|
+
drop constraint email_delivery_failure_check,
|
|
38
|
+
add constraint email_delivery_failure_check check (
|
|
39
|
+
status in ('queued', 'sending', 'retrying', 'accepted', 'canceled')
|
|
40
|
+
or failure_code is not null
|
|
41
|
+
)
|
|
42
|
+
`.execute(db);
|
|
43
|
+
await sql`
|
|
44
|
+
create unique index if not exists email_delivery_notification_contact_key
|
|
45
|
+
on core.email_delivery (notification_id, contact_id)
|
|
46
|
+
where contact_id is not null
|
|
47
|
+
`.execute(db);
|
|
48
|
+
|
|
49
|
+
await sql`
|
|
50
|
+
alter table accounting.contact
|
|
51
|
+
add column if not exists statement_email_unsubscribed_at timestamptz
|
|
52
|
+
`.execute(db);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Enum additions are retained so historical deliveries remain readable.
|
|
56
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
57
|
+
await sql`
|
|
58
|
+
alter table accounting.contact
|
|
59
|
+
drop column if exists statement_email_unsubscribed_at
|
|
60
|
+
`.execute(db);
|
|
61
|
+
await sql`
|
|
62
|
+
drop index if exists core.email_delivery_notification_contact_key
|
|
63
|
+
`.execute(db);
|
|
64
|
+
await sql`
|
|
65
|
+
delete from core.email_delivery where user_id is null
|
|
66
|
+
`.execute(db);
|
|
67
|
+
await sql`
|
|
68
|
+
alter table core.email_delivery
|
|
69
|
+
drop constraint email_delivery_failure_check,
|
|
70
|
+
add constraint email_delivery_failure_check check (
|
|
71
|
+
status not in ('rejected', 'failed') or failure_code is not null
|
|
72
|
+
),
|
|
73
|
+
drop constraint email_delivery_terminal_check,
|
|
74
|
+
add constraint email_delivery_terminal_check check (
|
|
75
|
+
(status in ('accepted', 'rejected', 'failed', 'canceled')
|
|
76
|
+
and finished_at is not null)
|
|
77
|
+
or (status in ('queued', 'sending', 'retrying') and finished_at is null)
|
|
78
|
+
),
|
|
79
|
+
drop constraint email_delivery_recipient_check,
|
|
80
|
+
drop column if exists recipient_email,
|
|
81
|
+
drop column if exists contact_id,
|
|
82
|
+
alter column user_id set not null
|
|
83
|
+
`.execute(db);
|
|
84
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
create function accounting.require_payment_writer() returns trigger
|
|
9
|
+
language plpgsql as $$
|
|
10
|
+
declare
|
|
11
|
+
target record;
|
|
12
|
+
has_payments boolean;
|
|
13
|
+
begin
|
|
14
|
+
if current_setting('accounting.payment_writer_version', true) = '1'
|
|
15
|
+
or to_regclass('accounting.payment') is null then
|
|
16
|
+
if tg_op = 'DELETE' then return old; else return new; end if;
|
|
17
|
+
end if;
|
|
18
|
+
for target in
|
|
19
|
+
select distinct (value ->> 'tenant_id')::uuid as tenant_id,
|
|
20
|
+
(case when tg_table_name = 'transaction' then value ->> 'id'
|
|
21
|
+
else value ->> 'transaction_id' end)::uuid as transaction_id
|
|
22
|
+
from jsonb_array_elements(jsonb_build_array(to_jsonb(old), to_jsonb(new)))
|
|
23
|
+
where value is not null and value <> 'null'::jsonb
|
|
24
|
+
order by tenant_id, transaction_id
|
|
25
|
+
loop
|
|
26
|
+
if target.transaction_id is null then continue; end if;
|
|
27
|
+
-- Payment creation locks this same row before inserting its evidence.
|
|
28
|
+
perform id from accounting.transaction
|
|
29
|
+
where id = target.transaction_id and tenant_id = target.tenant_id for update;
|
|
30
|
+
execute 'select exists (select 1 from accounting.payment
|
|
31
|
+
where tenant_id = $1 and transaction_id = $2)'
|
|
32
|
+
into has_payments using target.tenant_id, target.transaction_id;
|
|
33
|
+
if has_payments then
|
|
34
|
+
raise exception using errcode = '23514', constraint = 'payment_writer_compatibility',
|
|
35
|
+
message = 'This transaction requires a deployment with payments support',
|
|
36
|
+
detail = jsonb_build_object('tenantId', target.tenant_id,
|
|
37
|
+
'transactionId', target.transaction_id)::text;
|
|
38
|
+
end if;
|
|
39
|
+
end loop;
|
|
40
|
+
if tg_op = 'DELETE' then return old; else return new; end if;
|
|
41
|
+
end $$
|
|
42
|
+
`.execute(db);
|
|
43
|
+
for (const table of [
|
|
44
|
+
'transaction',
|
|
45
|
+
'transaction_line',
|
|
46
|
+
'journal_entry',
|
|
47
|
+
'bank_record_transaction_payment',
|
|
48
|
+
]) {
|
|
49
|
+
await sql`
|
|
50
|
+
create trigger payment_writer_compatibility before insert or update or delete
|
|
51
|
+
on ${sql.table(`accounting.${table}`)}
|
|
52
|
+
for each row execute function accounting.require_payment_writer()
|
|
53
|
+
`.execute(db);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
58
|
+
for (const table of [
|
|
59
|
+
'transaction',
|
|
60
|
+
'transaction_line',
|
|
61
|
+
'journal_entry',
|
|
62
|
+
'bank_record_transaction_payment',
|
|
63
|
+
]) {
|
|
64
|
+
await sql`drop trigger payment_writer_compatibility on ${sql.table(`accounting.${table}`)}`.execute(
|
|
65
|
+
db
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
await sql`drop function accounting.require_payment_writer()`.execute(db);
|
|
69
|
+
}
|