@vrplatform/kysely 1.3.45-4699 → 1.3.45-4719
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Kysely } from 'kysely';
|
|
2
2
|
import { sql } from 'kysely';
|
|
3
3
|
|
|
4
|
-
export async function
|
|
4
|
+
export async function backfillCanonicalJsonbShapes(
|
|
5
|
+
db: Kysely<unknown>
|
|
6
|
+
): Promise<void> {
|
|
5
7
|
await sql`
|
|
6
8
|
update public.connection
|
|
7
9
|
set credentials = (credentials #>> '{}')::jsonb
|
|
@@ -33,46 +35,175 @@ export async function up(db: Kysely<unknown>): Promise<void> {
|
|
|
33
35
|
set payload = (payload #>> '{}')::jsonb
|
|
34
36
|
where jsonb_typeof(payload) = 'string'
|
|
35
37
|
`.execute(db);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const canonicalJsonbShapeConstraintTargets = [
|
|
41
|
+
'connection',
|
|
42
|
+
'feature',
|
|
43
|
+
'transaction',
|
|
44
|
+
'source',
|
|
45
|
+
'ownerStatementProjection',
|
|
46
|
+
] as const;
|
|
47
|
+
|
|
48
|
+
type CanonicalJsonbShapeConstraintTarget =
|
|
49
|
+
(typeof canonicalJsonbShapeConstraintTargets)[number];
|
|
50
|
+
|
|
51
|
+
export async function addCanonicalJsonbShapeConstraints(
|
|
52
|
+
db: Kysely<unknown>,
|
|
53
|
+
target: CanonicalJsonbShapeConstraintTarget
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
if (target === 'connection') {
|
|
56
|
+
await sql`
|
|
57
|
+
do $$
|
|
58
|
+
begin
|
|
59
|
+
if not exists (
|
|
60
|
+
select 1 from pg_constraint
|
|
61
|
+
where conname = 'connection_credentials_object_check'
|
|
62
|
+
and conrelid = 'public.connection'::regclass
|
|
63
|
+
) then
|
|
64
|
+
alter table public.connection
|
|
65
|
+
add constraint connection_credentials_object_check
|
|
66
|
+
check (
|
|
67
|
+
credentials is null
|
|
68
|
+
or jsonb_typeof(credentials) = 'object'
|
|
69
|
+
) not valid;
|
|
70
|
+
end if;
|
|
71
|
+
if not exists (
|
|
72
|
+
select 1 from pg_constraint
|
|
73
|
+
where conname = 'connection_persistent_state_object_check'
|
|
74
|
+
and conrelid = 'public.connection'::regclass
|
|
75
|
+
) then
|
|
76
|
+
alter table public.connection
|
|
77
|
+
add constraint connection_persistent_state_object_check
|
|
78
|
+
check (
|
|
79
|
+
persistent_state is null
|
|
80
|
+
or jsonb_typeof(persistent_state) = 'object'
|
|
81
|
+
) not valid;
|
|
82
|
+
end if;
|
|
83
|
+
end
|
|
84
|
+
$$
|
|
85
|
+
`.execute(db);
|
|
86
|
+
} else if (target === 'feature') {
|
|
87
|
+
await sql`
|
|
88
|
+
do $$
|
|
89
|
+
begin
|
|
90
|
+
if not exists (
|
|
91
|
+
select 1 from pg_constraint
|
|
92
|
+
where conname = 'feature_required_approvals_array_check'
|
|
93
|
+
and conrelid = 'public.feature'::regclass
|
|
94
|
+
) then
|
|
95
|
+
alter table public.feature
|
|
96
|
+
add constraint feature_required_approvals_array_check
|
|
97
|
+
check (
|
|
98
|
+
required_approvals is null
|
|
99
|
+
or jsonb_typeof(required_approvals) = 'array'
|
|
100
|
+
) not valid;
|
|
101
|
+
end if;
|
|
102
|
+
end
|
|
103
|
+
$$
|
|
104
|
+
`.execute(db);
|
|
105
|
+
} else if (target === 'transaction') {
|
|
106
|
+
await sql`
|
|
107
|
+
do $$
|
|
108
|
+
begin
|
|
109
|
+
if not exists (
|
|
110
|
+
select 1 from pg_constraint
|
|
111
|
+
where conname = 'transaction_recurring_pattern_object_check'
|
|
112
|
+
and conrelid = 'accounting.transaction'::regclass
|
|
113
|
+
) then
|
|
114
|
+
alter table accounting.transaction
|
|
115
|
+
add constraint transaction_recurring_pattern_object_check
|
|
116
|
+
check (
|
|
117
|
+
recurring_pattern is null
|
|
118
|
+
or jsonb_typeof(recurring_pattern) = 'object'
|
|
119
|
+
) not valid;
|
|
120
|
+
end if;
|
|
121
|
+
end
|
|
122
|
+
$$
|
|
123
|
+
`.execute(db);
|
|
124
|
+
} else if (target === 'source') {
|
|
125
|
+
await sql`
|
|
126
|
+
do $$
|
|
127
|
+
begin
|
|
128
|
+
if not exists (
|
|
129
|
+
select 1 from pg_constraint
|
|
130
|
+
where conname = 'source_owner_statement_json_object_check'
|
|
131
|
+
and conrelid = 'public.source'::regclass
|
|
132
|
+
) then
|
|
133
|
+
alter table public.source
|
|
134
|
+
add constraint source_owner_statement_json_object_check
|
|
135
|
+
check (
|
|
136
|
+
type <> 'ownerStatement'
|
|
137
|
+
or json is null
|
|
138
|
+
or jsonb_typeof(json) = 'object'
|
|
139
|
+
) not valid;
|
|
140
|
+
end if;
|
|
141
|
+
end
|
|
142
|
+
$$
|
|
143
|
+
`.execute(db);
|
|
144
|
+
} else {
|
|
145
|
+
await sql`
|
|
146
|
+
do $$
|
|
147
|
+
begin
|
|
148
|
+
if not exists (
|
|
149
|
+
select 1 from pg_constraint
|
|
150
|
+
where conname = 'owner_statement_projection_payload_container_check'
|
|
151
|
+
and conrelid = 'accounting.owner_statement_projection'::regclass
|
|
152
|
+
) then
|
|
153
|
+
alter table accounting.owner_statement_projection
|
|
154
|
+
add constraint owner_statement_projection_payload_container_check
|
|
155
|
+
check (jsonb_typeof(payload) in ('array', 'object')) not valid;
|
|
156
|
+
end if;
|
|
157
|
+
end
|
|
158
|
+
$$
|
|
159
|
+
`.execute(db);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function validateCanonicalJsonbShapeConstraints(
|
|
164
|
+
db: Kysely<unknown>,
|
|
165
|
+
target: CanonicalJsonbShapeConstraintTarget
|
|
166
|
+
): Promise<void> {
|
|
167
|
+
if (target === 'connection') {
|
|
168
|
+
await sql`
|
|
169
|
+
alter table public.connection
|
|
170
|
+
validate constraint connection_credentials_object_check
|
|
171
|
+
`.execute(db);
|
|
172
|
+
await sql`
|
|
173
|
+
alter table public.connection
|
|
174
|
+
validate constraint connection_persistent_state_object_check
|
|
175
|
+
`.execute(db);
|
|
176
|
+
} else if (target === 'feature') {
|
|
177
|
+
await sql`
|
|
178
|
+
alter table public.feature
|
|
179
|
+
validate constraint feature_required_approvals_array_check
|
|
180
|
+
`.execute(db);
|
|
181
|
+
} else if (target === 'transaction') {
|
|
182
|
+
await sql`
|
|
183
|
+
alter table accounting.transaction
|
|
184
|
+
validate constraint transaction_recurring_pattern_object_check
|
|
185
|
+
`.execute(db);
|
|
186
|
+
} else if (target === 'source') {
|
|
187
|
+
await sql`
|
|
188
|
+
alter table public.source
|
|
189
|
+
validate constraint source_owner_statement_json_object_check
|
|
190
|
+
`.execute(db);
|
|
191
|
+
} else {
|
|
192
|
+
await sql`
|
|
193
|
+
alter table accounting.owner_statement_projection
|
|
194
|
+
validate constraint owner_statement_projection_payload_container_check
|
|
195
|
+
`.execute(db);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
200
|
+
await backfillCanonicalJsonbShapes(db);
|
|
201
|
+
for (const target of canonicalJsonbShapeConstraintTargets) {
|
|
202
|
+
await addCanonicalJsonbShapeConstraints(db, target);
|
|
203
|
+
}
|
|
204
|
+
for (const target of canonicalJsonbShapeConstraintTargets) {
|
|
205
|
+
await validateCanonicalJsonbShapeConstraints(db, target);
|
|
206
|
+
}
|
|
76
207
|
}
|
|
77
208
|
|
|
78
209
|
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
@@ -0,0 +1,20 @@
|
|
|
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 flow_mapping_source_id_idx
|
|
7
|
+
on core.flow_mapping (source_id)
|
|
8
|
+
`.execute(db);
|
|
9
|
+
await sql`
|
|
10
|
+
create index file_storage_source_link_source_id_idx
|
|
11
|
+
on public.file_storage_source_link (source_id)
|
|
12
|
+
`.execute(db);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
16
|
+
await sql`
|
|
17
|
+
drop index public.file_storage_source_link_source_id_idx
|
|
18
|
+
`.execute(db);
|
|
19
|
+
await sql`drop index core.flow_mapping_source_id_idx`.execute(db);
|
|
20
|
+
}
|