@vrplatform/kysely 1.3.41-stage.4236 → 1.3.41-stage.4237
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,100 @@
|
|
|
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
|
+
}
|