@vrplatform/kysely 1.3.45-40371378523 → 1.3.45-40394938404
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.
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// PRO-19885: authentication reads tokens only from control_plane.token. The
|
|
5
|
+
// regional table has no reader or writer left. Crunchy keeps its frozen copy:
|
|
6
|
+
// it is the only database that holds VRIntegrations teams, and the only one
|
|
7
|
+
// where the baseline partner is not the sole team with that realm. Dropped
|
|
8
|
+
// without cascade, so a missed dependency fails the migration.
|
|
9
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
10
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
11
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
12
|
+
|
|
13
|
+
const holdsVrIntegrationTeams = await sql<{ holds: boolean }>`
|
|
14
|
+
select exists (
|
|
15
|
+
select 1
|
|
16
|
+
from public.tenant
|
|
17
|
+
where storage_realm = 'vrintegration'
|
|
18
|
+
and id <> 'd6ab2bbe-e0fc-48d9-89a3-c3c05f4e79b5'
|
|
19
|
+
) as holds
|
|
20
|
+
`.execute(db);
|
|
21
|
+
if (holdsVrIntegrationTeams.rows[0]?.holds) return;
|
|
22
|
+
|
|
23
|
+
await sql`drop table public.token`.execute(db);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Recreates the empty table as the baseline defined it. Rows are not restored.
|
|
27
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
28
|
+
await sql`
|
|
29
|
+
create table if not exists public.token (
|
|
30
|
+
id text primary key default gen_random_uuid(),
|
|
31
|
+
payload jsonb not null default jsonb_build_object(),
|
|
32
|
+
created_at timestamptz not null default now(),
|
|
33
|
+
expires_at timestamptz,
|
|
34
|
+
type text,
|
|
35
|
+
nano_id text not null default gen_random_uuid(),
|
|
36
|
+
tenant_id uuid references public.tenant (id)
|
|
37
|
+
on update restrict on delete set null,
|
|
38
|
+
user_id uuid references public."user" (id)
|
|
39
|
+
on update restrict on delete set null
|
|
40
|
+
)
|
|
41
|
+
`.execute(db);
|
|
42
|
+
await sql`
|
|
43
|
+
create index if not exists token_id_type_idx on public.token (id, type)
|
|
44
|
+
`.execute(db);
|
|
45
|
+
await sql`
|
|
46
|
+
create index if not exists token_nano_id_idx on public.token (nano_id)
|
|
47
|
+
`.execute(db);
|
|
48
|
+
await sql`
|
|
49
|
+
create unique index if not exists token_partner_secret_unique_idx
|
|
50
|
+
on public.token (nano_id)
|
|
51
|
+
where type = any (array['partner_api_key', 'embedded_bootstrap'])
|
|
52
|
+
`.execute(db);
|
|
53
|
+
await sql`
|
|
54
|
+
create index if not exists token_tenant_id_id_type_idx
|
|
55
|
+
on public.token (tenant_id, id, type)
|
|
56
|
+
`.execute(db);
|
|
57
|
+
await sql`
|
|
58
|
+
create index if not exists token_tenant_id_key on public.token (tenant_id)
|
|
59
|
+
`.execute(db);
|
|
60
|
+
}
|