@query-doctor/core 0.8.9 → 0.10.0

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.
Files changed (57) hide show
  1. package/dist/index.cjs +21 -1
  2. package/dist/index.d.cts +8 -5
  3. package/dist/index.d.mts +8 -5
  4. package/dist/index.mjs +5 -3
  5. package/dist/optimizer/genalgo.cjs +5 -5
  6. package/dist/optimizer/genalgo.cjs.map +1 -1
  7. package/dist/optimizer/genalgo.d.cts +6 -5
  8. package/dist/optimizer/genalgo.d.cts.map +1 -1
  9. package/dist/optimizer/genalgo.d.mts +6 -5
  10. package/dist/optimizer/genalgo.d.mts.map +1 -1
  11. package/dist/optimizer/genalgo.mjs +5 -5
  12. package/dist/optimizer/genalgo.mjs.map +1 -1
  13. package/dist/optimizer/statistics.cjs +1 -61
  14. package/dist/optimizer/statistics.cjs.map +1 -1
  15. package/dist/optimizer/statistics.d.cts +1 -20
  16. package/dist/optimizer/statistics.d.cts.map +1 -1
  17. package/dist/optimizer/statistics.d.mts +1 -20
  18. package/dist/optimizer/statistics.d.mts.map +1 -1
  19. package/dist/optimizer/statistics.mjs +1 -61
  20. package/dist/optimizer/statistics.mjs.map +1 -1
  21. package/dist/query.cjs +33 -0
  22. package/dist/query.cjs.map +1 -0
  23. package/dist/query.d.cts +105 -0
  24. package/dist/query.d.cts.map +1 -0
  25. package/dist/query.d.mts +105 -0
  26. package/dist/query.d.mts.map +1 -0
  27. package/dist/query.mjs +31 -0
  28. package/dist/query.mjs.map +1 -0
  29. package/dist/schema-dump.cjs +365 -0
  30. package/dist/schema-dump.cjs.map +1 -0
  31. package/dist/schema-dump.mjs +365 -0
  32. package/dist/schema-dump.mjs.map +1 -0
  33. package/dist/schema.cjs +172 -0
  34. package/dist/schema.cjs.map +1 -0
  35. package/dist/schema.d.cts +352 -0
  36. package/dist/schema.d.cts.map +1 -0
  37. package/dist/schema.d.mts +352 -0
  38. package/dist/schema.d.mts.map +1 -0
  39. package/dist/schema.mjs +157 -0
  40. package/dist/schema.mjs.map +1 -0
  41. package/dist/sql/database.d.cts +1 -1
  42. package/dist/sql/database.d.mts +1 -1
  43. package/dist/sql/indexes.cjs +51 -2
  44. package/dist/sql/indexes.cjs.map +1 -1
  45. package/dist/sql/indexes.d.cts +20 -4
  46. package/dist/sql/indexes.d.cts.map +1 -1
  47. package/dist/sql/indexes.d.mts +20 -4
  48. package/dist/sql/indexes.d.mts.map +1 -1
  49. package/dist/sql/indexes.mjs +51 -3
  50. package/dist/sql/indexes.mjs.map +1 -1
  51. package/dist/sql/walker.cjs +1 -1
  52. package/dist/sql/walker.mjs +1 -1
  53. package/dist/websocket-server.d.cts +68 -0
  54. package/dist/websocket-server.d.cts.map +1 -0
  55. package/dist/websocket-server.d.mts +68 -0
  56. package/dist/websocket-server.d.mts.map +1 -0
  57. package/package.json +4 -2
@@ -0,0 +1,352 @@
1
+ 'use client';
2
+
3
+ import { PgIdentifier } from "./sql/pg-identifier.mjs";
4
+ import { Postgres } from "./sql/database.mjs";
5
+ import { z } from "zod";
6
+
7
+ //#region src/schema.d.ts
8
+ declare const FullSchemaKeyColumn: z.ZodObject<{
9
+ type: z.ZodLiteral<"indexColumn">;
10
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
11
+ order: z.ZodOptional<z.ZodEnum<{
12
+ ASC: "ASC";
13
+ DESC: "DESC";
14
+ }>>;
15
+ nulls: z.ZodOptional<z.ZodEnum<{
16
+ FIRST: "FIRST";
17
+ LAST: "LAST";
18
+ }>>;
19
+ opclass: z.ZodOptional<z.ZodString>;
20
+ collation: z.ZodOptional<z.ZodString>;
21
+ }, z.core.$strip>;
22
+ type FullSchemaKeyColumn = z.infer<typeof FullSchemaKeyColumn>;
23
+ declare const FullSchemaIncludedColumn: z.ZodObject<{
24
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
25
+ }, z.core.$strip>;
26
+ type FullSchemaIncludedColumn = z.infer<typeof FullSchemaIncludedColumn>;
27
+ declare const FullSchemaIndex: z.ZodObject<{
28
+ type: z.ZodLiteral<"index">;
29
+ oid: z.ZodNumber;
30
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
31
+ tableName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
32
+ indexName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
33
+ indexType: z.ZodString;
34
+ isUnique: z.ZodBoolean;
35
+ isPrimary: z.ZodBoolean;
36
+ isClustered: z.ZodBoolean;
37
+ wherePredicate: z.ZodOptional<z.ZodString>;
38
+ tablespace: z.ZodOptional<z.ZodString>;
39
+ keyColumns: z.ZodArray<z.ZodObject<{
40
+ type: z.ZodLiteral<"indexColumn">;
41
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
42
+ order: z.ZodOptional<z.ZodEnum<{
43
+ ASC: "ASC";
44
+ DESC: "DESC";
45
+ }>>;
46
+ nulls: z.ZodOptional<z.ZodEnum<{
47
+ FIRST: "FIRST";
48
+ LAST: "LAST";
49
+ }>>;
50
+ opclass: z.ZodOptional<z.ZodString>;
51
+ collation: z.ZodOptional<z.ZodString>;
52
+ }, z.core.$strip>>;
53
+ includedColumns: z.ZodOptional<z.ZodArray<z.ZodObject<{
54
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
55
+ }, z.core.$strip>>>;
56
+ }, z.core.$strip>;
57
+ type FullSchemaIndex = z.infer<typeof FullSchemaIndex>;
58
+ declare const FullSchemaColumn: z.ZodObject<{
59
+ type: z.ZodLiteral<"column">;
60
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
61
+ order: z.ZodNumber;
62
+ columnType: z.ZodString;
63
+ isNullable: z.ZodBoolean;
64
+ defaultValue: z.ZodOptional<z.ZodString>;
65
+ dropped: z.ZodBoolean;
66
+ collation: z.ZodOptional<z.ZodString>;
67
+ storage: z.ZodOptional<z.ZodEnum<{
68
+ plain: "plain";
69
+ main: "main";
70
+ external: "external";
71
+ extended: "extended";
72
+ }>>;
73
+ isIdentity: z.ZodOptional<z.ZodEnum<{
74
+ always: "always";
75
+ "by default": "by default";
76
+ }>>;
77
+ }, z.core.$strip>;
78
+ type FullSchemaColumn = z.infer<typeof FullSchemaColumn>;
79
+ declare const FullSchemaTable: z.ZodObject<{
80
+ type: z.ZodLiteral<"table">;
81
+ oid: z.ZodNumber;
82
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
83
+ tableName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
84
+ tablespace: z.ZodOptional<z.ZodString>;
85
+ partitionKeyDef: z.ZodOptional<z.ZodString>;
86
+ columns: z.ZodDefault<z.ZodArray<z.ZodObject<{
87
+ type: z.ZodLiteral<"column">;
88
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
89
+ order: z.ZodNumber;
90
+ columnType: z.ZodString;
91
+ isNullable: z.ZodBoolean;
92
+ defaultValue: z.ZodOptional<z.ZodString>;
93
+ dropped: z.ZodBoolean;
94
+ collation: z.ZodOptional<z.ZodString>;
95
+ storage: z.ZodOptional<z.ZodEnum<{
96
+ plain: "plain";
97
+ main: "main";
98
+ external: "external";
99
+ extended: "extended";
100
+ }>>;
101
+ isIdentity: z.ZodOptional<z.ZodEnum<{
102
+ always: "always";
103
+ "by default": "by default";
104
+ }>>;
105
+ }, z.core.$strip>>>;
106
+ }, z.core.$strip>;
107
+ type FullSchemaTable = z.infer<typeof FullSchemaTable>;
108
+ declare const FullSchemaConstraint: z.ZodObject<{
109
+ type: z.ZodLiteral<"constraint">;
110
+ oid: z.ZodNumber;
111
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
112
+ tableName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
113
+ constraintName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
114
+ constraintType: z.ZodUnion<[z.ZodEnum<{
115
+ check: "check";
116
+ foreign_key: "foreign_key";
117
+ not_null: "not_null";
118
+ primary_key: "primary_key";
119
+ unique: "unique";
120
+ trigger: "trigger";
121
+ exclusion: "exclusion";
122
+ }>, z.ZodString]>;
123
+ definition: z.ZodString;
124
+ isDeferrable: z.ZodOptional<z.ZodBoolean>;
125
+ isInitiallyDeferred: z.ZodOptional<z.ZodBoolean>;
126
+ isValidated: z.ZodOptional<z.ZodBoolean>;
127
+ backingIndexOid: z.ZodOptional<z.ZodNumber>;
128
+ }, z.core.$strip>;
129
+ type FullSchemaConstraint = z.infer<typeof FullSchemaConstraint>;
130
+ declare const FullSchemaFunction: z.ZodObject<{
131
+ type: z.ZodLiteral<"function">;
132
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
133
+ objectName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
134
+ objectType: z.ZodEnum<{
135
+ function: "function";
136
+ procedure: "procedure";
137
+ aggregate: "aggregate";
138
+ "window function": "window function";
139
+ }>;
140
+ identityArguments: z.ZodOptional<z.ZodString>;
141
+ definition: z.ZodString;
142
+ }, z.core.$strip>;
143
+ type FullSchemaFunction = z.infer<typeof FullSchemaFunction>;
144
+ declare const FullSchemaExtension: z.ZodObject<{
145
+ extensionName: z.ZodString;
146
+ version: z.ZodString;
147
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
148
+ }, z.core.$strip>;
149
+ type FullSchemaExtension = z.infer<typeof FullSchemaExtension>;
150
+ declare const FullSchemaView: z.ZodObject<{
151
+ type: z.ZodLiteral<"view">;
152
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
153
+ viewName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
154
+ objectType: z.ZodEnum<{
155
+ view: "view";
156
+ materialized_view: "materialized_view";
157
+ }>;
158
+ definition: z.ZodString;
159
+ tablespace: z.ZodOptional<z.ZodString>;
160
+ }, z.core.$strip>;
161
+ type FullSchemaView = z.infer<typeof FullSchemaView>;
162
+ declare const FullSchemaTypeConstraint: z.ZodObject<{
163
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
164
+ definition: z.ZodString;
165
+ }, z.core.$strip>;
166
+ type FullSchemaTypeConstraint = z.infer<typeof FullSchemaTypeConstraint>;
167
+ declare const FullSchemaCompositeAttribute: z.ZodObject<{
168
+ type: z.ZodLiteral<"compositeAttribute">;
169
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
170
+ attributeType: z.ZodString;
171
+ collation: z.ZodOptional<z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>>;
172
+ }, z.core.$strip>;
173
+ type FullSchemaCompositeAttribute = z.infer<typeof FullSchemaCompositeAttribute>;
174
+ declare const FullSchemaType: z.ZodObject<{
175
+ type: z.ZodLiteral<"type">;
176
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
177
+ typeName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
178
+ typeCategory: z.ZodEnum<{
179
+ enum: "enum";
180
+ domain: "domain";
181
+ composite: "composite";
182
+ }>;
183
+ enumLabels: z.ZodOptional<z.ZodArray<z.ZodString>>;
184
+ domainBaseType: z.ZodOptional<z.ZodString>;
185
+ domainIsNotNull: z.ZodOptional<z.ZodBoolean>;
186
+ domainDefault: z.ZodOptional<z.ZodString>;
187
+ domainConstraints: z.ZodOptional<z.ZodArray<z.ZodObject<{
188
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
189
+ definition: z.ZodString;
190
+ }, z.core.$strip>>>;
191
+ compositeAttributes: z.ZodOptional<z.ZodArray<z.ZodObject<{
192
+ type: z.ZodLiteral<"compositeAttribute">;
193
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
194
+ attributeType: z.ZodString;
195
+ collation: z.ZodOptional<z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>>;
196
+ }, z.core.$strip>>>;
197
+ }, z.core.$strip>;
198
+ type FullSchemaType = z.infer<typeof FullSchemaType>;
199
+ declare const FullSchemaTrigger: z.ZodObject<{
200
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
201
+ tableName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
202
+ triggerName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
203
+ definition: z.ZodString;
204
+ enabledMode: z.ZodString;
205
+ }, z.core.$strip>;
206
+ type FullSchemaTrigger = z.infer<typeof FullSchemaTrigger>;
207
+ declare const FullSchema: z.ZodObject<{
208
+ indexes: z.ZodDefault<z.ZodArray<z.ZodObject<{
209
+ type: z.ZodLiteral<"index">;
210
+ oid: z.ZodNumber;
211
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
212
+ tableName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
213
+ indexName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
214
+ indexType: z.ZodString;
215
+ isUnique: z.ZodBoolean;
216
+ isPrimary: z.ZodBoolean;
217
+ isClustered: z.ZodBoolean;
218
+ wherePredicate: z.ZodOptional<z.ZodString>;
219
+ tablespace: z.ZodOptional<z.ZodString>;
220
+ keyColumns: z.ZodArray<z.ZodObject<{
221
+ type: z.ZodLiteral<"indexColumn">;
222
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
223
+ order: z.ZodOptional<z.ZodEnum<{
224
+ ASC: "ASC";
225
+ DESC: "DESC";
226
+ }>>;
227
+ nulls: z.ZodOptional<z.ZodEnum<{
228
+ FIRST: "FIRST";
229
+ LAST: "LAST";
230
+ }>>;
231
+ opclass: z.ZodOptional<z.ZodString>;
232
+ collation: z.ZodOptional<z.ZodString>;
233
+ }, z.core.$strip>>;
234
+ includedColumns: z.ZodOptional<z.ZodArray<z.ZodObject<{
235
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
236
+ }, z.core.$strip>>>;
237
+ }, z.core.$strip>>>;
238
+ tables: z.ZodDefault<z.ZodArray<z.ZodObject<{
239
+ type: z.ZodLiteral<"table">;
240
+ oid: z.ZodNumber;
241
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
242
+ tableName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
243
+ tablespace: z.ZodOptional<z.ZodString>;
244
+ partitionKeyDef: z.ZodOptional<z.ZodString>;
245
+ columns: z.ZodDefault<z.ZodArray<z.ZodObject<{
246
+ type: z.ZodLiteral<"column">;
247
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
248
+ order: z.ZodNumber;
249
+ columnType: z.ZodString;
250
+ isNullable: z.ZodBoolean;
251
+ defaultValue: z.ZodOptional<z.ZodString>;
252
+ dropped: z.ZodBoolean;
253
+ collation: z.ZodOptional<z.ZodString>;
254
+ storage: z.ZodOptional<z.ZodEnum<{
255
+ plain: "plain";
256
+ main: "main";
257
+ external: "external";
258
+ extended: "extended";
259
+ }>>;
260
+ isIdentity: z.ZodOptional<z.ZodEnum<{
261
+ always: "always";
262
+ "by default": "by default";
263
+ }>>;
264
+ }, z.core.$strip>>>;
265
+ }, z.core.$strip>>>;
266
+ constraints: z.ZodDefault<z.ZodArray<z.ZodObject<{
267
+ type: z.ZodLiteral<"constraint">;
268
+ oid: z.ZodNumber;
269
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
270
+ tableName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
271
+ constraintName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
272
+ constraintType: z.ZodUnion<[z.ZodEnum<{
273
+ check: "check";
274
+ foreign_key: "foreign_key";
275
+ not_null: "not_null";
276
+ primary_key: "primary_key";
277
+ unique: "unique";
278
+ trigger: "trigger";
279
+ exclusion: "exclusion";
280
+ }>, z.ZodString]>;
281
+ definition: z.ZodString;
282
+ isDeferrable: z.ZodOptional<z.ZodBoolean>;
283
+ isInitiallyDeferred: z.ZodOptional<z.ZodBoolean>;
284
+ isValidated: z.ZodOptional<z.ZodBoolean>;
285
+ backingIndexOid: z.ZodOptional<z.ZodNumber>;
286
+ }, z.core.$strip>>>;
287
+ functions: z.ZodDefault<z.ZodArray<z.ZodObject<{
288
+ type: z.ZodLiteral<"function">;
289
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
290
+ objectName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
291
+ objectType: z.ZodEnum<{
292
+ function: "function";
293
+ procedure: "procedure";
294
+ aggregate: "aggregate";
295
+ "window function": "window function";
296
+ }>;
297
+ identityArguments: z.ZodOptional<z.ZodString>;
298
+ definition: z.ZodString;
299
+ }, z.core.$strip>>>;
300
+ extensions: z.ZodDefault<z.ZodArray<z.ZodObject<{
301
+ extensionName: z.ZodString;
302
+ version: z.ZodString;
303
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
304
+ }, z.core.$strip>>>;
305
+ views: z.ZodDefault<z.ZodArray<z.ZodObject<{
306
+ type: z.ZodLiteral<"view">;
307
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
308
+ viewName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
309
+ objectType: z.ZodEnum<{
310
+ view: "view";
311
+ materialized_view: "materialized_view";
312
+ }>;
313
+ definition: z.ZodString;
314
+ tablespace: z.ZodOptional<z.ZodString>;
315
+ }, z.core.$strip>>>;
316
+ types: z.ZodDefault<z.ZodArray<z.ZodObject<{
317
+ type: z.ZodLiteral<"type">;
318
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
319
+ typeName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
320
+ typeCategory: z.ZodEnum<{
321
+ enum: "enum";
322
+ domain: "domain";
323
+ composite: "composite";
324
+ }>;
325
+ enumLabels: z.ZodOptional<z.ZodArray<z.ZodString>>;
326
+ domainBaseType: z.ZodOptional<z.ZodString>;
327
+ domainIsNotNull: z.ZodOptional<z.ZodBoolean>;
328
+ domainDefault: z.ZodOptional<z.ZodString>;
329
+ domainConstraints: z.ZodOptional<z.ZodArray<z.ZodObject<{
330
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
331
+ definition: z.ZodString;
332
+ }, z.core.$strip>>>;
333
+ compositeAttributes: z.ZodOptional<z.ZodArray<z.ZodObject<{
334
+ type: z.ZodLiteral<"compositeAttribute">;
335
+ name: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
336
+ attributeType: z.ZodString;
337
+ collation: z.ZodOptional<z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>>;
338
+ }, z.core.$strip>>>;
339
+ }, z.core.$strip>>>;
340
+ triggers: z.ZodDefault<z.ZodArray<z.ZodObject<{
341
+ schemaName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
342
+ tableName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
343
+ triggerName: z.ZodCodec<z.ZodString, z.ZodCustom<PgIdentifier, PgIdentifier>>;
344
+ definition: z.ZodString;
345
+ enabledMode: z.ZodString;
346
+ }, z.core.$strip>>>;
347
+ }, z.core.$strip>;
348
+ type FullSchema = z.infer<typeof FullSchema>;
349
+ declare function dumpSchema(db: Postgres): Promise<FullSchema>;
350
+ //#endregion
351
+ export { FullSchema, FullSchemaColumn, FullSchemaCompositeAttribute, FullSchemaConstraint, FullSchemaExtension, FullSchemaFunction, FullSchemaIncludedColumn, FullSchemaIndex, FullSchemaKeyColumn, FullSchemaTable, FullSchemaTrigger, FullSchemaType, FullSchemaTypeConstraint, FullSchemaView, dumpSchema };
352
+ //# sourceMappingURL=schema.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.mts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;;cAUa,mBAAA,EAAmB,CAAA,CAAA,SAAA;;;;;;;;;;;;;;KASpB,mBAAA,GAAsB,CAAA,CAAE,KAAA,QAAa,mBAAA;AAAA,cAEpC,wBAAA,EAAwB,CAAA,CAAA,SAAA;;;KAIzB,wBAAA,GAA2B,CAAA,CAAE,KAAA,QAAa,wBAAA;AAAA,cAEzC,eAAA,EAAe,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgBhB,eAAA,GAAkB,CAAA,CAAE,KAAA,QAAa,eAAA;AAAA,cAEhC,gBAAA,EAAgB,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;KAajB,gBAAA,GAAmB,CAAA,CAAE,KAAA,QAAa,gBAAA;AAAA,cAEjC,eAAA,EAAe,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAUhB,eAAA,GAAkB,CAAA,CAAE,KAAA,QAAa,eAAA;AAAA,cAEhC,oBAAA,EAAoB,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;KAwBr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.mjs";
4
+ import { z } from "zod";
5
+ //#region src/schema.ts
6
+ const Identifier = z.codec(z.string(), z.custom(), {
7
+ encode: (v) => v.toString(),
8
+ decode: (v) => PgIdentifier.fromString(v)
9
+ });
10
+ const FullSchemaKeyColumn = z.object({
11
+ type: z.literal("indexColumn"),
12
+ name: Identifier,
13
+ order: z.enum(["ASC", "DESC"]).optional(),
14
+ nulls: z.enum(["FIRST", "LAST"]).optional(),
15
+ opclass: z.string().optional(),
16
+ collation: z.string().optional()
17
+ });
18
+ const FullSchemaIncludedColumn = z.object({ name: Identifier });
19
+ const FullSchemaIndex = z.object({
20
+ type: z.literal("index"),
21
+ oid: z.number(),
22
+ schemaName: Identifier,
23
+ tableName: Identifier,
24
+ indexName: Identifier,
25
+ indexType: z.string(),
26
+ isUnique: z.boolean(),
27
+ isPrimary: z.boolean(),
28
+ isClustered: z.boolean(),
29
+ wherePredicate: z.string().optional(),
30
+ tablespace: z.string().optional(),
31
+ keyColumns: z.array(FullSchemaKeyColumn),
32
+ includedColumns: z.array(FullSchemaIncludedColumn).optional()
33
+ });
34
+ const FullSchemaColumn = z.object({
35
+ type: z.literal("column"),
36
+ name: Identifier,
37
+ order: z.number(),
38
+ columnType: z.string(),
39
+ isNullable: z.boolean(),
40
+ defaultValue: z.string().optional(),
41
+ dropped: z.boolean(),
42
+ collation: z.string().optional(),
43
+ storage: z.enum([
44
+ "plain",
45
+ "main",
46
+ "external",
47
+ "extended"
48
+ ]).optional(),
49
+ isIdentity: z.enum(["always", "by default"]).optional()
50
+ });
51
+ const FullSchemaTable = z.object({
52
+ type: z.literal("table"),
53
+ oid: z.number(),
54
+ schemaName: Identifier,
55
+ tableName: Identifier,
56
+ tablespace: z.string().optional(),
57
+ partitionKeyDef: z.string().optional(),
58
+ columns: z.array(FullSchemaColumn).default([])
59
+ });
60
+ const FullSchemaConstraint = z.object({
61
+ type: z.literal("constraint"),
62
+ oid: z.number(),
63
+ schemaName: Identifier,
64
+ tableName: Identifier,
65
+ constraintName: Identifier,
66
+ constraintType: z.enum([
67
+ "check",
68
+ "foreign_key",
69
+ "not_null",
70
+ "primary_key",
71
+ "unique",
72
+ "trigger",
73
+ "exclusion"
74
+ ]).or(z.string()),
75
+ definition: z.string(),
76
+ isDeferrable: z.boolean().optional(),
77
+ isInitiallyDeferred: z.boolean().optional(),
78
+ isValidated: z.boolean().optional(),
79
+ backingIndexOid: z.number().optional()
80
+ });
81
+ const FullSchemaFunction = z.object({
82
+ type: z.literal("function"),
83
+ schemaName: Identifier,
84
+ objectName: Identifier,
85
+ objectType: z.enum([
86
+ "function",
87
+ "procedure",
88
+ "aggregate",
89
+ "window function"
90
+ ]),
91
+ identityArguments: z.string().optional(),
92
+ definition: z.string()
93
+ });
94
+ const FullSchemaExtension = z.object({
95
+ extensionName: z.string(),
96
+ version: z.string(),
97
+ schemaName: Identifier
98
+ });
99
+ const FullSchemaView = z.object({
100
+ type: z.literal("view"),
101
+ schemaName: Identifier,
102
+ viewName: Identifier,
103
+ objectType: z.enum(["view", "materialized_view"]),
104
+ definition: z.string(),
105
+ tablespace: z.string().optional()
106
+ });
107
+ const FullSchemaTypeConstraint = z.object({
108
+ name: Identifier,
109
+ definition: z.string()
110
+ });
111
+ const FullSchemaCompositeAttribute = z.object({
112
+ type: z.literal("compositeAttribute"),
113
+ name: Identifier,
114
+ attributeType: z.string(),
115
+ collation: Identifier.optional()
116
+ });
117
+ const FullSchemaType = z.object({
118
+ type: z.literal("type"),
119
+ schemaName: Identifier,
120
+ typeName: Identifier,
121
+ typeCategory: z.enum([
122
+ "enum",
123
+ "domain",
124
+ "composite"
125
+ ]),
126
+ enumLabels: z.array(z.string()).optional(),
127
+ domainBaseType: z.string().optional(),
128
+ domainIsNotNull: z.boolean().optional(),
129
+ domainDefault: z.string().optional(),
130
+ domainConstraints: z.array(FullSchemaTypeConstraint).optional(),
131
+ compositeAttributes: z.array(FullSchemaCompositeAttribute).optional()
132
+ });
133
+ const FullSchemaTrigger = z.object({
134
+ schemaName: Identifier,
135
+ tableName: Identifier,
136
+ triggerName: Identifier,
137
+ definition: z.string(),
138
+ enabledMode: z.string()
139
+ });
140
+ const FullSchema = z.object({
141
+ indexes: z.array(FullSchemaIndex).default([]),
142
+ tables: z.array(FullSchemaTable).default([]),
143
+ constraints: z.array(FullSchemaConstraint).default([]),
144
+ functions: z.array(FullSchemaFunction).default([]),
145
+ extensions: z.array(FullSchemaExtension).default([]),
146
+ views: z.array(FullSchemaView).default([]),
147
+ types: z.array(FullSchemaType).default([]),
148
+ triggers: z.array(FullSchemaTrigger).default([])
149
+ });
150
+ async function dumpSchema(db) {
151
+ const rows = await db.exec(SCHEMA_DUMP_SQL);
152
+ return FullSchema.parse(rows[0]?.result ?? {});
153
+ }
154
+ //#endregion
155
+ export { FullSchema, FullSchemaColumn, FullSchemaCompositeAttribute, FullSchemaConstraint, FullSchemaExtension, FullSchemaFunction, FullSchemaIncludedColumn, FullSchemaIndex, FullSchemaKeyColumn, FullSchemaTable, FullSchemaTrigger, FullSchemaType, FullSchemaTypeConstraint, FullSchemaView, dumpSchema };
156
+
157
+ //# sourceMappingURL=schema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { SCHEMA_DUMP_SQL } from \"./schema-dump.js\";\nimport type { Postgres } from \"./sql/database.js\";\nimport { PgIdentifier } from \"./sql/pg-identifier.js\";\n\nconst Identifier = z.codec(z.string(), z.custom<PgIdentifier>(), {\n encode: (v) => v.toString(),\n decode: (v) => PgIdentifier.fromString(v),\n});\n\nexport const FullSchemaKeyColumn = z.object({\n type: z.literal(\"indexColumn\"),\n name: Identifier,\n order: z.enum([\"ASC\", \"DESC\"]).optional(),\n nulls: z.enum([\"FIRST\", \"LAST\"]).optional(),\n opclass: z.string().optional(),\n collation: z.string().optional(),\n});\n\nexport type FullSchemaKeyColumn = z.infer<typeof FullSchemaKeyColumn>;\n\nexport const FullSchemaIncludedColumn = z.object({\n name: Identifier,\n});\n\nexport type FullSchemaIncludedColumn = z.infer<typeof FullSchemaIncludedColumn>;\n\nexport const FullSchemaIndex = z.object({\n type: z.literal(\"index\"),\n oid: z.number(),\n schemaName: Identifier,\n tableName: Identifier,\n indexName: Identifier,\n indexType: z.string(),\n isUnique: z.boolean(),\n isPrimary: z.boolean(),\n isClustered: z.boolean(),\n wherePredicate: z.string().optional(),\n tablespace: z.string().optional(),\n keyColumns: z.array(FullSchemaKeyColumn),\n includedColumns: z.array(FullSchemaIncludedColumn).optional(),\n});\n\nexport type FullSchemaIndex = z.infer<typeof FullSchemaIndex>;\n\nexport const FullSchemaColumn = z.object({\n type: z.literal(\"column\"),\n name: Identifier,\n order: z.number(),\n columnType: z.string(),\n isNullable: z.boolean(),\n defaultValue: z.string().optional(),\n dropped: z.boolean(),\n collation: z.string().optional(),\n storage: z.enum([\"plain\", \"main\", \"external\", \"extended\"]).optional(),\n isIdentity: z.enum([\"always\", \"by default\"]).optional(),\n});\n\nexport type FullSchemaColumn = z.infer<typeof FullSchemaColumn>;\n\nexport const FullSchemaTable = z.object({\n type: z.literal(\"table\"),\n oid: z.number(),\n schemaName: Identifier,\n tableName: Identifier,\n tablespace: z.string().optional(),\n partitionKeyDef: z.string().optional(),\n columns: z.array(FullSchemaColumn).default([]),\n});\n\nexport type FullSchemaTable = z.infer<typeof FullSchemaTable>;\n\nexport const FullSchemaConstraint = z.object({\n type: z.literal(\"constraint\"),\n oid: z.number(),\n schemaName: Identifier,\n tableName: Identifier,\n constraintName: Identifier,\n constraintType: z\n .enum([\n \"check\",\n \"foreign_key\",\n \"not_null\",\n \"primary_key\",\n \"unique\",\n \"trigger\",\n \"exclusion\",\n ])\n .or(z.string()),\n definition: z.string(),\n isDeferrable: z.boolean().optional(),\n isInitiallyDeferred: z.boolean().optional(),\n isValidated: z.boolean().optional(),\n backingIndexOid: z.number().optional(),\n});\n\nexport type FullSchemaConstraint = z.infer<typeof FullSchemaConstraint>;\n\nexport const FullSchemaFunction = z.object({\n type: z.literal(\"function\"),\n schemaName: Identifier,\n objectName: Identifier,\n objectType: z.enum([\"function\", \"procedure\", \"aggregate\", \"window function\"]),\n identityArguments: z.string().optional(),\n definition: z.string(),\n});\n\nexport type FullSchemaFunction = z.infer<typeof FullSchemaFunction>;\n\nexport const FullSchemaExtension = z.object({\n extensionName: z.string(),\n version: z.string(),\n schemaName: Identifier,\n});\n\nexport type FullSchemaExtension = z.infer<typeof FullSchemaExtension>;\n\nexport const FullSchemaView = z.object({\n type: z.literal(\"view\"),\n schemaName: Identifier,\n viewName: Identifier,\n objectType: z.enum([\"view\", \"materialized_view\"]),\n definition: z.string(),\n tablespace: z.string().optional(),\n});\n\nexport type FullSchemaView = z.infer<typeof FullSchemaView>;\n\nexport const FullSchemaTypeConstraint = z.object({\n name: Identifier,\n definition: z.string(),\n});\n\nexport type FullSchemaTypeConstraint = z.infer<typeof FullSchemaTypeConstraint>;\n\nexport const FullSchemaCompositeAttribute = z.object({\n type: z.literal(\"compositeAttribute\"),\n name: Identifier,\n attributeType: z.string(),\n collation: Identifier.optional(),\n});\n\nexport type FullSchemaCompositeAttribute = z.infer<\n typeof FullSchemaCompositeAttribute\n>;\n\nexport const FullSchemaType = z.object({\n type: z.literal(\"type\"),\n schemaName: Identifier,\n typeName: Identifier,\n typeCategory: z.enum([\"enum\", \"domain\", \"composite\"]),\n enumLabels: z.array(z.string()).optional(),\n domainBaseType: z.string().optional(),\n domainIsNotNull: z.boolean().optional(),\n domainDefault: z.string().optional(),\n domainConstraints: z.array(FullSchemaTypeConstraint).optional(),\n compositeAttributes: z.array(FullSchemaCompositeAttribute).optional(),\n});\n\nexport type FullSchemaType = z.infer<typeof FullSchemaType>;\n\nexport const FullSchemaTrigger = z.object({\n schemaName: Identifier,\n tableName: Identifier,\n triggerName: Identifier,\n definition: z.string(),\n enabledMode: z.string(),\n});\n\nexport type FullSchemaTrigger = z.infer<typeof FullSchemaTrigger>;\n\nexport const FullSchema = z.object({\n indexes: z.array(FullSchemaIndex).default([]),\n tables: z.array(FullSchemaTable).default([]),\n constraints: z.array(FullSchemaConstraint).default([]),\n functions: z.array(FullSchemaFunction).default([]),\n extensions: z.array(FullSchemaExtension).default([]),\n views: z.array(FullSchemaView).default([]),\n types: z.array(FullSchemaType).default([]),\n triggers: z.array(FullSchemaTrigger).default([]),\n});\n\nexport type FullSchema = z.infer<typeof FullSchema>;\n\nexport async function dumpSchema(db: Postgres): Promise<FullSchema> {\n const rows = await db.exec<{ result: FullSchema }>(SCHEMA_DUMP_SQL);\n return FullSchema.parse(rows[0]?.result ?? {});\n}\n"],"mappings":";;;;;AAKA,MAAM,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAsB,EAAE;CAC/D,SAAS,MAAM,EAAE,UAAU;CAC3B,SAAS,MAAM,aAAa,WAAW,EAAE;CAC1C,CAAC;AAEF,MAAa,sBAAsB,EAAE,OAAO;CAC1C,MAAM,EAAE,QAAQ,cAAc;CAC9B,MAAM;CACN,OAAO,EAAE,KAAK,CAAC,OAAO,OAAO,CAAC,CAAC,UAAU;CACzC,OAAO,EAAE,KAAK,CAAC,SAAS,OAAO,CAAC,CAAC,UAAU;CAC3C,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC;AAIF,MAAa,2BAA2B,EAAE,OAAO,EAC/C,MAAM,YACP,CAAC;AAIF,MAAa,kBAAkB,EAAE,OAAO;CACtC,MAAM,EAAE,QAAQ,QAAQ;CACxB,KAAK,EAAE,QAAQ;CACf,YAAY;CACZ,WAAW;CACX,WAAW;CACX,WAAW,EAAE,QAAQ;CACrB,UAAU,EAAE,SAAS;CACrB,WAAW,EAAE,SAAS;CACtB,aAAa,EAAE,SAAS;CACxB,gBAAgB,EAAE,QAAQ,CAAC,UAAU;CACrC,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,YAAY,EAAE,MAAM,oBAAoB;CACxC,iBAAiB,EAAE,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,SAAS,EAAE,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAC;CAC7C,QAAQ,EAAE,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAC;CAC5C,aAAa,EAAE,MAAM,qBAAqB,CAAC,QAAQ,EAAE,CAAC;CACtD,WAAW,EAAE,MAAM,mBAAmB,CAAC,QAAQ,EAAE,CAAC;CAClD,YAAY,EAAE,MAAM,oBAAoB,CAAC,QAAQ,EAAE,CAAC;CACpD,OAAO,EAAE,MAAM,eAAe,CAAC,QAAQ,EAAE,CAAC;CAC1C,OAAO,EAAE,MAAM,eAAe,CAAC,QAAQ,EAAE,CAAC;CAC1C,UAAU,EAAE,MAAM,kBAAkB,CAAC,QAAQ,EAAE,CAAC;CACjD,CAAC;AAIF,eAAsB,WAAW,IAAmC;CAClE,MAAM,OAAO,MAAM,GAAG,KAA6B,gBAAgB;AACnE,QAAO,WAAW,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC"}
@@ -4,7 +4,7 @@ import { PgIdentifier } from "./pg-identifier.cjs";
4
4
  import { z } from "zod";
5
5
 
6
6
  //#region src/sql/database.d.ts
7
- declare const PostgresVersion: z.core.$ZodBranded<z.ZodString, "PostgresVersion">;
7
+ declare const PostgresVersion: z.core.$ZodBranded<z.ZodString, "PostgresVersion", "out">;
8
8
  type PostgresVersion = z.infer<typeof PostgresVersion>;
9
9
  interface PostgresTransaction {
10
10
  /**
@@ -4,7 +4,7 @@ import { PgIdentifier } from "./pg-identifier.mjs";
4
4
  import { z } from "zod";
5
5
 
6
6
  //#region src/sql/database.d.ts
7
- declare const PostgresVersion: z.core.$ZodBranded<z.ZodString, "PostgresVersion">;
7
+ declare const PostgresVersion: z.core.$ZodBranded<z.ZodString, "PostgresVersion", "out">;
8
8
  type PostgresVersion = z.infer<typeof PostgresVersion>;
9
9
  interface PostgresTransaction {
10
10
  /**
@@ -1,16 +1,65 @@
1
1
  "use client";
2
2
  //#region src/sql/indexes.ts
3
3
  function isIndexSupported(index) {
4
- return index.index_type === "btree" || index.index_type === "gin";
4
+ return index.indexType === "btree" || index.indexType === "gin";
5
5
  }
6
6
  /**
7
7
  * Doesn't necessarily decide whether the index can be dropped but can be
8
8
  * used to not even try dropping indexes that _definitely_ cannot be dropped
9
9
  */
10
10
  function isIndexProbablyDroppable(index) {
11
- return !index.is_primary && !index.is_unique;
11
+ return !index.isPrimary && !index.isUnique;
12
+ }
13
+ function columnsEqual(a, b) {
14
+ if (a.length !== b.length) return false;
15
+ for (let i = 0; i < a.length; i++) if (a[i].name.toString() !== b[i].name.toString() || (a[i].order ?? null) !== (b[i].order ?? null) || (a[i].opclass ?? null) !== (b[i].opclass ?? null)) return false;
16
+ return true;
17
+ }
18
+ function indexesAreEqual(a, b) {
19
+ return a.schemaName.toString() === b.schemaName.toString() && a.tableName.toString() === b.tableName.toString() && a.indexType === b.indexType && (a.wherePredicate ?? null) === (b.wherePredicate ?? null) && columnsEqual(a.keyColumns, b.keyColumns);
20
+ }
21
+ function sharedPrefixColumns(shorter, longer) {
22
+ if (shorter.schemaName.toString() !== longer.schemaName.toString() || shorter.tableName.toString() !== longer.tableName.toString() || shorter.indexType !== longer.indexType || shorter.indexType !== "btree" || shorter.wherePredicate !== void 0 || longer.wherePredicate !== void 0 || shorter.keyColumns.length >= longer.keyColumns.length) return null;
23
+ for (let i = 0; i < shorter.keyColumns.length; i++) {
24
+ const s = shorter.keyColumns[i];
25
+ const l = longer.keyColumns[i];
26
+ if (s.name.toString() !== l.name.toString() || (s.order ?? null) !== (l.order ?? null) || (s.opclass ?? null) !== (l.opclass ?? null)) return null;
27
+ }
28
+ return shorter.keyColumns;
29
+ }
30
+ function groupDuplicateIndexes(indexes) {
31
+ const groups = [];
32
+ for (const index of indexes) {
33
+ const existing = groups.find((g) => g.kind === "exact" && indexesAreEqual(g.indexes[0], index));
34
+ if (existing) existing.indexes.push(index);
35
+ else groups.push({
36
+ kind: "exact",
37
+ indexes: [index]
38
+ });
39
+ }
40
+ const exactGroups = groups.filter((g) => g.indexes.length > 1);
41
+ const representatives = groups.filter((g) => g.indexes.length === 1).map((g) => g.indexes[0]);
42
+ const prefixGroups = [];
43
+ for (const shorter of representatives) {
44
+ const existing = prefixGroups.find((g) => g.indexes.some((idx) => sharedPrefixColumns(shorter, idx) !== null || sharedPrefixColumns(idx, shorter) !== null));
45
+ if (existing) {
46
+ if (!existing.indexes.includes(shorter)) existing.indexes.push(shorter);
47
+ } else {
48
+ const longer = representatives.find((idx) => idx !== shorter && sharedPrefixColumns(shorter, idx) !== null);
49
+ if (longer) {
50
+ const sharedPrefix = sharedPrefixColumns(shorter, longer);
51
+ prefixGroups.push({
52
+ kind: "prefix",
53
+ indexes: [longer, shorter],
54
+ sharedPrefix
55
+ });
56
+ }
57
+ }
58
+ }
59
+ return [...exactGroups, ...prefixGroups];
12
60
  }
13
61
  //#endregion
62
+ exports.groupDuplicateIndexes = groupDuplicateIndexes;
14
63
  exports.isIndexProbablyDroppable = isIndexProbablyDroppable;
15
64
  exports.isIndexSupported = isIndexSupported;
16
65
 
@@ -1 +1 @@
1
- {"version":3,"file":"indexes.cjs","names":[],"sources":["../../src/sql/indexes.ts"],"sourcesContent":["import type { IndexedTable } from \"../optimizer/statistics.js\";\n\nexport function isIndexSupported(index: IndexedTable) {\n return index.index_type === \"btree\" || index.index_type === \"gin\";\n}\n\n/**\n * Doesn't necessarily decide whether the index can be dropped but can be\n * used to not even try dropping indexes that _definitely_ cannot be dropped\n */\nexport function isIndexProbablyDroppable(index: IndexedTable) {\n /* TODO: until we have a better solution, this is the best we have */\n /* The is_unique check is problematic only if the column is declared as unique */\n return !index.is_primary && !index.is_unique;\n}\n"],"mappings":";;AAEA,SAAgB,iBAAiB,OAAqB;AACpD,QAAO,MAAM,eAAe,WAAW,MAAM,eAAe;;;;;;AAO9D,SAAgB,yBAAyB,OAAqB;AAG5D,QAAO,CAAC,MAAM,cAAc,CAAC,MAAM"}
1
+ {"version":3,"file":"indexes.cjs","names":[],"sources":["../../src/sql/indexes.ts"],"sourcesContent":["import type { FullSchemaIndex } from \"../schema.js\";\n\ntype IndexTypeHint = { indexType: string };\ntype IndexDropHint = { isPrimary: boolean; isUnique: boolean };\n\nexport function isIndexSupported(index: IndexTypeHint) {\n return index.indexType === \"btree\" || index.indexType === \"gin\";\n}\n\n/**\n * Doesn't necessarily decide whether the index can be dropped but can be\n * used to not even try dropping indexes that _definitely_ cannot be dropped\n */\nexport function isIndexProbablyDroppable(index: IndexDropHint) {\n /* TODO: until we have a better solution, this is the best we have */\n /* The is_unique check is problematic only if the column is declared as unique */\n return !index.isPrimary && !index.isUnique;\n}\n\nexport type DuplicateIndexGroup =\n | { kind: \"exact\"; indexes: FullSchemaIndex[] }\n | {\n kind: \"prefix\";\n indexes: FullSchemaIndex[];\n sharedPrefix: FullSchemaIndex[\"keyColumns\"];\n };\n\nfunction columnsEqual(\n a: FullSchemaIndex[\"keyColumns\"],\n b: FullSchemaIndex[\"keyColumns\"],\n): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (\n a[i].name.toString() !== b[i].name.toString() ||\n (a[i].order ?? null) !== (b[i].order ?? null) ||\n (a[i].opclass ?? null) !== (b[i].opclass ?? null)\n ) {\n return false;\n }\n }\n return true;\n}\n\nfunction indexesAreEqual(a: FullSchemaIndex, b: FullSchemaIndex): boolean {\n return (\n a.schemaName.toString() === b.schemaName.toString() &&\n a.tableName.toString() === b.tableName.toString() &&\n a.indexType === b.indexType &&\n (a.wherePredicate ?? null) === (b.wherePredicate ?? null) &&\n columnsEqual(a.keyColumns, b.keyColumns)\n );\n}\n\nfunction sharedPrefixColumns(\n shorter: FullSchemaIndex,\n longer: FullSchemaIndex,\n): FullSchemaIndex[\"keyColumns\"] | null {\n if (\n shorter.schemaName.toString() !== longer.schemaName.toString() ||\n shorter.tableName.toString() !== longer.tableName.toString() ||\n shorter.indexType !== longer.indexType ||\n shorter.indexType !== \"btree\" ||\n shorter.wherePredicate !== undefined ||\n longer.wherePredicate !== undefined ||\n shorter.keyColumns.length >= longer.keyColumns.length\n ) {\n return null;\n }\n for (let i = 0; i < shorter.keyColumns.length; i++) {\n const s = shorter.keyColumns[i];\n const l = longer.keyColumns[i];\n if (\n s.name.toString() !== l.name.toString() ||\n (s.order ?? null) !== (l.order ?? null) ||\n (s.opclass ?? null) !== (l.opclass ?? null)\n ) {\n return null;\n }\n }\n return shorter.keyColumns;\n}\n\nexport function groupDuplicateIndexes(\n indexes: FullSchemaIndex[],\n): DuplicateIndexGroup[] {\n const groups: DuplicateIndexGroup[] = [];\n\n for (const index of indexes) {\n const existing = groups.find(\n (g) => g.kind === \"exact\" && indexesAreEqual(g.indexes[0], index),\n );\n if (existing) {\n existing.indexes.push(index);\n } else {\n groups.push({ kind: \"exact\", indexes: [index] });\n }\n }\n\n const exactGroups = groups.filter((g) => g.indexes.length > 1);\n\n const representatives = groups\n .filter((g) => g.indexes.length === 1)\n .map((g) => g.indexes[0]);\n\n const prefixGroups: Extract<DuplicateIndexGroup, { kind: \"prefix\" }>[] = [];\n\n for (const shorter of representatives) {\n const existing = prefixGroups.find((g) =>\n g.indexes.some(\n (idx) =>\n sharedPrefixColumns(shorter, idx) !== null ||\n sharedPrefixColumns(idx, shorter) !== null,\n ),\n );\n if (existing) {\n if (!existing.indexes.includes(shorter)) {\n existing.indexes.push(shorter);\n }\n } else {\n const longer = representatives.find(\n (idx) => idx !== shorter && sharedPrefixColumns(shorter, idx) !== null,\n );\n if (longer) {\n const sharedPrefix = sharedPrefixColumns(shorter, longer)!;\n prefixGroups.push({\n kind: \"prefix\",\n indexes: [longer, shorter],\n sharedPrefix,\n });\n }\n }\n }\n\n return [...exactGroups, ...prefixGroups];\n}\n"],"mappings":";;AAKA,SAAgB,iBAAiB,OAAsB;AACrD,QAAO,MAAM,cAAc,WAAW,MAAM,cAAc;;;;;;AAO5D,SAAgB,yBAAyB,OAAsB;AAG7D,QAAO,CAAC,MAAM,aAAa,CAAC,MAAM;;AAWpC,SAAS,aACP,GACA,GACS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