@vrplatform/kysely 1.3.40 → 1.3.41-4245
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.map +1 -1
- package/build/main/control-plane/index.d.ts +141 -0
- package/build/main/control-plane/index.js +3 -0
- package/build/main/control-plane/index.js.map +1 -0
- package/build/main/error.js.map +1 -1
- package/build/main/index.d.ts +6 -3
- package/build/main/index.js +8 -9
- package/build/main/index.js.map +1 -1
- package/build/main/isomorphic.d.ts +2 -1
- package/build/main/isomorphic.js +2 -2
- package/build/main/isomorphic.js.map +1 -1
- package/build/main/local/digest.js.map +1 -1
- package/build/main/local/generate.js +12 -0
- package/build/main/local/generate.js.map +1 -1
- package/build/main/local/index.d.ts +3 -2
- package/build/main/local/index.js +56 -3
- package/build/main/local/index.js.map +1 -1
- package/build/main/local/prune-pulled-schema.js.map +1 -1
- package/build/main/pganalyze-comment-plugin/comment-transformer.js +0 -1
- package/build/main/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/main/pganalyze-comment-plugin/index.js +16 -3
- package/build/main/pganalyze-comment-plugin/index.js.map +1 -1
- package/build/main/plugins.js.map +1 -1
- package/build/main/query/listing/status.d.ts +4 -4
- package/build/main/query/listing/status.js +19 -2
- package/build/main/query/listing/status.js.map +1 -1
- package/build/main/regional.d.ts +34 -0
- package/build/main/regional.js +145 -0
- package/build/main/regional.js.map +1 -0
- package/build/main/test/index.js.map +1 -1
- package/build/main/transaction.d.ts +7 -0
- package/build/main/transaction.js +32 -0
- package/build/main/transaction.js.map +1 -0
- package/build/main/v1.generated.d.ts +133 -2
- package/build/main/v1.generated.js.map +1 -1
- package/build/migrations/0000000000001-init.ts +5 -0
- package/build/migrations/0000000000009-drop-store-schema.ts +14 -0
- package/build/migrations/0000000000010-bank-rules.ts +190 -0
- package/build/migrations/0000000000011-bank-rule-line-adjustments.ts +65 -0
- package/build/migrations/0000000000012-bank-rule-conditions.ts +45 -0
- package/build/migrations/0000000000013-bank-rule-name-unique.ts +15 -0
- package/build/migrations/0000000000014-bank-rule-drop-legacy-conditions.ts +41 -0
- package/build/migrations/0000000000015-booking-channel-logo-dev-provider.ts +70 -0
- package/build/migrations/0000000000016-owner-statement-draft-status.ts +22 -0
- package/build/migrations/0000000000017-tenant-migration-markers.ts +18 -0
- package/build/migrations/0000000000018-security-deposits-payable-category.ts +63 -0
- package/build/migrations/0000000000019-tenant-app-settings.ts +76 -0
- package/build/migrations/0000000000020-operating-opening-trial-balance.ts +36 -0
- package/build/migrations/0000000000021-audit-foreign-key-indexes.ts +77 -0
- package/build/migrations/0000000000022-opening-trial-balance-combined-columns.ts +30 -0
- package/build/migrations/0000000000023-journal-entry-currency-mismatch-reason.ts +14 -0
- package/build/migrations/0000000000024-listing-parent.ts +37 -0
- package/build/migrations/0000000000025-journal-entry-parent-listing.ts +26 -0
- package/build/migrations/0000000000026-booking-channel-logo-slots.ts +89 -0
- package/build/migrations/0000000000027-list-browse-performance-indexes.ts +52 -0
- package/build/migrations/0000000000028-flow-setting-status-jsonb.ts +20 -0
- package/build/migrations/0000000000029-tenant-slug.ts +328 -0
- package/build/migrations/0000000000030-pms-accounting-windows.ts +50 -0
- package/build/migrations/0000000000031-owner-statement-projection-listing-revision.ts +20 -0
- package/build/migrations/0000000000032-flow-event-listening.ts +28 -0
- package/build/migrations/0000000000033-opening-trial-balance-transaction.ts +272 -0
- package/build/migrations/0000000000034-historic-general-ledger.ts +24 -0
- package/build/migrations/0000000000035-tenant-regional-placement.ts +37 -0
- package/build/migrations/0000000000036-control-plane-projection-events.ts +43 -0
- package/build/migrations/0000000000037-tenant-guide-onboarding.ts +21 -0
- package/build/migrations/0000000000038-ramp-staging-connect-params.ts +35 -0
- package/build/migrations/0000000000038-tracking-event-analytics-sink.ts +31 -0
- package/build/migrations/0000000000039-crunchy-region.ts +86 -0
- package/build/migrations/0000000000039-gl-pms-accounting-window-guard.ts +125 -0
- package/build/migrations/0000000000040-hostaway-region.ts +72 -0
- package/build/module/camel-case/index.js.map +1 -1
- package/build/module/control-plane/index.d.ts +141 -0
- package/build/module/control-plane/index.js +2 -0
- package/build/module/control-plane/index.js.map +1 -0
- package/build/module/error.js.map +1 -1
- package/build/module/index.d.ts +6 -3
- package/build/module/index.js +8 -9
- package/build/module/index.js.map +1 -1
- package/build/module/isomorphic.d.ts +2 -1
- package/build/module/isomorphic.js.map +1 -1
- package/build/module/local/digest.js.map +1 -1
- package/build/module/local/generate.js +12 -0
- package/build/module/local/generate.js.map +1 -1
- package/build/module/local/index.d.ts +3 -2
- package/build/module/local/index.js +23 -3
- package/build/module/local/index.js.map +1 -1
- package/build/module/local/prune-pulled-schema.js.map +1 -1
- package/build/module/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/module/pganalyze-comment-plugin/index.js.map +1 -1
- package/build/module/plugins.js.map +1 -1
- package/build/module/query/listing/status.d.ts +4 -4
- package/build/module/query/listing/status.js +19 -2
- package/build/module/query/listing/status.js.map +1 -1
- package/build/module/regional.d.ts +34 -0
- package/build/module/regional.js +103 -0
- package/build/module/regional.js.map +1 -0
- package/build/module/test/index.js.map +1 -1
- package/build/module/transaction.d.ts +7 -0
- package/build/module/transaction.js +25 -0
- package/build/module/transaction.js.map +1 -0
- package/build/module/v1.generated.d.ts +133 -2
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +13 -4
- package/build/main/tsconfig.main.tsbuildinfo +0 -1
- package/build/module/tsconfig.esm.tsbuildinfo +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
alter table public.connection
|
|
7
|
+
add column accounting_start_at date,
|
|
8
|
+
add column accounting_end_at date,
|
|
9
|
+
add constraint connection_accounting_window_check
|
|
10
|
+
check (
|
|
11
|
+
(
|
|
12
|
+
accounting_start_at is null
|
|
13
|
+
and accounting_end_at is null
|
|
14
|
+
)
|
|
15
|
+
or accounting_end_at is null
|
|
16
|
+
or accounting_start_at < accounting_end_at
|
|
17
|
+
);
|
|
18
|
+
`.execute(db);
|
|
19
|
+
|
|
20
|
+
await sql`
|
|
21
|
+
update public.connection as connection
|
|
22
|
+
set accounting_start_at = date '1900-01-01'
|
|
23
|
+
from public.app as app
|
|
24
|
+
where app.id = connection.app_id
|
|
25
|
+
and app.category = 'propertyManagementSystem'
|
|
26
|
+
and connection.status = 'active';
|
|
27
|
+
`.execute(db);
|
|
28
|
+
|
|
29
|
+
await sql`
|
|
30
|
+
create index connection_tenant_accounting_window_idx
|
|
31
|
+
on public.connection (
|
|
32
|
+
tenant_id,
|
|
33
|
+
accounting_start_at,
|
|
34
|
+
accounting_end_at
|
|
35
|
+
);
|
|
36
|
+
`.execute(db);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
40
|
+
await sql`
|
|
41
|
+
drop index if exists public.connection_tenant_accounting_window_idx;
|
|
42
|
+
`.execute(db);
|
|
43
|
+
|
|
44
|
+
await sql`
|
|
45
|
+
alter table public.connection
|
|
46
|
+
drop constraint if exists connection_accounting_window_check,
|
|
47
|
+
drop column if exists accounting_end_at,
|
|
48
|
+
drop column if exists accounting_start_at;
|
|
49
|
+
`.execute(db);
|
|
50
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 accounting.owner_statement_projection_listing_revision (
|
|
7
|
+
tenant_id uuid not null,
|
|
8
|
+
listing_id uuid not null,
|
|
9
|
+
revision bigint default 0 not null,
|
|
10
|
+
updated_at timestamp with time zone default now() not null,
|
|
11
|
+
primary key (tenant_id, listing_id)
|
|
12
|
+
);
|
|
13
|
+
`.execute(db);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
17
|
+
await sql`
|
|
18
|
+
drop table accounting.owner_statement_projection_listing_revision;
|
|
19
|
+
`.execute(db);
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
alter table core.flow
|
|
7
|
+
add column event_listening jsonb not null default '[]'::jsonb,
|
|
8
|
+
add constraint flow_event_listening_array_check
|
|
9
|
+
check (jsonb_typeof(event_listening) = 'array');
|
|
10
|
+
`.execute(db);
|
|
11
|
+
|
|
12
|
+
await sql`
|
|
13
|
+
create index flow_event_listening_idx
|
|
14
|
+
on core.flow using gin (event_listening);
|
|
15
|
+
`.execute(db);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
19
|
+
await sql`
|
|
20
|
+
drop index if exists core.flow_event_listening_idx;
|
|
21
|
+
`.execute(db);
|
|
22
|
+
|
|
23
|
+
await sql`
|
|
24
|
+
alter table core.flow
|
|
25
|
+
drop constraint if exists flow_event_listening_array_check,
|
|
26
|
+
drop column if exists event_listening;
|
|
27
|
+
`.execute(db);
|
|
28
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
const EQUITY_CATEGORY_ID = '62de7391-5fb2-4789-a782-feb2c6ce95eb';
|
|
5
|
+
const JOURNAL_BATCH_TYPE = 'journalBatch';
|
|
6
|
+
const OPENING_TRIAL_BALANCE_JOURNAL_ENTRY_TYPE = 'opening_trial_balance';
|
|
7
|
+
const OPENING_TRIAL_BALANCE_REF = 'openingTrialBalance';
|
|
8
|
+
const OPENING_TRIAL_BALANCE_REF_PREFIX = 'openingTrialBalance_';
|
|
9
|
+
const LEGACY_OPENING_TRIAL_BALANCE_REF_PREFIX =
|
|
10
|
+
'openingTrialBalance_operating_manual_';
|
|
11
|
+
|
|
12
|
+
export async function up(db: Kysely<any>): Promise<void> {
|
|
13
|
+
await sql`
|
|
14
|
+
insert into accounting.transaction_type (name)
|
|
15
|
+
values (${JOURNAL_BATCH_TYPE})
|
|
16
|
+
on conflict (name) do nothing;
|
|
17
|
+
`.execute(db);
|
|
18
|
+
|
|
19
|
+
await sql`
|
|
20
|
+
with tenants_with_opening_trial_balance as (
|
|
21
|
+
select
|
|
22
|
+
tenant.id,
|
|
23
|
+
lower(coalesce(tenant.default_currency, 'usd')) as currency,
|
|
24
|
+
(tenant.statement_start_at::date - interval '1 day')::date as opening_date
|
|
25
|
+
from public.tenant
|
|
26
|
+
where tenant.statement_start_at is not null
|
|
27
|
+
and not exists (
|
|
28
|
+
select 1
|
|
29
|
+
from accounting.transaction existing_transaction
|
|
30
|
+
where existing_transaction.tenant_id = tenant.id
|
|
31
|
+
and existing_transaction.unique_ref = ${OPENING_TRIAL_BALANCE_REF}
|
|
32
|
+
)
|
|
33
|
+
and (
|
|
34
|
+
exists (
|
|
35
|
+
select 1
|
|
36
|
+
from accounting.account
|
|
37
|
+
inner join accounting.account_category category
|
|
38
|
+
on category.id = account.category_id
|
|
39
|
+
left join accounting.account_assignment opening_balance_assignment
|
|
40
|
+
on opening_balance_assignment.account_id = account.id
|
|
41
|
+
and opening_balance_assignment.tenant_id = account.tenant_id
|
|
42
|
+
and opening_balance_assignment.type = 'openingBalance'
|
|
43
|
+
where account.tenant_id = tenant.id
|
|
44
|
+
and account.status = 'active'
|
|
45
|
+
and account.type in ('ledger', 'bank')
|
|
46
|
+
and category.classification is not null
|
|
47
|
+
and (
|
|
48
|
+
category.classification in ('asset', 'liability')
|
|
49
|
+
or category.id = ${EQUITY_CATEGORY_ID}
|
|
50
|
+
)
|
|
51
|
+
and opening_balance_assignment.id is null
|
|
52
|
+
and account.opening_trial_balance_combined_cent_total <> 0
|
|
53
|
+
)
|
|
54
|
+
or exists (
|
|
55
|
+
select 1
|
|
56
|
+
from accounting.journal_entry
|
|
57
|
+
where journal_entry.tenant_id = tenant.id
|
|
58
|
+
and journal_entry.type = ${OPENING_TRIAL_BALANCE_JOURNAL_ENTRY_TYPE}
|
|
59
|
+
and (
|
|
60
|
+
journal_entry.unique_ref like ${`${OPENING_TRIAL_BALANCE_REF_PREFIX}%`}
|
|
61
|
+
or journal_entry.unique_ref like ${`${LEGACY_OPENING_TRIAL_BALANCE_REF_PREFIX}%`}
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
insert into accounting.transaction (
|
|
67
|
+
id,
|
|
68
|
+
tenant_id,
|
|
69
|
+
description,
|
|
70
|
+
type,
|
|
71
|
+
date,
|
|
72
|
+
currency,
|
|
73
|
+
cent_total,
|
|
74
|
+
unique_ref,
|
|
75
|
+
status,
|
|
76
|
+
paid_status,
|
|
77
|
+
paid_at,
|
|
78
|
+
is_opening_balance
|
|
79
|
+
)
|
|
80
|
+
select
|
|
81
|
+
gen_random_uuid(),
|
|
82
|
+
tenant.id,
|
|
83
|
+
'Opening Trial Balance',
|
|
84
|
+
${JOURNAL_BATCH_TYPE},
|
|
85
|
+
tenant.opening_date,
|
|
86
|
+
tenant.currency,
|
|
87
|
+
0,
|
|
88
|
+
${OPENING_TRIAL_BALANCE_REF},
|
|
89
|
+
'active',
|
|
90
|
+
'paid',
|
|
91
|
+
tenant.opening_date,
|
|
92
|
+
true
|
|
93
|
+
from tenants_with_opening_trial_balance tenant;
|
|
94
|
+
`.execute(db);
|
|
95
|
+
|
|
96
|
+
await sql`
|
|
97
|
+
insert into accounting.transaction_line (
|
|
98
|
+
id,
|
|
99
|
+
transaction_id,
|
|
100
|
+
tenant_id,
|
|
101
|
+
description,
|
|
102
|
+
account_id,
|
|
103
|
+
cent_total,
|
|
104
|
+
party,
|
|
105
|
+
unique_ref
|
|
106
|
+
)
|
|
107
|
+
select
|
|
108
|
+
gen_random_uuid(),
|
|
109
|
+
transaction.id,
|
|
110
|
+
account.tenant_id,
|
|
111
|
+
'Opening Account Balance',
|
|
112
|
+
account.id,
|
|
113
|
+
account.opening_trial_balance_combined_cent_total,
|
|
114
|
+
'manager',
|
|
115
|
+
${OPENING_TRIAL_BALANCE_REF_PREFIX} || 'account_' || account.id
|
|
116
|
+
from accounting.transaction
|
|
117
|
+
inner join accounting.account
|
|
118
|
+
on account.tenant_id = transaction.tenant_id
|
|
119
|
+
inner join accounting.account_category category
|
|
120
|
+
on category.id = account.category_id
|
|
121
|
+
left join accounting.account_assignment opening_balance_assignment
|
|
122
|
+
on opening_balance_assignment.account_id = account.id
|
|
123
|
+
and opening_balance_assignment.tenant_id = account.tenant_id
|
|
124
|
+
and opening_balance_assignment.type = 'openingBalance'
|
|
125
|
+
where transaction.type = ${JOURNAL_BATCH_TYPE}
|
|
126
|
+
and transaction.unique_ref = ${OPENING_TRIAL_BALANCE_REF}
|
|
127
|
+
and transaction.is_opening_balance = true
|
|
128
|
+
and account.status = 'active'
|
|
129
|
+
and account.type in ('ledger', 'bank')
|
|
130
|
+
and category.classification is not null
|
|
131
|
+
and (
|
|
132
|
+
category.classification in ('asset', 'liability')
|
|
133
|
+
or category.id = ${EQUITY_CATEGORY_ID}
|
|
134
|
+
)
|
|
135
|
+
and opening_balance_assignment.id is null
|
|
136
|
+
and not exists (
|
|
137
|
+
select 1
|
|
138
|
+
from accounting.transaction_line existing_line
|
|
139
|
+
where existing_line.tenant_id = transaction.tenant_id
|
|
140
|
+
and existing_line.transaction_id = transaction.id
|
|
141
|
+
and existing_line.unique_ref =
|
|
142
|
+
${OPENING_TRIAL_BALANCE_REF_PREFIX} || 'account_' || account.id
|
|
143
|
+
);
|
|
144
|
+
`.execute(db);
|
|
145
|
+
|
|
146
|
+
await sql`
|
|
147
|
+
with assignment_account as (
|
|
148
|
+
select distinct on (account.tenant_id)
|
|
149
|
+
account.tenant_id,
|
|
150
|
+
account.id
|
|
151
|
+
from accounting.account
|
|
152
|
+
inner join accounting.account_assignment assignment
|
|
153
|
+
on assignment.account_id = account.id
|
|
154
|
+
and assignment.tenant_id = account.tenant_id
|
|
155
|
+
and assignment.type = 'openingBalance'
|
|
156
|
+
where account.status = 'active'
|
|
157
|
+
order by account.tenant_id, account.title, account.id
|
|
158
|
+
),
|
|
159
|
+
source_total as (
|
|
160
|
+
select
|
|
161
|
+
transaction_line.tenant_id,
|
|
162
|
+
transaction_line.transaction_id,
|
|
163
|
+
coalesce(sum(transaction_line.cent_total), 0) as cent_total
|
|
164
|
+
from accounting.transaction_line
|
|
165
|
+
where transaction_line.unique_ref like ${`${OPENING_TRIAL_BALANCE_REF_PREFIX}account_%`}
|
|
166
|
+
group by transaction_line.tenant_id, transaction_line.transaction_id
|
|
167
|
+
)
|
|
168
|
+
insert into accounting.transaction_line (
|
|
169
|
+
id,
|
|
170
|
+
transaction_id,
|
|
171
|
+
tenant_id,
|
|
172
|
+
description,
|
|
173
|
+
account_id,
|
|
174
|
+
cent_total,
|
|
175
|
+
party,
|
|
176
|
+
unique_ref
|
|
177
|
+
)
|
|
178
|
+
select
|
|
179
|
+
gen_random_uuid(),
|
|
180
|
+
transaction.id,
|
|
181
|
+
transaction.tenant_id,
|
|
182
|
+
case
|
|
183
|
+
when coalesce(source_total.cent_total, 0) > 0
|
|
184
|
+
then 'Opening Balance Surplus'
|
|
185
|
+
else 'Opening Balance Deficit'
|
|
186
|
+
end,
|
|
187
|
+
assignment_account.id,
|
|
188
|
+
coalesce(source_total.cent_total, 0) * -1,
|
|
189
|
+
'manager',
|
|
190
|
+
${OPENING_TRIAL_BALANCE_REF_PREFIX} || 'assignment_' || assignment_account.id
|
|
191
|
+
from accounting.transaction
|
|
192
|
+
inner join assignment_account
|
|
193
|
+
on assignment_account.tenant_id = transaction.tenant_id
|
|
194
|
+
left join source_total
|
|
195
|
+
on source_total.tenant_id = transaction.tenant_id
|
|
196
|
+
and source_total.transaction_id = transaction.id
|
|
197
|
+
where transaction.type = ${JOURNAL_BATCH_TYPE}
|
|
198
|
+
and transaction.unique_ref = ${OPENING_TRIAL_BALANCE_REF}
|
|
199
|
+
and transaction.is_opening_balance = true
|
|
200
|
+
and not exists (
|
|
201
|
+
select 1
|
|
202
|
+
from accounting.transaction_line existing_line
|
|
203
|
+
where existing_line.tenant_id = transaction.tenant_id
|
|
204
|
+
and existing_line.transaction_id = transaction.id
|
|
205
|
+
and existing_line.unique_ref =
|
|
206
|
+
${OPENING_TRIAL_BALANCE_REF_PREFIX} || 'assignment_' || assignment_account.id
|
|
207
|
+
);
|
|
208
|
+
`.execute(db);
|
|
209
|
+
|
|
210
|
+
await sql`
|
|
211
|
+
update accounting.journal_entry journal_entry
|
|
212
|
+
set
|
|
213
|
+
entity_type = 'transaction',
|
|
214
|
+
transaction_id = transaction_line.transaction_id,
|
|
215
|
+
line_id = transaction_line.id,
|
|
216
|
+
unique_ref = transaction_line.unique_ref
|
|
217
|
+
from accounting.transaction
|
|
218
|
+
inner join accounting.transaction_line
|
|
219
|
+
on transaction_line.transaction_id = transaction.id
|
|
220
|
+
and transaction_line.tenant_id = transaction.tenant_id
|
|
221
|
+
where journal_entry.tenant_id = transaction.tenant_id
|
|
222
|
+
and journal_entry.account_id = transaction_line.account_id
|
|
223
|
+
and transaction.type = ${JOURNAL_BATCH_TYPE}
|
|
224
|
+
and transaction.unique_ref = ${OPENING_TRIAL_BALANCE_REF}
|
|
225
|
+
and transaction.is_opening_balance = true
|
|
226
|
+
and journal_entry.type = ${OPENING_TRIAL_BALANCE_JOURNAL_ENTRY_TYPE}
|
|
227
|
+
and (
|
|
228
|
+
journal_entry.unique_ref like ${`${OPENING_TRIAL_BALANCE_REF_PREFIX}%`}
|
|
229
|
+
or journal_entry.unique_ref like ${`${LEGACY_OPENING_TRIAL_BALANCE_REF_PREFIX}%`}
|
|
230
|
+
);
|
|
231
|
+
`.execute(db);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
235
|
+
await sql`
|
|
236
|
+
update accounting.journal_entry journal_entry
|
|
237
|
+
set
|
|
238
|
+
transaction_id = null,
|
|
239
|
+
line_id = null
|
|
240
|
+
from accounting.transaction
|
|
241
|
+
where journal_entry.transaction_id = transaction.id
|
|
242
|
+
and transaction.type = ${JOURNAL_BATCH_TYPE}
|
|
243
|
+
and transaction.unique_ref = ${OPENING_TRIAL_BALANCE_REF}
|
|
244
|
+
and transaction.is_opening_balance = true;
|
|
245
|
+
`.execute(db);
|
|
246
|
+
|
|
247
|
+
await sql`
|
|
248
|
+
delete from accounting.transaction_line
|
|
249
|
+
using accounting.transaction
|
|
250
|
+
where transaction_line.transaction_id = transaction.id
|
|
251
|
+
and transaction.type = ${JOURNAL_BATCH_TYPE}
|
|
252
|
+
and transaction.unique_ref = ${OPENING_TRIAL_BALANCE_REF}
|
|
253
|
+
and transaction.is_opening_balance = true;
|
|
254
|
+
`.execute(db);
|
|
255
|
+
|
|
256
|
+
await sql`
|
|
257
|
+
delete from accounting.transaction
|
|
258
|
+
where type = ${JOURNAL_BATCH_TYPE}
|
|
259
|
+
and unique_ref = ${OPENING_TRIAL_BALANCE_REF}
|
|
260
|
+
and is_opening_balance = true;
|
|
261
|
+
`.execute(db);
|
|
262
|
+
|
|
263
|
+
await sql`
|
|
264
|
+
delete from accounting.transaction_type
|
|
265
|
+
where name = ${JOURNAL_BATCH_TYPE}
|
|
266
|
+
and not exists (
|
|
267
|
+
select 1
|
|
268
|
+
from accounting.transaction
|
|
269
|
+
where transaction.type = ${JOURNAL_BATCH_TYPE}
|
|
270
|
+
);
|
|
271
|
+
`.execute(db);
|
|
272
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
const HISTORIC_GENERAL_LEDGER_JOURNAL_ENTRY_TYPE = 'historical_general_ledger';
|
|
5
|
+
|
|
6
|
+
export async function up(db: Kysely<any>): Promise<void> {
|
|
7
|
+
await sql`
|
|
8
|
+
insert into accounting.journal_entry_type (name)
|
|
9
|
+
values (${HISTORIC_GENERAL_LEDGER_JOURNAL_ENTRY_TYPE})
|
|
10
|
+
on conflict (name) do nothing;
|
|
11
|
+
`.execute(db);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
15
|
+
await sql`
|
|
16
|
+
delete from accounting.journal_entry_type
|
|
17
|
+
where name = ${HISTORIC_GENERAL_LEDGER_JOURNAL_ENTRY_TYPE}
|
|
18
|
+
and not exists (
|
|
19
|
+
select 1
|
|
20
|
+
from accounting.journal_entry
|
|
21
|
+
where type = ${HISTORIC_GENERAL_LEDGER_JOURNAL_ENTRY_TYPE}
|
|
22
|
+
);
|
|
23
|
+
`.execute(db);
|
|
24
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
alter table public.tenant
|
|
7
|
+
add column data_region text not null default 'eu',
|
|
8
|
+
add column storage_realm text not null default 'vrtrust';
|
|
9
|
+
`.execute(db);
|
|
10
|
+
|
|
11
|
+
await sql`
|
|
12
|
+
update public.tenant
|
|
13
|
+
set storage_realm = 'vrintegration'
|
|
14
|
+
where coalesce(is_general_ledger, false) = false;
|
|
15
|
+
`.execute(db);
|
|
16
|
+
|
|
17
|
+
await sql`
|
|
18
|
+
alter table public.tenant
|
|
19
|
+
add constraint tenant_data_region_check
|
|
20
|
+
check (data_region in ('eu', 'us', 'ap')),
|
|
21
|
+
add constraint tenant_storage_realm_check
|
|
22
|
+
check (storage_realm in ('vrintegration', 'vrtrust')),
|
|
23
|
+
add constraint tenant_vrintegration_region_check
|
|
24
|
+
check (storage_realm <> 'vrintegration' or data_region = 'eu');
|
|
25
|
+
`.execute(db);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
29
|
+
await sql`
|
|
30
|
+
alter table public.tenant
|
|
31
|
+
drop constraint tenant_vrintegration_region_check,
|
|
32
|
+
drop constraint tenant_storage_realm_check,
|
|
33
|
+
drop constraint tenant_data_region_check,
|
|
34
|
+
drop column storage_realm,
|
|
35
|
+
drop column data_region;
|
|
36
|
+
`.execute(db);
|
|
37
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 public.control_plane_projection_event (
|
|
7
|
+
event_id uuid primary key,
|
|
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 not null,
|
|
13
|
+
payload jsonb not null default jsonb_build_object(),
|
|
14
|
+
applied_at timestamptz not null default now(),
|
|
15
|
+
constraint control_plane_projection_event_region_check
|
|
16
|
+
check (data_region in ('eu', 'us', 'ap')),
|
|
17
|
+
constraint control_plane_projection_event_version_check
|
|
18
|
+
check (event_version > 0),
|
|
19
|
+
constraint control_plane_projection_event_aggregate_version_key
|
|
20
|
+
unique (aggregate_type, aggregate_id, event_version)
|
|
21
|
+
);
|
|
22
|
+
`.execute(db);
|
|
23
|
+
|
|
24
|
+
await sql`
|
|
25
|
+
create index control_plane_projection_event_aggregate_idx
|
|
26
|
+
on public.control_plane_projection_event (
|
|
27
|
+
aggregate_type,
|
|
28
|
+
aggregate_id,
|
|
29
|
+
applied_at
|
|
30
|
+
);
|
|
31
|
+
`.execute(db);
|
|
32
|
+
|
|
33
|
+
await sql`
|
|
34
|
+
create index control_plane_projection_event_applied_at_idx
|
|
35
|
+
on public.control_plane_projection_event (applied_at);
|
|
36
|
+
`.execute(db);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
40
|
+
await sql`
|
|
41
|
+
drop table if exists public.control_plane_projection_event;
|
|
42
|
+
`.execute(db);
|
|
43
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
alter table public.tenant
|
|
7
|
+
add column guide_onboarding jsonb;
|
|
8
|
+
`.execute(db);
|
|
9
|
+
|
|
10
|
+
await sql`
|
|
11
|
+
comment on column public.tenant.guide_onboarding is
|
|
12
|
+
'JSON column for explicit VRPilot onboarding guide state.';
|
|
13
|
+
`.execute(db);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
17
|
+
await sql`
|
|
18
|
+
alter table public.tenant
|
|
19
|
+
drop column guide_onboarding;
|
|
20
|
+
`.execute(db);
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<any>): Promise<void> {
|
|
5
|
+
// tracking.event is an append-only analytics sink consumed from a queue.
|
|
6
|
+
// FKs into OLTP buy nothing here and poison whole consumer batches when a
|
|
7
|
+
// referenced tenant/user row is deleted while events are in flight.
|
|
8
|
+
await sql`
|
|
9
|
+
alter table tracking.event
|
|
10
|
+
drop constraint if exists event_tenant_id_fkey;
|
|
11
|
+
`.execute(db);
|
|
12
|
+
|
|
13
|
+
await sql`
|
|
14
|
+
alter table tracking.event
|
|
15
|
+
drop constraint if exists event_user_id_fkey;
|
|
16
|
+
`.execute(db);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
20
|
+
await sql`
|
|
21
|
+
alter table tracking.event
|
|
22
|
+
add constraint event_tenant_id_fkey
|
|
23
|
+
foreign key (tenant_id) references public.tenant(id) on delete cascade;
|
|
24
|
+
`.execute(db);
|
|
25
|
+
|
|
26
|
+
await sql`
|
|
27
|
+
alter table tracking.event
|
|
28
|
+
add constraint event_user_id_fkey
|
|
29
|
+
foreign key (user_id) references public."user"(id);
|
|
30
|
+
`.execute(db);
|
|
31
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// 'crunchy' becomes its own region: the legacy Crunchy Postgres is no longer
|
|
5
|
+
// pretending to be the eu cell. All existing tenants physically live there,
|
|
6
|
+
// so their placement flips from 'eu' to 'crunchy'; 'eu' stays a valid region
|
|
7
|
+
// for the future Neon Frankfurt cell. vrintegration tenants pin to crunchy.
|
|
8
|
+
export async function up(db: Kysely<any>): Promise<void> {
|
|
9
|
+
await sql`
|
|
10
|
+
alter table public.tenant
|
|
11
|
+
drop constraint tenant_data_region_check,
|
|
12
|
+
drop constraint tenant_vrintegration_region_check;
|
|
13
|
+
`.execute(db);
|
|
14
|
+
|
|
15
|
+
await sql`
|
|
16
|
+
update public.tenant
|
|
17
|
+
set data_region = 'crunchy'
|
|
18
|
+
where data_region = 'eu';
|
|
19
|
+
`.execute(db);
|
|
20
|
+
|
|
21
|
+
await sql`
|
|
22
|
+
alter table public.tenant
|
|
23
|
+
alter column data_region set default 'crunchy',
|
|
24
|
+
add constraint tenant_data_region_check
|
|
25
|
+
check (data_region in ('ap', 'crunchy', 'eu', 'us')),
|
|
26
|
+
add constraint tenant_vrintegration_region_check
|
|
27
|
+
check (storage_realm <> 'vrintegration' or data_region = 'crunchy');
|
|
28
|
+
`.execute(db);
|
|
29
|
+
|
|
30
|
+
await sql`
|
|
31
|
+
alter table public.control_plane_projection_event
|
|
32
|
+
drop constraint control_plane_projection_event_region_check;
|
|
33
|
+
`.execute(db);
|
|
34
|
+
|
|
35
|
+
await sql`
|
|
36
|
+
update public.control_plane_projection_event
|
|
37
|
+
set data_region = 'crunchy'
|
|
38
|
+
where data_region = 'eu';
|
|
39
|
+
`.execute(db);
|
|
40
|
+
|
|
41
|
+
await sql`
|
|
42
|
+
alter table public.control_plane_projection_event
|
|
43
|
+
add constraint control_plane_projection_event_region_check
|
|
44
|
+
check (data_region in ('ap', 'crunchy', 'eu', 'us'));
|
|
45
|
+
`.execute(db);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
49
|
+
await sql`
|
|
50
|
+
alter table public.control_plane_projection_event
|
|
51
|
+
drop constraint control_plane_projection_event_region_check;
|
|
52
|
+
`.execute(db);
|
|
53
|
+
|
|
54
|
+
await sql`
|
|
55
|
+
update public.control_plane_projection_event
|
|
56
|
+
set data_region = 'eu'
|
|
57
|
+
where data_region = 'crunchy';
|
|
58
|
+
`.execute(db);
|
|
59
|
+
|
|
60
|
+
await sql`
|
|
61
|
+
alter table public.control_plane_projection_event
|
|
62
|
+
add constraint control_plane_projection_event_region_check
|
|
63
|
+
check (data_region in ('eu', 'us', 'ap'));
|
|
64
|
+
`.execute(db);
|
|
65
|
+
|
|
66
|
+
await sql`
|
|
67
|
+
alter table public.tenant
|
|
68
|
+
drop constraint tenant_data_region_check,
|
|
69
|
+
drop constraint tenant_vrintegration_region_check;
|
|
70
|
+
`.execute(db);
|
|
71
|
+
|
|
72
|
+
await sql`
|
|
73
|
+
update public.tenant
|
|
74
|
+
set data_region = 'eu'
|
|
75
|
+
where data_region = 'crunchy';
|
|
76
|
+
`.execute(db);
|
|
77
|
+
|
|
78
|
+
await sql`
|
|
79
|
+
alter table public.tenant
|
|
80
|
+
alter column data_region set default 'eu',
|
|
81
|
+
add constraint tenant_data_region_check
|
|
82
|
+
check (data_region in ('eu', 'us', 'ap')),
|
|
83
|
+
add constraint tenant_vrintegration_region_check
|
|
84
|
+
check (storage_realm <> 'vrintegration' or data_region = 'eu');
|
|
85
|
+
`.execute(db);
|
|
86
|
+
}
|