@vrplatform/kysely 1.3.45-437 → 1.3.45-44075979560
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 +62 -1
- package/build/main/control-plane/index.js +10 -0
- package/build/main/control-plane/index.js.map +1 -1
- package/build/main/error.d.ts +2 -2
- package/build/main/error.js.map +1 -1
- package/build/main/index.d.ts +50 -4
- package/build/main/index.js +389 -63
- 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/digest.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/local/prune-pulled-schema.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/migration.d.ts +5 -5
- 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/pganalyze-comment-plugin/index.js.map +1 -1
- package/build/main/plugins.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.d.ts +2 -2
- package/build/main/query/listing/status.js +6 -2
- package/build/main/query/listing/status.js.map +1 -1
- package/build/main/query/tenant/billing-partner.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 +2 -1
- 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/transaction.js.map +1 -1
- package/build/main/v1.generated.d.ts +596 -70
- 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/0000000000116-guest-review.ts +45 -0
- package/build/migrations-v2/0000000000117-ramp-external-funding-accounts.ts +91 -0
- package/build/migrations-v2/0000000000118-pm-payout-assignment.ts +25 -0
- package/build/migrations-v2/0000000000119-chart-of-accounts-classifications.ts +46 -0
- package/build/migrations-v2/0000000000120-feedback.ts +41 -0
- package/build/migrations-v2/0000000000121-source-owner-block-calendar-index.ts +43 -0
- package/build/migrations-v2/0000000000122-recurring-fee-stay-types-filter.ts +20 -0
- package/build/migrations-v2/0000000000123-reservation-owner-stay-type-index.ts +40 -0
- package/build/migrations-v2/0000000000124-remove-tenant-test-and-billable-columns.ts +63 -0
- package/build/migrations-v2/0000000000125-ramp-application.ts +56 -0
- package/build/migrations-v2/0000000000126-advanced-deposits-update-operation.ts +10 -0
- package/build/migrations-v2/0000000000127-contact-1099-tax-details.ts +46 -0
- package/build/migrations-v2/0000000000128-tax-1099-email-templates.ts +36 -0
- package/build/migrations-v2/0000000000129-tenant-locked-at.ts +18 -0
- package/build/migrations-v2/0000000000130-second-factor-reset.ts +65 -0
- package/build/migrations-v2/0000000000131-payout-hold.ts +49 -0
- package/build/migrations-v2/0000000000132-member-invite-approval.ts +62 -0
- package/build/migrations-v2/0000000000133-audit-action-client-ip.ts +38 -0
- package/build/migrations-v2/0000000000134-drop-orphaned-hasura-triggers.ts +39 -0
- package/build/migrations-v2/0000000000135-drop-orphaned-hasura-triggers-literal.ts +42 -0
- package/build/migrations-v2/0000000000136-drop-all-hasura-triggers.ts +43 -0
- package/build/migrations-v2/0000000000137-webhook-event.ts +57 -0
- package/build/migrations-v2/0000000000138-contact-tax-details-requested-at.ts +24 -0
- package/build/migrations-v2/0000000000139-tax-statement-1099.ts +140 -0
- package/build/migrations-v2/0000000000140-owner-payment-settings.ts +53 -0
- package/build/migrations-v2/0000000000141-owner-payment-requests.ts +100 -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 +62 -1
- package/build/module/control-plane/index.js +9 -0
- package/build/module/control-plane/index.js.map +1 -1
- package/build/module/error.d.ts +2 -2
- package/build/module/error.js.map +1 -1
- package/build/module/index.d.ts +50 -4
- package/build/module/index.js +387 -63
- 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/local/prune-pulled-schema.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/migration.d.ts +5 -5
- 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.d.ts +2 -2
- 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 +2 -1
- 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 +596 -70
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +10 -8
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
// These lookup indexes scan existing multi-million-row tables.
|
|
7
|
+
await sql`set local statement_timeout = '10min'`.execute(db);
|
|
8
|
+
|
|
9
|
+
await sql`
|
|
10
|
+
create index if not exists reservation_journal_invalidation_covered_effect_idx
|
|
11
|
+
on accounting.reservation_journal_invalidation (covered_by_effect_id)
|
|
12
|
+
where covered_by_effect_id is not null
|
|
13
|
+
`.execute(db);
|
|
14
|
+
await sql`
|
|
15
|
+
create index if not exists reservation_journal_statement_impact_listing_idx
|
|
16
|
+
on accounting.reservation_journal_statement_impact (listing_id)
|
|
17
|
+
`.execute(db);
|
|
18
|
+
// The stale-only index cannot cover foreign-key checks for every tenant row.
|
|
19
|
+
await sql`
|
|
20
|
+
create index if not exists reservation_journal_state_tenant_idx
|
|
21
|
+
on accounting.reservation_journal_state (tenant_id)
|
|
22
|
+
`.execute(db);
|
|
23
|
+
await sql`
|
|
24
|
+
create index if not exists owner_statement_previous_idx
|
|
25
|
+
on public.owner_statement (previous_owner_statement_id)
|
|
26
|
+
where previous_owner_statement_id is not null
|
|
27
|
+
`.execute(db);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
31
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
32
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
33
|
+
|
|
34
|
+
await sql`
|
|
35
|
+
drop index if exists public.owner_statement_previous_idx
|
|
36
|
+
`.execute(db);
|
|
37
|
+
await sql`
|
|
38
|
+
drop index if exists accounting.reservation_journal_state_tenant_idx
|
|
39
|
+
`.execute(db);
|
|
40
|
+
await sql`
|
|
41
|
+
drop index if exists accounting.reservation_journal_statement_impact_listing_idx
|
|
42
|
+
`.execute(db);
|
|
43
|
+
await sql`
|
|
44
|
+
drop index if exists accounting.reservation_journal_invalidation_covered_effect_idx
|
|
45
|
+
`.execute(db);
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
update public.tenant set is_onboarding = false where is_onboarding is null
|
|
8
|
+
`.execute(db);
|
|
9
|
+
// Finish deferred tenant guards before altering the table they still reference.
|
|
10
|
+
await sql`set constraints all immediate`.execute(db);
|
|
11
|
+
await sql`
|
|
12
|
+
alter table public.tenant
|
|
13
|
+
alter column is_onboarding set default false,
|
|
14
|
+
alter column is_onboarding set not null
|
|
15
|
+
`.execute(db);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
19
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
20
|
+
await sql`
|
|
21
|
+
alter table public.tenant alter column is_onboarding drop not null
|
|
22
|
+
`.execute(db);
|
|
23
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// Owner statement attach and detach only move the statement columns. They hold no
|
|
5
|
+
// payment evidence, so deployments without the payments writer may change them.
|
|
6
|
+
// txn_code is generated and still null in NEW inside a BEFORE trigger.
|
|
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
|
+
await sql`
|
|
11
|
+
create or replace function accounting.require_payment_writer() returns trigger
|
|
12
|
+
language plpgsql as $$
|
|
13
|
+
declare
|
|
14
|
+
target record;
|
|
15
|
+
has_payments boolean;
|
|
16
|
+
begin
|
|
17
|
+
if current_setting('accounting.payment_writer_version', true) = '1'
|
|
18
|
+
or to_regclass('accounting.payment') is null then
|
|
19
|
+
if tg_op = 'DELETE' then return old; else return new; end if;
|
|
20
|
+
end if;
|
|
21
|
+
if tg_op = 'UPDATE' and tg_table_name = 'journal_entry'
|
|
22
|
+
and to_jsonb(new) - array['attached_to_owner_statement_id', 'listing_ownership_period_id',
|
|
23
|
+
'updated_at', 'txn_code']
|
|
24
|
+
= to_jsonb(old) - array['attached_to_owner_statement_id', 'listing_ownership_period_id',
|
|
25
|
+
'updated_at', 'txn_code'] then
|
|
26
|
+
return new;
|
|
27
|
+
end if;
|
|
28
|
+
for target in
|
|
29
|
+
select distinct (value ->> 'tenant_id')::uuid as tenant_id,
|
|
30
|
+
(case when tg_table_name = 'transaction' then value ->> 'id'
|
|
31
|
+
else value ->> 'transaction_id' end)::uuid as transaction_id
|
|
32
|
+
from jsonb_array_elements(jsonb_build_array(to_jsonb(old), to_jsonb(new)))
|
|
33
|
+
where value is not null and value <> 'null'::jsonb
|
|
34
|
+
order by tenant_id, transaction_id
|
|
35
|
+
loop
|
|
36
|
+
if target.transaction_id is null then continue; end if;
|
|
37
|
+
-- Payment creation locks this same row before inserting its evidence.
|
|
38
|
+
perform id from accounting.transaction
|
|
39
|
+
where id = target.transaction_id and tenant_id = target.tenant_id for update;
|
|
40
|
+
execute 'select exists (select 1 from accounting.payment
|
|
41
|
+
where tenant_id = $1 and transaction_id = $2)'
|
|
42
|
+
into has_payments using target.tenant_id, target.transaction_id;
|
|
43
|
+
if has_payments then
|
|
44
|
+
raise exception using errcode = '23514', constraint = 'payment_writer_compatibility',
|
|
45
|
+
message = 'This transaction requires a deployment with payments support',
|
|
46
|
+
detail = jsonb_build_object('tenantId', target.tenant_id,
|
|
47
|
+
'transactionId', target.transaction_id)::text;
|
|
48
|
+
end if;
|
|
49
|
+
end loop;
|
|
50
|
+
if tg_op = 'DELETE' then return old; else return new; end if;
|
|
51
|
+
end $$
|
|
52
|
+
`.execute(db);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
56
|
+
await sql`
|
|
57
|
+
create or replace function accounting.require_payment_writer() returns trigger
|
|
58
|
+
language plpgsql as $$
|
|
59
|
+
declare
|
|
60
|
+
target record;
|
|
61
|
+
has_payments boolean;
|
|
62
|
+
begin
|
|
63
|
+
if current_setting('accounting.payment_writer_version', true) = '1'
|
|
64
|
+
or to_regclass('accounting.payment') is null then
|
|
65
|
+
if tg_op = 'DELETE' then return old; else return new; end if;
|
|
66
|
+
end if;
|
|
67
|
+
for target in
|
|
68
|
+
select distinct (value ->> 'tenant_id')::uuid as tenant_id,
|
|
69
|
+
(case when tg_table_name = 'transaction' then value ->> 'id'
|
|
70
|
+
else value ->> 'transaction_id' end)::uuid as transaction_id
|
|
71
|
+
from jsonb_array_elements(jsonb_build_array(to_jsonb(old), to_jsonb(new)))
|
|
72
|
+
where value is not null and value <> 'null'::jsonb
|
|
73
|
+
order by tenant_id, transaction_id
|
|
74
|
+
loop
|
|
75
|
+
if target.transaction_id is null then continue; end if;
|
|
76
|
+
-- Payment creation locks this same row before inserting its evidence.
|
|
77
|
+
perform id from accounting.transaction
|
|
78
|
+
where id = target.transaction_id and tenant_id = target.tenant_id for update;
|
|
79
|
+
execute 'select exists (select 1 from accounting.payment
|
|
80
|
+
where tenant_id = $1 and transaction_id = $2)'
|
|
81
|
+
into has_payments using target.tenant_id, target.transaction_id;
|
|
82
|
+
if has_payments then
|
|
83
|
+
raise exception using errcode = '23514', constraint = 'payment_writer_compatibility',
|
|
84
|
+
message = 'This transaction requires a deployment with payments support',
|
|
85
|
+
detail = jsonb_build_object('tenantId', target.tenant_id,
|
|
86
|
+
'transactionId', target.transaction_id)::text;
|
|
87
|
+
end if;
|
|
88
|
+
end loop;
|
|
89
|
+
if tg_op = 'DELETE' then return old; else return new; end if;
|
|
90
|
+
end $$
|
|
91
|
+
`.execute(db);
|
|
92
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
// These indexes scan existing multi-million-row tables.
|
|
7
|
+
await sql`set local statement_timeout = '10min'`.execute(db);
|
|
8
|
+
|
|
9
|
+
// recoverPublicAuditEvents (PRO-19064) looks for events projected with an
|
|
10
|
+
// older version. Without this index it probes every audit action since the
|
|
11
|
+
// cutover on each run.
|
|
12
|
+
await sql`
|
|
13
|
+
create index if not exists public_event_projection_version_idx
|
|
14
|
+
on audit.public_event (projection_version)
|
|
15
|
+
`.execute(db);
|
|
16
|
+
// The payment linker (PRO-18060) reads pending lines newest first, one
|
|
17
|
+
// keyset page at a time. match_status_tenant_id_idx cannot order them, so
|
|
18
|
+
// every page read all pending lines of the tenant.
|
|
19
|
+
await sql`
|
|
20
|
+
create index if not exists payment_line_pending_tenant_created_idx
|
|
21
|
+
on public.payment_line (tenant_id, created_at desc, id desc)
|
|
22
|
+
where match_status = 'pending'
|
|
23
|
+
`.execute(db);
|
|
24
|
+
await sql`
|
|
25
|
+
create index if not exists transaction_line_pending_tenant_created_idx
|
|
26
|
+
on accounting.transaction_line (tenant_id, created_at desc, id desc)
|
|
27
|
+
where match_status = 'pending'
|
|
28
|
+
`.execute(db);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
32
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
33
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
34
|
+
|
|
35
|
+
await sql`
|
|
36
|
+
drop index if exists accounting.transaction_line_pending_tenant_created_idx
|
|
37
|
+
`.execute(db);
|
|
38
|
+
await sql`
|
|
39
|
+
drop index if exists public.payment_line_pending_tenant_created_idx
|
|
40
|
+
`.execute(db);
|
|
41
|
+
await sql`
|
|
42
|
+
drop index if exists audit.public_event_projection_version_idx
|
|
43
|
+
`.execute(db);
|
|
44
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 = '10min'`.execute(db);
|
|
7
|
+
|
|
8
|
+
// With 100 most-common values, the planner assumed an emptied tenant still
|
|
9
|
+
// owned about 545000 core.change rows, chose a skip scan over
|
|
10
|
+
// (sync_id, tenant_id) for the foreign-key check, and timed out deleting the
|
|
11
|
+
// tenant row (PRO-18138). A running vacuum holds the lock this needs; apply
|
|
12
|
+
// it when the table is idle.
|
|
13
|
+
await sql`
|
|
14
|
+
alter table core.change alter column tenant_id set statistics 1000
|
|
15
|
+
`.execute(db);
|
|
16
|
+
await sql`analyze core.change (tenant_id)`.execute(db);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
20
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
21
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
22
|
+
|
|
23
|
+
await sql`
|
|
24
|
+
alter table core.change alter column tenant_id set statistics -1
|
|
25
|
+
`.execute(db);
|
|
26
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// Product events live in Control Plane public.events. The legacy regional sink
|
|
5
|
+
// received its last write on 2026-08-18 and was reconciled by PRO-16951.
|
|
6
|
+
// Hasura never delivered the tracking_event trigger rows, so they are dropped
|
|
7
|
+
// with the table and are not restored by down.
|
|
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 = '240s'`.execute(db);
|
|
11
|
+
await sql`drop table if exists tracking.event`.execute(db);
|
|
12
|
+
await sql`
|
|
13
|
+
drop function if exists hdb_catalog."notify_hasura_tracking_event_INSERT"()
|
|
14
|
+
`.execute(db);
|
|
15
|
+
await sql`
|
|
16
|
+
drop function if exists hdb_catalog."notify_hasura_tracking_event_UPDATE"()
|
|
17
|
+
`.execute(db);
|
|
18
|
+
await sql`
|
|
19
|
+
delete from hdb_catalog.event_invocation_logs
|
|
20
|
+
where trigger_name = 'tracking_event'
|
|
21
|
+
`.execute(db);
|
|
22
|
+
await sql`
|
|
23
|
+
delete from hdb_catalog.event_log
|
|
24
|
+
where trigger_name = 'tracking_event'
|
|
25
|
+
and schema_name = 'tracking'
|
|
26
|
+
and table_name = 'event'
|
|
27
|
+
`.execute(db);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
31
|
+
await sql`
|
|
32
|
+
create table if not exists tracking.event (
|
|
33
|
+
id uuid default gen_random_uuid() not null primary key,
|
|
34
|
+
tenant_id uuid,
|
|
35
|
+
user_id uuid,
|
|
36
|
+
created_at timestamp with time zone default now() not null,
|
|
37
|
+
name text not null,
|
|
38
|
+
props jsonb not null,
|
|
39
|
+
package_name text not null,
|
|
40
|
+
tracked_at timestamp with time zone default now(),
|
|
41
|
+
"timestamp" timestamp without time zone
|
|
42
|
+
generated always as (coalesce(tracked_at, created_at)) stored
|
|
43
|
+
)
|
|
44
|
+
`.execute(db);
|
|
45
|
+
await sql`
|
|
46
|
+
create index if not exists event_name_created_at_idx
|
|
47
|
+
on tracking.event (name, created_at)
|
|
48
|
+
`.execute(db);
|
|
49
|
+
await sql`
|
|
50
|
+
create index if not exists event_name_tracked_at_idx
|
|
51
|
+
on tracking.event (name, tracked_at)
|
|
52
|
+
`.execute(db);
|
|
53
|
+
await sql`
|
|
54
|
+
create index if not exists event_tenant_id_name_idx
|
|
55
|
+
on tracking.event (tenant_id, name)
|
|
56
|
+
`.execute(db);
|
|
57
|
+
await sql`
|
|
58
|
+
create index if not exists event_user_id on tracking.event (user_id)
|
|
59
|
+
`.execute(db);
|
|
60
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
const original = `effect.effect_type = 'REFRESH_RESERVATION_JOURNAL'
|
|
4
|
+
and effect.entity_type = 'reservation'`;
|
|
5
|
+
const corrected = `effect.effect_type in (
|
|
6
|
+
'REFRESH_RESERVATION_JOURNAL',
|
|
7
|
+
'REFRESH_RECURRING_FEE_RESERVATIONS'
|
|
8
|
+
)
|
|
9
|
+
and effect.entity_type in ('reservation', 'recurringFee')`;
|
|
10
|
+
|
|
11
|
+
async function replaceProjectedEffects<Database>(
|
|
12
|
+
db: Kysely<Database>,
|
|
13
|
+
before: string,
|
|
14
|
+
after: string
|
|
15
|
+
) {
|
|
16
|
+
const { rows } = await sql<{ definition: string }>`
|
|
17
|
+
select pg_get_functiondef('core.refresh_audit_action_source(uuid)'::regprocedure)
|
|
18
|
+
as definition
|
|
19
|
+
`.execute(db);
|
|
20
|
+
const definition = rows[0]?.definition;
|
|
21
|
+
if (!definition || definition.split(before).length !== 2) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
'Journal operation source projection has an unexpected definition'
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
await sql.raw(definition.replace(before, after)).execute(db);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function up<Database>(db: Kysely<Database>): Promise<void> {
|
|
30
|
+
await replaceProjectedEffects(db, original, corrected);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function down<Database>(db: Kysely<Database>): Promise<void> {
|
|
34
|
+
await replaceProjectedEffects(db, corrected, original);
|
|
35
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// GET /reservations searches these five columns with ILIKE '%term%'. Without
|
|
5
|
+
// trigram indexes the total count reads every reservation of the team. On
|
|
6
|
+
// large databases run scripts/ben-2/pro-19034-create-search-indexes.ts
|
|
7
|
+
// first: it builds them concurrently, and this migration then skips them.
|
|
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 = '30min'`.execute(db);
|
|
11
|
+
|
|
12
|
+
await sql`create extension if not exists pg_trgm`.execute(db);
|
|
13
|
+
await sql`
|
|
14
|
+
create index if not exists reservation_guest_name_trgm_idx
|
|
15
|
+
on public.reservation using gin (guest_name gin_trgm_ops)
|
|
16
|
+
`.execute(db);
|
|
17
|
+
await sql`
|
|
18
|
+
create index if not exists reservation_unique_ref_trgm_idx
|
|
19
|
+
on public.reservation using gin (unique_ref gin_trgm_ops)
|
|
20
|
+
`.execute(db);
|
|
21
|
+
await sql`
|
|
22
|
+
create index if not exists reservation_short_ref_trgm_idx
|
|
23
|
+
on public.reservation using gin (short_ref gin_trgm_ops)
|
|
24
|
+
`.execute(db);
|
|
25
|
+
await sql`
|
|
26
|
+
create index if not exists reservation_confirmation_code_trgm_idx
|
|
27
|
+
on public.reservation using gin (confirmation_code gin_trgm_ops)
|
|
28
|
+
`.execute(db);
|
|
29
|
+
await sql`
|
|
30
|
+
create index if not exists reservation_pms_reference_code_trgm_idx
|
|
31
|
+
on public.reservation using gin (pms_reference_code gin_trgm_ops)
|
|
32
|
+
`.execute(db);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
36
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
37
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
38
|
+
|
|
39
|
+
await sql`drop index if exists public.reservation_guest_name_trgm_idx`.execute(
|
|
40
|
+
db
|
|
41
|
+
);
|
|
42
|
+
await sql`drop index if exists public.reservation_unique_ref_trgm_idx`.execute(
|
|
43
|
+
db
|
|
44
|
+
);
|
|
45
|
+
await sql`drop index if exists public.reservation_short_ref_trgm_idx`.execute(
|
|
46
|
+
db
|
|
47
|
+
);
|
|
48
|
+
await sql`
|
|
49
|
+
drop index if exists public.reservation_confirmation_code_trgm_idx
|
|
50
|
+
`.execute(db);
|
|
51
|
+
await sql`
|
|
52
|
+
drop index if exists public.reservation_pms_reference_code_trgm_idx
|
|
53
|
+
`.execute(db);
|
|
54
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// The reservation payment correction (GET /reservations paidStatus filter and
|
|
5
|
+
// its total count) looks up each reservation's deposit journal entries. The
|
|
6
|
+
// existing (reservation_id, tenant_id) index returns every journal entry of the
|
|
7
|
+
// reservation and filters the three deposit predicates after the heap fetch.
|
|
8
|
+
// This partial index holds only those rows. On large databases run
|
|
9
|
+
// scripts/ben-2/pro-18866-create-deposit-index.ts first: it builds the index
|
|
10
|
+
// concurrently, and this migration then skips it.
|
|
11
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
12
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
13
|
+
await sql`set local statement_timeout = '30min'`.execute(db);
|
|
14
|
+
|
|
15
|
+
await sql`
|
|
16
|
+
create index if not exists journal_entry_reservation_deposit_idx
|
|
17
|
+
on accounting.journal_entry (reservation_id, tenant_id)
|
|
18
|
+
where entity_type = 'transaction'
|
|
19
|
+
and unique_ref like 'deposit%'
|
|
20
|
+
and type <> 'transaction_deposit'
|
|
21
|
+
`.execute(db);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
25
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
26
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
27
|
+
|
|
28
|
+
await sql`
|
|
29
|
+
drop index if exists accounting.journal_entry_reservation_deposit_idx
|
|
30
|
+
`.execute(db);
|
|
31
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19314: the manager dashboard reads active reservation journal entries by
|
|
5
|
+
// posting date (revenue, take rate, booked revenue) and per reservation (ADR,
|
|
6
|
+
// posted-stay checks). On the largest team that is about 1.9M entries a year,
|
|
7
|
+
// and a heap fetch per entry took 21-39 s. Both partial indexes cover every
|
|
8
|
+
// column those queries read, so they can run as index-only scans. On large
|
|
9
|
+
// databases run scripts/ben-2/pro-19314-create-revenue-indexes.ts first: it
|
|
10
|
+
// builds the indexes concurrently, and this migration then skips them. The
|
|
11
|
+
// migrator runs in a transaction, so this build cannot be concurrent: the short
|
|
12
|
+
// statement timeout fails it before it blocks journal writes for long.
|
|
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
|
+
// A failed concurrent build leaves an invalid index that `if not exists`
|
|
17
|
+
// would keep, so drop it first.
|
|
18
|
+
const invalid = await sql<{ name: string }>`
|
|
19
|
+
select index_class.relname as name
|
|
20
|
+
from pg_index as i
|
|
21
|
+
inner join pg_class as index_class on index_class.oid = i.indexrelid
|
|
22
|
+
where i.indrelid = 'accounting.journal_entry'::regclass
|
|
23
|
+
and index_class.relname in (
|
|
24
|
+
'journal_entry_reservation_revenue_txn_at_idx',
|
|
25
|
+
'journal_entry_reservation_revenue_reservation_idx'
|
|
26
|
+
)
|
|
27
|
+
and not (i.indisvalid and i.indisready)
|
|
28
|
+
`.execute(db);
|
|
29
|
+
for (const { name } of invalid.rows) {
|
|
30
|
+
await sql`drop index accounting.${sql.id(name)}`.execute(db);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
await sql`
|
|
34
|
+
create index if not exists journal_entry_reservation_revenue_txn_at_idx
|
|
35
|
+
on accounting.journal_entry (tenant_id, txn_at)
|
|
36
|
+
include (reservation_id, account_id, type, party, cent_total)
|
|
37
|
+
where entity_type = 'reservation' and status = 'active'
|
|
38
|
+
`.execute(db);
|
|
39
|
+
await sql`
|
|
40
|
+
create index if not exists journal_entry_reservation_revenue_reservation_idx
|
|
41
|
+
on accounting.journal_entry (reservation_id, tenant_id)
|
|
42
|
+
include (account_id, type, party, cent_total, txn_at)
|
|
43
|
+
where entity_type = 'reservation' and status = 'active'
|
|
44
|
+
`.execute(db);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
48
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
49
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
50
|
+
|
|
51
|
+
await sql`
|
|
52
|
+
drop index if exists accounting.journal_entry_reservation_revenue_txn_at_idx
|
|
53
|
+
`.execute(db);
|
|
54
|
+
await sql`
|
|
55
|
+
drop index if exists accounting.journal_entry_reservation_revenue_reservation_idx
|
|
56
|
+
`.execute(db);
|
|
57
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19365: owners who open statements by emailed link get their own
|
|
5
|
+
// editable owner statement email, separate from the portal user email.
|
|
6
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
7
|
+
await sql`
|
|
8
|
+
insert into public.email_template_type (name)
|
|
9
|
+
values ('ownerStatementLink_owner')
|
|
10
|
+
on conflict do nothing
|
|
11
|
+
`.execute(db);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
15
|
+
await sql`
|
|
16
|
+
delete from public.email_template
|
|
17
|
+
where type = 'ownerStatementLink_owner'
|
|
18
|
+
`.execute(db);
|
|
19
|
+
await sql`
|
|
20
|
+
delete from public.email_template_type
|
|
21
|
+
where name = 'ownerStatementLink_owner'
|
|
22
|
+
`.execute(db);
|
|
23
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// Expand only: VRT becomes the source of truth for owner and vendor payment
|
|
5
|
+
// setup. Full bank numbers live in their own table so contact reads, copies
|
|
6
|
+
// and exports never select them. address_edited_at marks a mailing address
|
|
7
|
+
// edited in VRT so PMS sync stops overwriting it.
|
|
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.contact_payment_method as enum (
|
|
14
|
+
'rampAch', 'nachaAch', 'check', 'outside'
|
|
15
|
+
)
|
|
16
|
+
`.execute(db);
|
|
17
|
+
await sql`
|
|
18
|
+
create type accounting.bank_account_holder_type as enum ('individual', 'business')
|
|
19
|
+
`.execute(db);
|
|
20
|
+
await sql`
|
|
21
|
+
create type accounting.bank_account_kind as enum ('checking', 'savings')
|
|
22
|
+
`.execute(db);
|
|
23
|
+
|
|
24
|
+
await sql`
|
|
25
|
+
alter table accounting.contact
|
|
26
|
+
add column if not exists default_payment_method accounting.contact_payment_method,
|
|
27
|
+
add column if not exists address_edited_at timestamptz
|
|
28
|
+
`.execute(db);
|
|
29
|
+
|
|
30
|
+
await sql`
|
|
31
|
+
create table accounting.contact_bank_account (
|
|
32
|
+
contact_id uuid primary key references accounting.contact (id) on delete cascade,
|
|
33
|
+
tenant_id uuid not null references public.tenant (id) on delete restrict,
|
|
34
|
+
holder_name text not null check (length(holder_name) between 1 and 200),
|
|
35
|
+
holder_type accounting.bank_account_holder_type not null,
|
|
36
|
+
account_kind accounting.bank_account_kind not null,
|
|
37
|
+
routing_number text not null check (routing_number ~ '^[0-9]{9}$'),
|
|
38
|
+
account_number text not null check (account_number ~ '^[0-9]{4,17}$'),
|
|
39
|
+
updated_by_user_id uuid null references public.user (id) on delete set null,
|
|
40
|
+
created_at timestamptz not null default now(),
|
|
41
|
+
updated_at timestamptz not null default now()
|
|
42
|
+
)
|
|
43
|
+
`.execute(db);
|
|
44
|
+
await sql`
|
|
45
|
+
create index contact_bank_account_tenant_id_idx
|
|
46
|
+
on accounting.contact_bank_account (tenant_id)
|
|
47
|
+
`.execute(db);
|
|
48
|
+
await sql`
|
|
49
|
+
do $$
|
|
50
|
+
begin
|
|
51
|
+
if exists (select 1 from pg_roles where rolname = 'application') then
|
|
52
|
+
grant select, insert, update, delete on accounting.contact_bank_account
|
|
53
|
+
to application;
|
|
54
|
+
end if;
|
|
55
|
+
end;
|
|
56
|
+
$$
|
|
57
|
+
`.execute(db);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
61
|
+
await sql`drop table if exists accounting.contact_bank_account`.execute(db);
|
|
62
|
+
await sql`
|
|
63
|
+
alter table accounting.contact
|
|
64
|
+
drop column if exists address_edited_at,
|
|
65
|
+
drop column if exists default_payment_method
|
|
66
|
+
`.execute(db);
|
|
67
|
+
await sql`drop type if exists accounting.bank_account_kind`.execute(db);
|
|
68
|
+
await sql`drop type if exists accounting.bank_account_holder_type`.execute(
|
|
69
|
+
db
|
|
70
|
+
);
|
|
71
|
+
await sql`drop type if exists accounting.contact_payment_method`.execute(db);
|
|
72
|
+
}
|
|
@@ -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`set local statement_timeout = '10min'`.execute(db);
|
|
7
|
+
// Each address delete probes these referencing columns, including global users.
|
|
8
|
+
await sql`
|
|
9
|
+
create index if not exists user_address_id_idx on public."user" (address_id)
|
|
10
|
+
where address_id is not null
|
|
11
|
+
`.execute(db);
|
|
12
|
+
await sql`
|
|
13
|
+
create index if not exists owner_address_id_idx on public.owner (address_id)
|
|
14
|
+
where address_id is not null
|
|
15
|
+
`.execute(db);
|
|
16
|
+
await sql`
|
|
17
|
+
create index if not exists tenant_billing_address_id_idx on public.tenant (billing_address_id)
|
|
18
|
+
where billing_address_id is not null
|
|
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`drop index if exists public.tenant_billing_address_id_idx`.execute(
|
|
26
|
+
db
|
|
27
|
+
);
|
|
28
|
+
await sql`drop index if exists public.owner_address_id_idx`.execute(db);
|
|
29
|
+
await sql`drop index if exists public.user_address_id_idx`.execute(db);
|
|
30
|
+
}
|