@vrplatform/kysely 1.3.41 → 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 +368 -0
- package/build/main/control-plane/index.js +64 -0
- package/build/main/control-plane/index.js.map +1 -0
- 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 +13 -16
- package/build/main/index.js +145 -65
- package/build/main/index.js.map +1 -1
- package/build/main/isomorphic.d.ts +5 -5
- package/build/main/isomorphic.js +4 -10
- 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/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.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 +2 -12
- package/build/main/query/listing/status.js +31 -19
- 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 +60 -0
- package/build/main/regional.js +205 -0
- package/build/main/regional.js.map +1 -0
- 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 +593 -23
- 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 +368 -0
- package/build/module/control-plane/index.js +50 -0
- package/build/module/control-plane/index.js.map +1 -0
- 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 +13 -16
- package/build/module/index.js +146 -63
- 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/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/module/pganalyze-comment-plugin/index.js.map +1 -1
- 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 +2 -12
- package/build/module/query/listing/status.js +31 -17
- 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 +60 -0
- package/build/module/regional.js +162 -0
- package/build/module/regional.js.map +1 -0
- 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 +593 -23
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +18 -9
- package/build/main/tsconfig.main.tsbuildinfo +0 -1
- package/build/module/tsconfig.esm.tsbuildinfo +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
create index if not exists audit_action_created_at_idx
|
|
7
|
+
on audit.action (created_at);
|
|
8
|
+
`.execute(db);
|
|
9
|
+
await sql`
|
|
10
|
+
create index if not exists audit_mutation_created_at_idx
|
|
11
|
+
on audit.mutation (created_at)
|
|
12
|
+
where capture_order is not null;
|
|
13
|
+
`.execute(db);
|
|
14
|
+
await sql`
|
|
15
|
+
create index if not exists audit_effect_created_at_idx
|
|
16
|
+
on audit.effect (created_at);
|
|
17
|
+
`.execute(db);
|
|
18
|
+
await sql`
|
|
19
|
+
create index if not exists audit_effect_completed_at_idx
|
|
20
|
+
on audit.effect (completed_at)
|
|
21
|
+
where completed_at is not null;
|
|
22
|
+
`.execute(db);
|
|
23
|
+
await sql`
|
|
24
|
+
create index if not exists audit_effect_last_attempt_at_idx
|
|
25
|
+
on audit.effect (last_attempt_at)
|
|
26
|
+
where last_attempt_at is not null;
|
|
27
|
+
`.execute(db);
|
|
28
|
+
await sql`
|
|
29
|
+
create index if not exists audit_journal_delta_changed_at_idx
|
|
30
|
+
on audit.journal_delta (changed_at);
|
|
31
|
+
`.execute(db);
|
|
32
|
+
|
|
33
|
+
const indexes = await sql<{ count: number }>`
|
|
34
|
+
select count(*)::int as count
|
|
35
|
+
from pg_index i
|
|
36
|
+
inner join pg_class c on c.oid = i.indexrelid
|
|
37
|
+
inner join pg_namespace n on n.oid = c.relnamespace
|
|
38
|
+
where n.nspname = 'audit'
|
|
39
|
+
and c.relname in (
|
|
40
|
+
'audit_action_created_at_idx',
|
|
41
|
+
'audit_mutation_created_at_idx',
|
|
42
|
+
'audit_effect_created_at_idx',
|
|
43
|
+
'audit_effect_completed_at_idx',
|
|
44
|
+
'audit_effect_last_attempt_at_idx',
|
|
45
|
+
'audit_journal_delta_changed_at_idx'
|
|
46
|
+
)
|
|
47
|
+
and i.indisvalid
|
|
48
|
+
and i.indisready
|
|
49
|
+
and i.indislive
|
|
50
|
+
`.execute(db);
|
|
51
|
+
if (Number(indexes.rows[0]?.count) !== 6) {
|
|
52
|
+
throw new Error('Audit recovery indexes are unavailable');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
57
|
+
await sql`drop index audit.audit_journal_delta_changed_at_idx;`.execute(db);
|
|
58
|
+
await sql`drop index audit.audit_effect_last_attempt_at_idx;`.execute(db);
|
|
59
|
+
await sql`drop index audit.audit_effect_completed_at_idx;`.execute(db);
|
|
60
|
+
await sql`drop index audit.audit_effect_created_at_idx;`.execute(db);
|
|
61
|
+
await sql`drop index audit.audit_mutation_created_at_idx;`.execute(db);
|
|
62
|
+
await sql`drop index audit.audit_action_created_at_idx;`.execute(db);
|
|
63
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 = '180s';`.execute(db);
|
|
6
|
+
await sql`set local statement_timeout = '240s';`.execute(db);
|
|
7
|
+
await sql`
|
|
8
|
+
select pg_advisory_xact_lock(
|
|
9
|
+
hashtextextended('public_audit_event_recovery', 0)
|
|
10
|
+
);
|
|
11
|
+
`.execute(db);
|
|
12
|
+
await sql`
|
|
13
|
+
alter table audit.action
|
|
14
|
+
add column public_event_projected_at timestamptz default null;
|
|
15
|
+
`.execute(db);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
19
|
+
await sql`
|
|
20
|
+
alter table audit.action drop column public_event_projected_at;
|
|
21
|
+
`.execute(db);
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 = '180s';`.execute(db);
|
|
6
|
+
await sql`set local statement_timeout = '240s';`.execute(db);
|
|
7
|
+
await sql`
|
|
8
|
+
select pg_advisory_xact_lock(
|
|
9
|
+
hashtextextended('public_audit_event_recovery', 0)
|
|
10
|
+
);
|
|
11
|
+
`.execute(db);
|
|
12
|
+
await sql`
|
|
13
|
+
update audit.action as action
|
|
14
|
+
set public_event_projected_at = event.projected_at
|
|
15
|
+
from (
|
|
16
|
+
select tenant_id, action_id, max(projected_at) as projected_at
|
|
17
|
+
from audit.public_event
|
|
18
|
+
group by tenant_id, action_id
|
|
19
|
+
) as event
|
|
20
|
+
where action.tenant_id = event.tenant_id
|
|
21
|
+
and action.id = event.action_id
|
|
22
|
+
and action.public_event_projected_at is null
|
|
23
|
+
and action.created_at >= (
|
|
24
|
+
select cutover_at
|
|
25
|
+
from audit.public_event_projection_state
|
|
26
|
+
where singleton = true
|
|
27
|
+
);
|
|
28
|
+
`.execute(db);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
32
|
+
await sql`
|
|
33
|
+
update audit.action set public_event_projected_at = null;
|
|
34
|
+
`.execute(db);
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
alter table core.sync
|
|
8
|
+
drop constraint if exists sync_user_id_fkey
|
|
9
|
+
`.execute(db);
|
|
10
|
+
await sql`
|
|
11
|
+
alter table public.audit_log
|
|
12
|
+
drop constraint if exists audit_log_actor_user_id_fkey
|
|
13
|
+
`.execute(db);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await sql`
|
|
18
|
+
alter table core.sync
|
|
19
|
+
add constraint sync_user_id_fkey
|
|
20
|
+
foreign key (user_id)
|
|
21
|
+
references public."user"(id)
|
|
22
|
+
on update restrict
|
|
23
|
+
on delete set null
|
|
24
|
+
`.execute(db);
|
|
25
|
+
await sql`
|
|
26
|
+
alter table public.audit_log
|
|
27
|
+
add constraint audit_log_actor_user_id_fkey
|
|
28
|
+
foreign key (actor_user_id)
|
|
29
|
+
references public."user"(id)
|
|
30
|
+
on update restrict
|
|
31
|
+
on delete set null
|
|
32
|
+
`.execute(db);
|
|
33
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
create table health.tenant_issue_rule_state (
|
|
7
|
+
tenant_id uuid not null
|
|
8
|
+
references public.tenant(id) on delete cascade,
|
|
9
|
+
code health.tenant_issue_code not null,
|
|
10
|
+
dirty_at timestamptz not null,
|
|
11
|
+
computed_at timestamptz,
|
|
12
|
+
dirty_version bigint not null default 1,
|
|
13
|
+
computed_version bigint not null default 0,
|
|
14
|
+
created_at timestamptz not null default now(),
|
|
15
|
+
updated_at timestamptz not null default now(),
|
|
16
|
+
primary key (tenant_id, code)
|
|
17
|
+
);
|
|
18
|
+
`.execute(db);
|
|
19
|
+
await sql`
|
|
20
|
+
create index tenant_issue_rule_state_dirty_idx
|
|
21
|
+
on health.tenant_issue_rule_state (dirty_at, tenant_id, code)
|
|
22
|
+
where dirty_version > computed_version;
|
|
23
|
+
`.execute(db);
|
|
24
|
+
await sql`
|
|
25
|
+
insert into health.tenant_issue_rule_state (
|
|
26
|
+
tenant_id,
|
|
27
|
+
code,
|
|
28
|
+
dirty_at,
|
|
29
|
+
computed_at,
|
|
30
|
+
computed_version,
|
|
31
|
+
created_at,
|
|
32
|
+
updated_at
|
|
33
|
+
)
|
|
34
|
+
select
|
|
35
|
+
snapshot.tenant_id,
|
|
36
|
+
code,
|
|
37
|
+
snapshot.dirty_at,
|
|
38
|
+
snapshot.computed_at,
|
|
39
|
+
case
|
|
40
|
+
when snapshot.computed_at >= snapshot.dirty_at then 1
|
|
41
|
+
else 0
|
|
42
|
+
end,
|
|
43
|
+
snapshot.created_at,
|
|
44
|
+
snapshot.updated_at
|
|
45
|
+
from health.tenant_issue_snapshot as snapshot
|
|
46
|
+
cross join unnest(enum_range(null::health.tenant_issue_code)) as code;
|
|
47
|
+
`.execute(db);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
51
|
+
await sql`drop table health.tenant_issue_rule_state;`.execute(db);
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
create table health.reservation_issue_snapshot (
|
|
7
|
+
reservation_id uuid primary key
|
|
8
|
+
references public.reservation(id) on delete cascade,
|
|
9
|
+
tenant_id uuid not null references public.tenant(id) on delete cascade,
|
|
10
|
+
version bigint not null default 0,
|
|
11
|
+
issues jsonb not null default '[]'::jsonb,
|
|
12
|
+
dirty_version bigint not null default 1,
|
|
13
|
+
computed_version bigint not null default 0,
|
|
14
|
+
dirty_at timestamptz not null default now(),
|
|
15
|
+
computed_at timestamptz,
|
|
16
|
+
created_at timestamptz not null default now(),
|
|
17
|
+
updated_at timestamptz not null default now(),
|
|
18
|
+
constraint reservation_issue_snapshot_version_check check (version >= 0),
|
|
19
|
+
constraint reservation_issue_snapshot_dirty_version_check
|
|
20
|
+
check (dirty_version >= 0),
|
|
21
|
+
constraint reservation_issue_snapshot_computed_version_check
|
|
22
|
+
check (computed_version >= 0)
|
|
23
|
+
);
|
|
24
|
+
`.execute(db);
|
|
25
|
+
|
|
26
|
+
await sql`
|
|
27
|
+
create index reservation_issue_snapshot_tenant_idx
|
|
28
|
+
on health.reservation_issue_snapshot (tenant_id, reservation_id);
|
|
29
|
+
`.execute(db);
|
|
30
|
+
|
|
31
|
+
await sql`
|
|
32
|
+
create index reservation_issue_snapshot_reconciliation_idx
|
|
33
|
+
on health.reservation_issue_snapshot (
|
|
34
|
+
((dirty_version > computed_version)::int) desc,
|
|
35
|
+
computed_at,
|
|
36
|
+
reservation_id
|
|
37
|
+
);
|
|
38
|
+
`.execute(db);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
42
|
+
await sql`drop table if exists health.reservation_issue_snapshot;`.execute(
|
|
43
|
+
db
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -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`
|
|
6
|
+
alter table accounting.bank_rule_application
|
|
7
|
+
drop constraint bank_rule_application_bank_record_id_fkey,
|
|
8
|
+
add constraint bank_rule_application_bank_record_id_fkey
|
|
9
|
+
foreign key (bank_record_id)
|
|
10
|
+
references accounting.bank_record(id)
|
|
11
|
+
on update restrict
|
|
12
|
+
on delete cascade
|
|
13
|
+
`.execute(db);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await sql`
|
|
18
|
+
alter table accounting.bank_rule_application
|
|
19
|
+
drop constraint bank_rule_application_bank_record_id_fkey,
|
|
20
|
+
add constraint bank_rule_application_bank_record_id_fkey
|
|
21
|
+
foreign key (bank_record_id)
|
|
22
|
+
references accounting.bank_record(id)
|
|
23
|
+
on update restrict
|
|
24
|
+
on delete restrict
|
|
25
|
+
`.execute(db);
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
6
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
7
|
+
|
|
8
|
+
await sql`
|
|
9
|
+
create index if not exists
|
|
10
|
+
journal_entry_transaction_reservation_tenant_idx
|
|
11
|
+
on accounting.journal_entry (
|
|
12
|
+
transaction_id,
|
|
13
|
+
reservation_id,
|
|
14
|
+
tenant_id
|
|
15
|
+
)
|
|
16
|
+
where transaction_id is not null
|
|
17
|
+
`.execute(db);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
21
|
+
await sql`
|
|
22
|
+
drop index if exists
|
|
23
|
+
accounting.journal_entry_transaction_reservation_tenant_idx
|
|
24
|
+
`.execute(db);
|
|
25
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await sql`
|
|
5
|
+
create or replace function public.tenant_calculated_analytics_billing_status(
|
|
6
|
+
row_t public.tenant
|
|
7
|
+
) returns text
|
|
8
|
+
language sql stable
|
|
9
|
+
as $$
|
|
10
|
+
with norm as (
|
|
11
|
+
select
|
|
12
|
+
lower(nullif(row_t.billing_subscription_status, '')) as sub_status,
|
|
13
|
+
nullif(trim(row_t.billing_payment_method_type), '') as pm_type,
|
|
14
|
+
coalesce(row_t.is_onboarding, false) as is_onboarding
|
|
15
|
+
)
|
|
16
|
+
select
|
|
17
|
+
case
|
|
18
|
+
when sub_status in ('cancelled', 'voided') then 'cancelled'
|
|
19
|
+
when sub_status = 'errored' then 'errored'
|
|
20
|
+
when is_onboarding then 'onboarding'
|
|
21
|
+
when sub_status is null then 'partner'
|
|
22
|
+
when sub_status = 'draft' then 'pending'
|
|
23
|
+
when sub_status = 'active' and pm_type is null then 'pending'
|
|
24
|
+
when sub_status = 'active' and pm_type is not null then 'active'
|
|
25
|
+
else 'unknown'
|
|
26
|
+
end
|
|
27
|
+
from norm;
|
|
28
|
+
$$;
|
|
29
|
+
`.execute(db);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
33
|
+
await sql`
|
|
34
|
+
create or replace function public.tenant_calculated_analytics_billing_status(
|
|
35
|
+
row_t public.tenant
|
|
36
|
+
) returns text
|
|
37
|
+
language sql stable
|
|
38
|
+
as $$
|
|
39
|
+
with norm as (
|
|
40
|
+
select
|
|
41
|
+
lower(nullif(row_t.billing_subscription_status, '')) as sub_status,
|
|
42
|
+
nullif(trim(row_t.billing_payment_method_type), '') as pm_type,
|
|
43
|
+
row_t.trial_until as trial_until_date,
|
|
44
|
+
coalesce(row_t.is_onboarding, false) as is_onboarding
|
|
45
|
+
),
|
|
46
|
+
flags as (
|
|
47
|
+
select
|
|
48
|
+
trial_until_date is not null
|
|
49
|
+
and trial_until_date > current_date as trial_active,
|
|
50
|
+
sub_status,
|
|
51
|
+
pm_type,
|
|
52
|
+
is_onboarding
|
|
53
|
+
from norm
|
|
54
|
+
)
|
|
55
|
+
select
|
|
56
|
+
case
|
|
57
|
+
when sub_status in ('cancelled', 'voided') then 'cancelled'
|
|
58
|
+
when sub_status = 'errored' then 'errored'
|
|
59
|
+
when is_onboarding then 'onboarding'
|
|
60
|
+
when sub_status is null then 'partner'
|
|
61
|
+
when sub_status = 'draft' then 'pending'
|
|
62
|
+
when sub_status = 'active' and trial_active then 'trial'
|
|
63
|
+
when sub_status = 'active'
|
|
64
|
+
and not trial_active
|
|
65
|
+
and pm_type is null then 'pending'
|
|
66
|
+
when sub_status = 'active' and pm_type is not null then 'active'
|
|
67
|
+
else 'unknown'
|
|
68
|
+
end
|
|
69
|
+
from flags;
|
|
70
|
+
$$;
|
|
71
|
+
`.execute(db);
|
|
72
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
alter table public.tenant
|
|
8
|
+
add column partner_denied_permissions text[] not null default '{}'
|
|
9
|
+
`.execute(db);
|
|
10
|
+
await sql`
|
|
11
|
+
alter table public.tenant_user
|
|
12
|
+
add column permission_bundles text[] not null default '{}'
|
|
13
|
+
`.execute(db);
|
|
14
|
+
await sql`
|
|
15
|
+
alter table public.tenant_user
|
|
16
|
+
disable trigger set_public_tenant_user_updated_at
|
|
17
|
+
`.execute(db);
|
|
18
|
+
await sql`
|
|
19
|
+
update public.tenant_user as tenant_user
|
|
20
|
+
set permission_bundles = case
|
|
21
|
+
when tenant_user.role = 'admin' and tenant.type = 'partner'
|
|
22
|
+
then array['ui:team-admin:v1', 'ui:partner-admin:v1']::text[]
|
|
23
|
+
when tenant_user.role = 'admin'
|
|
24
|
+
then array['ui:team-admin:v1']::text[]
|
|
25
|
+
when tenant_user.role = 'user'
|
|
26
|
+
then array['ui:accounting:v1']::text[]
|
|
27
|
+
else array[]::text[]
|
|
28
|
+
end
|
|
29
|
+
from public.tenant as tenant
|
|
30
|
+
where tenant.id = tenant_user.tenant_id
|
|
31
|
+
`.execute(db);
|
|
32
|
+
await sql`
|
|
33
|
+
alter table public.tenant_user
|
|
34
|
+
enable trigger set_public_tenant_user_updated_at
|
|
35
|
+
`.execute(db);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
39
|
+
await sql`
|
|
40
|
+
alter table public.tenant_user drop column permission_bundles
|
|
41
|
+
`.execute(db);
|
|
42
|
+
await sql`
|
|
43
|
+
alter table public.tenant drop column partner_denied_permissions
|
|
44
|
+
`.execute(db);
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
alter table public.tenant_user
|
|
8
|
+
disable trigger set_public_tenant_user_updated_at
|
|
9
|
+
`.execute(db);
|
|
10
|
+
await sql`
|
|
11
|
+
update public.tenant_user as tenant_user
|
|
12
|
+
set permission_bundles = case
|
|
13
|
+
when tenant_user.role = 'admin' and tenant.type = 'partner'
|
|
14
|
+
then array['ui:team-admin:v1', 'ui:partner-admin:v1']::text[]
|
|
15
|
+
when tenant_user.role = 'admin'
|
|
16
|
+
then array['ui:team-admin:v1']::text[]
|
|
17
|
+
when tenant_user.role = 'user'
|
|
18
|
+
then array['ui:accounting:v1']::text[]
|
|
19
|
+
else tenant_user.permission_bundles
|
|
20
|
+
end
|
|
21
|
+
from public.tenant as tenant
|
|
22
|
+
where tenant.id = tenant_user.tenant_id
|
|
23
|
+
and cardinality(tenant_user.permission_bundles) = 0
|
|
24
|
+
and tenant_user.role in ('admin', 'user')
|
|
25
|
+
`.execute(db);
|
|
26
|
+
await sql`
|
|
27
|
+
alter table public.tenant_user
|
|
28
|
+
enable trigger set_public_tenant_user_updated_at
|
|
29
|
+
`.execute(db);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function down(_db: Kysely<unknown>): Promise<void> {}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
alter table public.tenant_user
|
|
8
|
+
add column managed_team_access text not null default 'assigned',
|
|
9
|
+
add constraint tenant_user_managed_team_access_check
|
|
10
|
+
check (managed_team_access in ('all', 'assigned'))
|
|
11
|
+
`.execute(db);
|
|
12
|
+
await sql`
|
|
13
|
+
alter table public.tenant_user
|
|
14
|
+
disable trigger set_public_tenant_user_updated_at
|
|
15
|
+
`.execute(db);
|
|
16
|
+
await sql`
|
|
17
|
+
update public.tenant_user as tenant_user
|
|
18
|
+
set managed_team_access = 'all'
|
|
19
|
+
from public.tenant as tenant
|
|
20
|
+
where tenant.id = tenant_user.tenant_id
|
|
21
|
+
and tenant.type = 'partner'
|
|
22
|
+
and tenant_user.role = 'admin'
|
|
23
|
+
`.execute(db);
|
|
24
|
+
await sql`
|
|
25
|
+
alter table public.tenant_user
|
|
26
|
+
enable trigger set_public_tenant_user_updated_at
|
|
27
|
+
`.execute(db);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
31
|
+
await sql`
|
|
32
|
+
alter table public.tenant_user drop column managed_team_access
|
|
33
|
+
`.execute(db);
|
|
34
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Kysely, sql } from 'kysely';
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await sql`
|
|
5
|
+
do $$
|
|
6
|
+
declare
|
|
7
|
+
definition text;
|
|
8
|
+
trigger_function regprocedure;
|
|
9
|
+
begin
|
|
10
|
+
for trigger_function in
|
|
11
|
+
select distinct p.oid::regprocedure
|
|
12
|
+
from pg_trigger as t
|
|
13
|
+
inner join pg_proc as p on p.oid = t.tgfoid
|
|
14
|
+
where t.tgrelid = 'public.tenant'::regclass
|
|
15
|
+
and not t.tgisinternal
|
|
16
|
+
and p.prosrc ilike '%trial_until%'
|
|
17
|
+
loop
|
|
18
|
+
definition := pg_get_functiondef(trigger_function);
|
|
19
|
+
definition := replace(definition, 'OLD."trial_until" , ', '');
|
|
20
|
+
definition := replace(definition, 'NEW."trial_until" , ', '');
|
|
21
|
+
|
|
22
|
+
if definition ilike '%trial_until%' then
|
|
23
|
+
raise exception
|
|
24
|
+
'Could not remove trial_until from tenant trigger function %',
|
|
25
|
+
trigger_function;
|
|
26
|
+
end if;
|
|
27
|
+
|
|
28
|
+
execute definition;
|
|
29
|
+
end loop;
|
|
30
|
+
end;
|
|
31
|
+
$$;
|
|
32
|
+
`.execute(db);
|
|
33
|
+
await sql`
|
|
34
|
+
alter table public.tenant drop column if exists trial_until
|
|
35
|
+
`.execute(db);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
39
|
+
await sql`
|
|
40
|
+
alter table public.tenant add column trial_until date
|
|
41
|
+
`.execute(db);
|
|
42
|
+
}
|