@vrplatform/kysely 1.3.41-stage.4319 → 1.3.45-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/.data.tar +0 -0
- package/build/main/camel-case/index.js +1 -1
- package/build/main/camel-case/index.js.map +1 -1
- package/build/main/control-plane/index.d.ts +240 -14
- package/build/main/control-plane/index.js +61 -0
- package/build/main/control-plane/index.js.map +1 -1
- package/build/main/domain.d.ts +4 -0
- package/build/main/domain.js +3 -0
- package/build/main/domain.js.map +1 -0
- package/build/main/error.d.ts +2 -1
- package/build/main/error.js +2 -1
- package/build/main/error.js.map +1 -1
- package/build/main/index.d.ts +10 -15
- package/build/main/index.js +140 -58
- package/build/main/index.js.map +1 -1
- package/build/main/isomorphic.d.ts +5 -5
- package/build/main/isomorphic.js +2 -8
- package/build/main/isomorphic.js.map +1 -1
- package/build/main/local/digest.d.ts +3 -3
- package/build/main/local/digest.js.map +1 -1
- package/build/main/local/generate.js +10 -10
- package/build/main/local/generate.js.map +1 -1
- package/build/main/local/index.d.ts +5 -1
- package/build/main/local/index.js +215 -6
- package/build/main/local/index.js.map +1 -1
- package/build/main/local/prune-pulled-schema.js +4 -1
- package/build/main/local/prune-pulled-schema.js.map +1 -1
- package/build/main/migration.d.ts +7 -0
- package/build/main/migration.js +11 -0
- package/build/main/migration.js.map +1 -0
- package/build/main/plugins.d.ts +2 -2
- package/build/main/plugins.js.map +1 -1
- package/build/main/postgres-error.d.ts +8 -0
- package/build/main/postgres-error.js +21 -0
- package/build/main/postgres-error.js.map +1 -0
- package/build/main/query/index.d.ts +1 -0
- package/build/main/query/index.js +1 -0
- package/build/main/query/index.js.map +1 -1
- package/build/main/query/listing/status.d.ts +0 -10
- package/build/main/query/listing/status.js +29 -18
- package/build/main/query/listing/status.js.map +1 -1
- package/build/main/query/tenant/billing-partner.d.ts +4 -0
- package/build/main/query/tenant/billing-partner.js +8 -0
- package/build/main/query/tenant/billing-partner.js.map +1 -0
- package/build/main/query/tenant/index.d.ts +2 -0
- package/build/main/query/tenant/index.js +19 -0
- package/build/main/query/tenant/index.js.map +1 -0
- package/build/main/query/tenant/status.d.ts +14 -0
- package/build/main/query/tenant/status.js +40 -0
- package/build/main/query/tenant/status.js.map +1 -0
- package/build/main/regional.d.ts +29 -3
- package/build/main/regional.js +68 -8
- package/build/main/regional.js.map +1 -1
- package/build/main/test/index.d.ts +3 -14
- package/build/main/test/index.js +0 -23
- package/build/main/test/index.js.map +1 -1
- package/build/main/transaction.d.ts +3 -3
- package/build/main/transaction.js.map +1 -1
- package/build/main/v1.generated.d.ts +577 -24
- package/build/main/v1.generated.js.map +1 -1
- package/build/migrations-v2/0000000000000-baseline.ts +5 -0
- package/build/migrations-v2/0000000000001-public-audit-events-v2.ts +137 -0
- package/build/migrations-v2/0000000000002-audit-recovery-watermarks.ts +30 -0
- package/build/migrations-v2/0000000000003-audit-effect-recovery-watermark.ts +13 -0
- package/build/migrations-v2/0000000000004-audit-event-projected-at.ts +15 -0
- package/build/migrations-v2/0000000000005-audit-recovery-indexes.ts +63 -0
- package/build/migrations-v2/0000000000006-audit-action-public-event-projected-at.ts +22 -0
- package/build/migrations-v2/0000000000007-audit-action-public-event-projected-at-backfill.ts +35 -0
- package/build/migrations-v2/0000000000008-global-user-attribution.ts +33 -0
- package/build/migrations-v2/0000000000008-team-issue-rule-state.ts +52 -0
- package/build/migrations-v2/0000000000009-reservation-issue-projections.ts +45 -0
- package/build/migrations-v2/0000000000010-bank-rule-application-bank-record-delete-cascade.ts +26 -0
- package/build/migrations-v2/0000000000011-guest-balance-journal-entry-lookup-index.ts +25 -0
- package/build/migrations-v2/0000000000012-trial-free-analytics-billing-status.ts +72 -0
- package/build/migrations-v2/0000000000013-ui-permission-bundles.ts +45 -0
- package/build/migrations-v2/0000000000014-ui-permission-bundle-top-up.ts +32 -0
- package/build/migrations-v2/0000000000016-managed-team-access.ts +34 -0
- package/build/migrations-v2/0000000000017-drop-trial-until.ts +42 -0
- package/build/migrations-v2/0000000000018-accounting-integrity-monitoring.ts +276 -0
- package/build/migrations-v2/0000000000019-accounting-integrity-run-shards.ts +26 -0
- package/build/migrations-v2/0000000000020-accounting-integrity-case-classification.ts +52 -0
- package/build/migrations-v2/0000000000021-payment-line-classification-monitor-indexes.ts +31 -0
- package/build/migrations-v2/0000000000022-accounting-integrity-controlled-repairs.ts +281 -0
- package/build/migrations-v2/0000000000023-line-classification-usage.ts +325 -0
- package/build/migrations-v2/0000000000024-tenant-region-migration.ts +108 -0
- package/build/migrations-v2/0000000000025-partner-ach-denial-default.ts +30 -0
- package/build/migrations-v2/0000000000026-line-classification-usage-capture.ts +399 -0
- package/build/migrations-v2/0000000000027-payout-replacement-chain.ts +27 -0
- package/build/migrations-v2/0000000000028-accounting-integrity-operator-workflow.ts +108 -0
- package/build/migrations-v2/0000000000029-accounting-integrity-definition-artifacts.ts +40 -0
- package/build/migrations-v2/0000000000030-accounting-integrity-review-metadata-compatibility.ts +49 -0
- package/build/module/camel-case/index.js +1 -1
- package/build/module/camel-case/index.js.map +1 -1
- package/build/module/control-plane/index.d.ts +240 -14
- package/build/module/control-plane/index.js +49 -1
- package/build/module/control-plane/index.js.map +1 -1
- package/build/module/domain.d.ts +4 -0
- package/build/module/domain.js +2 -0
- package/build/module/domain.js.map +1 -0
- package/build/module/error.d.ts +2 -1
- package/build/module/error.js +3 -1
- package/build/module/error.js.map +1 -1
- package/build/module/index.d.ts +10 -15
- package/build/module/index.js +141 -56
- package/build/module/index.js.map +1 -1
- package/build/module/isomorphic.d.ts +5 -5
- package/build/module/isomorphic.js +1 -6
- package/build/module/isomorphic.js.map +1 -1
- package/build/module/local/digest.d.ts +3 -3
- package/build/module/local/digest.js.map +1 -1
- package/build/module/local/generate.js +10 -10
- package/build/module/local/generate.js.map +1 -1
- package/build/module/local/index.d.ts +5 -1
- package/build/module/local/index.js +216 -7
- package/build/module/local/index.js.map +1 -1
- package/build/module/local/prune-pulled-schema.js +4 -1
- package/build/module/local/prune-pulled-schema.js.map +1 -1
- package/build/module/migration.d.ts +7 -0
- package/build/module/migration.js +8 -0
- package/build/module/migration.js.map +1 -0
- package/build/module/plugins.d.ts +2 -2
- package/build/module/plugins.js.map +1 -1
- package/build/module/postgres-error.d.ts +8 -0
- package/build/module/postgres-error.js +18 -0
- package/build/module/postgres-error.js.map +1 -0
- package/build/module/query/index.d.ts +1 -0
- package/build/module/query/index.js +1 -0
- package/build/module/query/index.js.map +1 -1
- package/build/module/query/listing/status.d.ts +0 -10
- package/build/module/query/listing/status.js +29 -16
- package/build/module/query/listing/status.js.map +1 -1
- package/build/module/query/tenant/billing-partner.d.ts +4 -0
- package/build/module/query/tenant/billing-partner.js +5 -0
- package/build/module/query/tenant/billing-partner.js.map +1 -0
- package/build/module/query/tenant/index.d.ts +2 -0
- package/build/module/query/tenant/index.js +3 -0
- package/build/module/query/tenant/index.js.map +1 -0
- package/build/module/query/tenant/status.d.ts +14 -0
- package/build/module/query/tenant/status.js +35 -0
- package/build/module/query/tenant/status.js.map +1 -0
- package/build/module/regional.d.ts +29 -3
- package/build/module/regional.js +67 -8
- package/build/module/regional.js.map +1 -1
- package/build/module/test/index.d.ts +3 -14
- package/build/module/test/index.js +1 -23
- package/build/module/test/index.js.map +1 -1
- package/build/module/transaction.d.ts +3 -3
- package/build/module/transaction.js.map +1 -1
- package/build/module/v1.generated.d.ts +577 -24
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +8 -8
- package/build/migrations/0000000000001-init.ts +0 -5
- package/build/migrations/0000000000009-drop-store-schema.ts +0 -14
- package/build/migrations/0000000000010-bank-rules.ts +0 -190
- package/build/migrations/0000000000011-bank-rule-line-adjustments.ts +0 -65
- package/build/migrations/0000000000012-bank-rule-conditions.ts +0 -45
- package/build/migrations/0000000000013-bank-rule-name-unique.ts +0 -15
- package/build/migrations/0000000000014-bank-rule-drop-legacy-conditions.ts +0 -41
- package/build/migrations/0000000000015-booking-channel-logo-dev-provider.ts +0 -70
- package/build/migrations/0000000000016-owner-statement-draft-status.ts +0 -22
- package/build/migrations/0000000000017-tenant-migration-markers.ts +0 -18
- package/build/migrations/0000000000018-security-deposits-payable-category.ts +0 -63
- package/build/migrations/0000000000019-tenant-app-settings.ts +0 -76
- package/build/migrations/0000000000020-operating-opening-trial-balance.ts +0 -36
- package/build/migrations/0000000000021-audit-foreign-key-indexes.ts +0 -77
- package/build/migrations/0000000000022-opening-trial-balance-combined-columns.ts +0 -30
- package/build/migrations/0000000000023-journal-entry-currency-mismatch-reason.ts +0 -14
- package/build/migrations/0000000000024-listing-parent.ts +0 -37
- package/build/migrations/0000000000025-journal-entry-parent-listing.ts +0 -26
- package/build/migrations/0000000000026-booking-channel-logo-slots.ts +0 -89
- package/build/migrations/0000000000027-list-browse-performance-indexes.ts +0 -52
- package/build/migrations/0000000000028-flow-setting-status-jsonb.ts +0 -20
- package/build/migrations/0000000000029-tenant-slug.ts +0 -328
- package/build/migrations/0000000000030-pms-accounting-windows.ts +0 -50
- package/build/migrations/0000000000031-owner-statement-projection-listing-revision.ts +0 -20
- package/build/migrations/0000000000032-flow-event-listening.ts +0 -28
- package/build/migrations/0000000000033-opening-trial-balance-transaction.ts +0 -272
- package/build/migrations/0000000000034-historic-general-ledger.ts +0 -24
- package/build/migrations/0000000000035-tenant-regional-placement.ts +0 -37
- package/build/migrations/0000000000036-control-plane-projection-events.ts +0 -43
- package/build/migrations/0000000000037-tenant-guide-onboarding.ts +0 -21
- package/build/migrations/0000000000038-tracking-event-analytics-sink.ts +0 -31
- package/build/migrations/0000000000039-crunchy-region.ts +0 -86
- package/build/migrations/0000000000040-hostaway-region.ts +0 -72
- package/build/migrations/0000000000041-audit-tenant-fk.ts +0 -66
- package/build/migrations/0000000000042-ramp-staging-connect-params.ts +0 -35
- package/build/migrations/0000000000043-gl-pms-accounting-window-guard.ts +0 -125
- package/build/migrations/0000000000044-tenant-cross-region-fks.ts +0 -45
- package/build/migrations/0000000000045-cloudflare-region-env.ts +0 -100
- package/build/migrations/0000000000046-control-plane-outbox-alias.ts +0 -46
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { Kysely } from 'kysely';
|
|
2
|
-
import { sql } from 'kysely';
|
|
3
|
-
|
|
4
|
-
// The audit schema is an append-only trail that outlives placement: actions
|
|
5
|
-
// can be performed by tenants homed in other regions (cell workers), and the
|
|
6
|
-
// audit rows of a delete action are written after the tenant row is gone.
|
|
7
|
-
// Tenant deletion already purges audit rows explicitly
|
|
8
|
-
// (packages/repository/src/tenant/delete.ts), so the tenant FKs (and their
|
|
9
|
-
// redundant cascades) only cause false failures; drop them.
|
|
10
|
-
export async function up(db: Kysely<any>): Promise<void> {
|
|
11
|
-
await sql`
|
|
12
|
-
alter table audit.action
|
|
13
|
-
drop constraint if exists action_tenant_id_fkey;
|
|
14
|
-
`.execute(db);
|
|
15
|
-
await sql`
|
|
16
|
-
alter table audit.mutation
|
|
17
|
-
drop constraint if exists mutation_tenant_id_fkey;
|
|
18
|
-
`.execute(db);
|
|
19
|
-
await sql`
|
|
20
|
-
alter table audit.effect
|
|
21
|
-
drop constraint if exists effect_tenant_id_fkey;
|
|
22
|
-
`.execute(db);
|
|
23
|
-
await sql`
|
|
24
|
-
alter table audit.effect_attempt
|
|
25
|
-
drop constraint if exists effect_attempt_tenant_id_fkey;
|
|
26
|
-
`.execute(db);
|
|
27
|
-
await sql`
|
|
28
|
-
alter table audit.journal_delta
|
|
29
|
-
drop constraint if exists journal_delta_tenant_id_fkey;
|
|
30
|
-
`.execute(db);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function down(db: Kysely<any>): Promise<void> {
|
|
34
|
-
// NOT VALID: rows referencing since-deleted or cross-region tenants may
|
|
35
|
-
// legitimately exist; only future writes are constrained again.
|
|
36
|
-
await sql`
|
|
37
|
-
alter table audit.action
|
|
38
|
-
add constraint action_tenant_id_fkey
|
|
39
|
-
foreign key (tenant_id) references public.tenant(id)
|
|
40
|
-
on delete cascade not valid;
|
|
41
|
-
`.execute(db);
|
|
42
|
-
await sql`
|
|
43
|
-
alter table audit.mutation
|
|
44
|
-
add constraint mutation_tenant_id_fkey
|
|
45
|
-
foreign key (tenant_id) references public.tenant(id)
|
|
46
|
-
on delete cascade not valid;
|
|
47
|
-
`.execute(db);
|
|
48
|
-
await sql`
|
|
49
|
-
alter table audit.effect
|
|
50
|
-
add constraint effect_tenant_id_fkey
|
|
51
|
-
foreign key (tenant_id) references public.tenant(id)
|
|
52
|
-
on delete cascade not valid;
|
|
53
|
-
`.execute(db);
|
|
54
|
-
await sql`
|
|
55
|
-
alter table audit.effect_attempt
|
|
56
|
-
add constraint effect_attempt_tenant_id_fkey
|
|
57
|
-
foreign key (tenant_id) references public.tenant(id)
|
|
58
|
-
on delete cascade not valid;
|
|
59
|
-
`.execute(db);
|
|
60
|
-
await sql`
|
|
61
|
-
alter table audit.journal_delta
|
|
62
|
-
add constraint journal_delta_tenant_id_fkey
|
|
63
|
-
foreign key (tenant_id) references public.tenant(id)
|
|
64
|
-
on delete cascade not valid;
|
|
65
|
-
`.execute(db);
|
|
66
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Kysely } from 'kysely';
|
|
2
|
-
import { sql } from 'kysely';
|
|
3
|
-
|
|
4
|
-
export async function up(db: Kysely<any>): Promise<void> {
|
|
5
|
-
await sql`
|
|
6
|
-
update public.app
|
|
7
|
-
set authentication = jsonb_set(
|
|
8
|
-
coalesce(authentication, '{}'::jsonb),
|
|
9
|
-
'{defaultConnectParamsByApiEnv}',
|
|
10
|
-
coalesce(
|
|
11
|
-
authentication -> 'defaultConnectParamsByApiEnv',
|
|
12
|
-
'{}'::jsonb
|
|
13
|
-
) || jsonb_build_object(
|
|
14
|
-
'staging',
|
|
15
|
-
jsonb_build_object('environment', 'demo')
|
|
16
|
-
),
|
|
17
|
-
true
|
|
18
|
-
)
|
|
19
|
-
where id = 'ramp';
|
|
20
|
-
`.execute(db);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function down(db: Kysely<any>): Promise<void> {
|
|
24
|
-
await sql`
|
|
25
|
-
update public.app
|
|
26
|
-
set authentication = jsonb_set(
|
|
27
|
-
coalesce(authentication, '{}'::jsonb),
|
|
28
|
-
'{defaultConnectParamsByApiEnv}',
|
|
29
|
-
coalesce(authentication -> 'defaultConnectParamsByApiEnv', '{}'::jsonb)
|
|
30
|
-
- 'staging',
|
|
31
|
-
true
|
|
32
|
-
)
|
|
33
|
-
where id = 'ramp';
|
|
34
|
-
`.execute(db);
|
|
35
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { Kysely } from 'kysely';
|
|
2
|
-
import { sql } from 'kysely';
|
|
3
|
-
|
|
4
|
-
export async function up(db: Kysely<any>): Promise<void> {
|
|
5
|
-
await sql`
|
|
6
|
-
create or replace function public.assert_gl_pms_accounting_window_for_tenant(
|
|
7
|
-
check_tenant_id uuid
|
|
8
|
-
)
|
|
9
|
-
returns void
|
|
10
|
-
language plpgsql
|
|
11
|
-
as $$
|
|
12
|
-
begin
|
|
13
|
-
if check_tenant_id is null then
|
|
14
|
-
return;
|
|
15
|
-
end if;
|
|
16
|
-
|
|
17
|
-
if exists (
|
|
18
|
-
select 1
|
|
19
|
-
from public.tenant as tenant
|
|
20
|
-
where tenant.id = check_tenant_id
|
|
21
|
-
and tenant.is_general_ledger is true
|
|
22
|
-
and exists (
|
|
23
|
-
select 1
|
|
24
|
-
from public.connection as connection
|
|
25
|
-
inner join public.app as app on app.id = connection.app_id
|
|
26
|
-
where connection.tenant_id = check_tenant_id
|
|
27
|
-
and connection.status = 'active'
|
|
28
|
-
and connection.accounting_start_at is null
|
|
29
|
-
and app.category = 'propertyManagementSystem'
|
|
30
|
-
)
|
|
31
|
-
and not exists (
|
|
32
|
-
select 1
|
|
33
|
-
from public.connection as connection
|
|
34
|
-
inner join public.app as app on app.id = connection.app_id
|
|
35
|
-
where connection.tenant_id = check_tenant_id
|
|
36
|
-
and connection.status = 'active'
|
|
37
|
-
and connection.accounting_start_at is not null
|
|
38
|
-
and connection.accounting_end_at is null
|
|
39
|
-
and app.category = 'propertyManagementSystem'
|
|
40
|
-
)
|
|
41
|
-
) then
|
|
42
|
-
raise exception
|
|
43
|
-
'Active GL PMS connection is missing accountingStartAt without an open PMS accounting source'
|
|
44
|
-
using errcode = '23514';
|
|
45
|
-
end if;
|
|
46
|
-
end;
|
|
47
|
-
$$;
|
|
48
|
-
`.execute(db);
|
|
49
|
-
|
|
50
|
-
await sql`
|
|
51
|
-
create or replace function public.assert_gl_pms_accounting_window_connection_trigger()
|
|
52
|
-
returns trigger
|
|
53
|
-
language plpgsql
|
|
54
|
-
as $$
|
|
55
|
-
begin
|
|
56
|
-
if tg_op = 'DELETE' then
|
|
57
|
-
perform public.assert_gl_pms_accounting_window_for_tenant(old.tenant_id);
|
|
58
|
-
return null;
|
|
59
|
-
end if;
|
|
60
|
-
|
|
61
|
-
if tg_op = 'UPDATE' and new.tenant_id is distinct from old.tenant_id then
|
|
62
|
-
perform public.assert_gl_pms_accounting_window_for_tenant(old.tenant_id);
|
|
63
|
-
end if;
|
|
64
|
-
|
|
65
|
-
perform public.assert_gl_pms_accounting_window_for_tenant(new.tenant_id);
|
|
66
|
-
return null;
|
|
67
|
-
end;
|
|
68
|
-
$$;
|
|
69
|
-
`.execute(db);
|
|
70
|
-
|
|
71
|
-
await sql`
|
|
72
|
-
create or replace function public.assert_gl_pms_accounting_window_tenant_trigger()
|
|
73
|
-
returns trigger
|
|
74
|
-
language plpgsql
|
|
75
|
-
as $$
|
|
76
|
-
begin
|
|
77
|
-
if new.is_general_ledger is true then
|
|
78
|
-
perform public.assert_gl_pms_accounting_window_for_tenant(new.id);
|
|
79
|
-
end if;
|
|
80
|
-
|
|
81
|
-
return null;
|
|
82
|
-
end;
|
|
83
|
-
$$;
|
|
84
|
-
`.execute(db);
|
|
85
|
-
|
|
86
|
-
await sql`
|
|
87
|
-
create constraint trigger connection_gl_pms_accounting_window_guard
|
|
88
|
-
after insert or update or delete on public.connection
|
|
89
|
-
deferrable initially deferred
|
|
90
|
-
for each row
|
|
91
|
-
execute function public.assert_gl_pms_accounting_window_connection_trigger();
|
|
92
|
-
`.execute(db);
|
|
93
|
-
|
|
94
|
-
await sql`
|
|
95
|
-
create constraint trigger tenant_gl_pms_accounting_window_guard
|
|
96
|
-
after insert or update on public.tenant
|
|
97
|
-
deferrable initially deferred
|
|
98
|
-
for each row
|
|
99
|
-
execute function public.assert_gl_pms_accounting_window_tenant_trigger();
|
|
100
|
-
`.execute(db);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function down(db: Kysely<any>): Promise<void> {
|
|
104
|
-
await sql`
|
|
105
|
-
drop trigger if exists tenant_gl_pms_accounting_window_guard
|
|
106
|
-
on public.tenant;
|
|
107
|
-
`.execute(db);
|
|
108
|
-
|
|
109
|
-
await sql`
|
|
110
|
-
drop trigger if exists connection_gl_pms_accounting_window_guard
|
|
111
|
-
on public.connection;
|
|
112
|
-
`.execute(db);
|
|
113
|
-
|
|
114
|
-
await sql`
|
|
115
|
-
drop function if exists public.assert_gl_pms_accounting_window_tenant_trigger();
|
|
116
|
-
`.execute(db);
|
|
117
|
-
|
|
118
|
-
await sql`
|
|
119
|
-
drop function if exists public.assert_gl_pms_accounting_window_connection_trigger();
|
|
120
|
-
`.execute(db);
|
|
121
|
-
|
|
122
|
-
await sql`
|
|
123
|
-
drop function if exists public.assert_gl_pms_accounting_window_for_tenant(uuid);
|
|
124
|
-
`.execute(db);
|
|
125
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { Kysely } from 'kysely';
|
|
2
|
-
import { sql } from 'kysely';
|
|
3
|
-
|
|
4
|
-
// Tenant-to-tenant references (partner, billing partner, chart-of-accounts
|
|
5
|
-
// source) are cross-region: a partner homed in one cell manages tenants in
|
|
6
|
-
// another, so these self-referential FKs cannot hold within a single regional
|
|
7
|
-
// database. The control plane holds the authoritative tenant graph; the
|
|
8
|
-
// regional columns keep the ids as plain references. Drop the FKs.
|
|
9
|
-
export async function up(db: Kysely<any>): Promise<void> {
|
|
10
|
-
await sql`
|
|
11
|
-
alter table public.tenant
|
|
12
|
-
drop constraint if exists tenant_partner_id_fkey;
|
|
13
|
-
`.execute(db);
|
|
14
|
-
await sql`
|
|
15
|
-
alter table public.tenant
|
|
16
|
-
drop constraint if exists tenant_billing_partner_id_fkey;
|
|
17
|
-
`.execute(db);
|
|
18
|
-
await sql`
|
|
19
|
-
alter table public.tenant
|
|
20
|
-
drop constraint if exists tenant_chart_of_account_tenant_id_fkey;
|
|
21
|
-
`.execute(db);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function down(db: Kysely<any>): Promise<void> {
|
|
25
|
-
// NOT VALID: cross-region references may already exist; only future writes
|
|
26
|
-
// are constrained again.
|
|
27
|
-
await sql`
|
|
28
|
-
alter table public.tenant
|
|
29
|
-
add constraint tenant_partner_id_fkey
|
|
30
|
-
foreign key (partner_id) references public.tenant(id)
|
|
31
|
-
on update restrict on delete restrict not valid;
|
|
32
|
-
`.execute(db);
|
|
33
|
-
await sql`
|
|
34
|
-
alter table public.tenant
|
|
35
|
-
add constraint tenant_billing_partner_id_fkey
|
|
36
|
-
foreign key (billing_partner_id) references public.tenant(id)
|
|
37
|
-
on update restrict on delete restrict not valid;
|
|
38
|
-
`.execute(db);
|
|
39
|
-
await sql`
|
|
40
|
-
alter table public.tenant
|
|
41
|
-
add constraint tenant_chart_of_account_tenant_id_fkey
|
|
42
|
-
foreign key (chart_of_account_tenant_id) references public.tenant(id)
|
|
43
|
-
on update restrict on delete restrict not valid;
|
|
44
|
-
`.execute(db);
|
|
45
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { Kysely } from 'kysely';
|
|
2
|
-
import { sql } from 'kysely';
|
|
3
|
-
|
|
4
|
-
const regionalApiEnvKeys = sql`array[
|
|
5
|
-
'staging-ap',
|
|
6
|
-
'staging-crunchy',
|
|
7
|
-
'staging-eu',
|
|
8
|
-
'staging-hostaway',
|
|
9
|
-
'staging-us',
|
|
10
|
-
'production-ap',
|
|
11
|
-
'production-crunchy',
|
|
12
|
-
'production-eu',
|
|
13
|
-
'production-hostaway',
|
|
14
|
-
'production-us'
|
|
15
|
-
]::text[]`;
|
|
16
|
-
|
|
17
|
-
export async function up(db: Kysely<any>): Promise<void> {
|
|
18
|
-
await sql`
|
|
19
|
-
do $$
|
|
20
|
-
begin
|
|
21
|
-
if exists (
|
|
22
|
-
select 1
|
|
23
|
-
from public.app
|
|
24
|
-
cross join lateral jsonb_each(
|
|
25
|
-
coalesce(authentication -> 'defaultConnectParamsByApiEnv', '{}'::jsonb)
|
|
26
|
-
) as env(key, value)
|
|
27
|
-
where env.key = any(${regionalApiEnvKeys})
|
|
28
|
-
and not (
|
|
29
|
-
coalesce(authentication -> 'defaultConnectParamsByApiEnv', '{}'::jsonb)
|
|
30
|
-
? split_part(env.key, '-', 1)
|
|
31
|
-
)
|
|
32
|
-
group by public.app.id, split_part(env.key, '-', 1)
|
|
33
|
-
having count(distinct env.value::text) > 1
|
|
34
|
-
) then
|
|
35
|
-
raise exception
|
|
36
|
-
'Regional defaultConnectParamsByApiEnv values disagree; add staging/production explicitly before removing regional keys';
|
|
37
|
-
end if;
|
|
38
|
-
end $$;
|
|
39
|
-
`.execute(db);
|
|
40
|
-
|
|
41
|
-
await sql`
|
|
42
|
-
with base_values as (
|
|
43
|
-
select
|
|
44
|
-
public.app.id,
|
|
45
|
-
split_part(env.key, '-', 1) as base_env,
|
|
46
|
-
min(env.value::text)::jsonb as params
|
|
47
|
-
from public.app
|
|
48
|
-
cross join lateral jsonb_each(
|
|
49
|
-
coalesce(authentication -> 'defaultConnectParamsByApiEnv', '{}'::jsonb)
|
|
50
|
-
) as env(key, value)
|
|
51
|
-
where env.key = any(${regionalApiEnvKeys})
|
|
52
|
-
and not (
|
|
53
|
-
coalesce(authentication -> 'defaultConnectParamsByApiEnv', '{}'::jsonb)
|
|
54
|
-
? split_part(env.key, '-', 1)
|
|
55
|
-
)
|
|
56
|
-
group by public.app.id, split_part(env.key, '-', 1)
|
|
57
|
-
),
|
|
58
|
-
per_app as (
|
|
59
|
-
select id, jsonb_object_agg(base_env, params) as params_by_env
|
|
60
|
-
from base_values
|
|
61
|
-
group by id
|
|
62
|
-
)
|
|
63
|
-
update public.app
|
|
64
|
-
set authentication = jsonb_set(
|
|
65
|
-
coalesce(authentication, '{}'::jsonb),
|
|
66
|
-
'{defaultConnectParamsByApiEnv}',
|
|
67
|
-
coalesce(authentication -> 'defaultConnectParamsByApiEnv', '{}'::jsonb)
|
|
68
|
-
|| per_app.params_by_env,
|
|
69
|
-
true
|
|
70
|
-
)
|
|
71
|
-
from per_app
|
|
72
|
-
where public.app.id = per_app.id;
|
|
73
|
-
`.execute(db);
|
|
74
|
-
|
|
75
|
-
await sql`
|
|
76
|
-
update public.app
|
|
77
|
-
set authentication = jsonb_set(
|
|
78
|
-
coalesce(authentication, '{}'::jsonb),
|
|
79
|
-
'{defaultConnectParamsByApiEnv}',
|
|
80
|
-
coalesce(authentication -> 'defaultConnectParamsByApiEnv', '{}'::jsonb)
|
|
81
|
-
- 'staging-ap'
|
|
82
|
-
- 'staging-crunchy'
|
|
83
|
-
- 'staging-eu'
|
|
84
|
-
- 'staging-hostaway'
|
|
85
|
-
- 'staging-us'
|
|
86
|
-
- 'production-ap'
|
|
87
|
-
- 'production-crunchy'
|
|
88
|
-
- 'production-eu'
|
|
89
|
-
- 'production-hostaway'
|
|
90
|
-
- 'production-us',
|
|
91
|
-
true
|
|
92
|
-
)
|
|
93
|
-
where coalesce(authentication -> 'defaultConnectParamsByApiEnv', '{}'::jsonb)
|
|
94
|
-
?| ${regionalApiEnvKeys};
|
|
95
|
-
`.execute(db);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function down(db: Kysely<any>): Promise<void> {
|
|
99
|
-
await sql`select 1`.execute(db);
|
|
100
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Kysely } from 'kysely';
|
|
2
|
-
import { sql } from 'kysely';
|
|
3
|
-
|
|
4
|
-
export async function up(db: Kysely<any>): Promise<void> {
|
|
5
|
-
await sql`
|
|
6
|
-
create table if not exists public.control_plane_outbox (
|
|
7
|
-
id uuid primary key default gen_random_uuid(),
|
|
8
|
-
aggregate_type text not null,
|
|
9
|
-
aggregate_id text not null,
|
|
10
|
-
event_type text not null,
|
|
11
|
-
event_version integer not null,
|
|
12
|
-
data_region text,
|
|
13
|
-
payload jsonb not null default jsonb_build_object(),
|
|
14
|
-
created_at timestamptz not null default now(),
|
|
15
|
-
published_at timestamptz,
|
|
16
|
-
attempts integer not null default 0,
|
|
17
|
-
last_error text,
|
|
18
|
-
constraint control_plane_outbox_region_check
|
|
19
|
-
check (
|
|
20
|
-
data_region is null
|
|
21
|
-
or data_region in ('ap', 'crunchy', 'eu', 'hostaway', 'us')
|
|
22
|
-
),
|
|
23
|
-
constraint control_plane_outbox_event_version_check
|
|
24
|
-
check (event_version > 0),
|
|
25
|
-
constraint control_plane_outbox_aggregate_version_key
|
|
26
|
-
unique (aggregate_type, aggregate_id, event_version)
|
|
27
|
-
);
|
|
28
|
-
`.execute(db);
|
|
29
|
-
|
|
30
|
-
await sql`
|
|
31
|
-
create index if not exists control_plane_outbox_pending_idx
|
|
32
|
-
on public.control_plane_outbox (created_at, id)
|
|
33
|
-
where published_at is null;
|
|
34
|
-
`.execute(db);
|
|
35
|
-
|
|
36
|
-
await sql`
|
|
37
|
-
create index if not exists control_plane_outbox_aggregate_idx
|
|
38
|
-
on public.control_plane_outbox (aggregate_type, aggregate_id, created_at);
|
|
39
|
-
`.execute(db);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function down(db: Kysely<any>): Promise<void> {
|
|
43
|
-
await sql`
|
|
44
|
-
drop table if exists public.control_plane_outbox;
|
|
45
|
-
`.execute(db);
|
|
46
|
-
}
|