@anthonyalayo/drizzle-kit 1.0.2 → 1.0.5

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 (172) hide show
  1. package/api.d.mts +2891 -0
  2. package/api.d.ts +2891 -0
  3. package/api.js +47534 -0
  4. package/api.mjs +47521 -0
  5. package/bin.cjs +80043 -0
  6. package/{src/index.ts → index-Z-1TKnbX.d.mts} +123 -141
  7. package/index-Z-1TKnbX.d.ts +308 -0
  8. package/index.d.mts +2 -0
  9. package/index.d.ts +2 -0
  10. package/index.js +32 -0
  11. package/index.mjs +7 -0
  12. package/package.json +2 -2
  13. package/utils.js +6056 -0
  14. package/utils.mjs +6032 -0
  15. package/.gitignore +0 -25
  16. package/build.dev.ts +0 -51
  17. package/build.ts +0 -112
  18. package/imports-checker/analyze.ts +0 -78
  19. package/imports-checker/checker.ts +0 -296
  20. package/imports-checker/grammar/grammar.ohm +0 -121
  21. package/imports-checker/grammar/grammar.ohm-bundle.d.ts +0 -164
  22. package/imports-checker/grammar/grammar.ohm-bundle.js +0 -753
  23. package/imports-checker/index.ts +0 -48
  24. package/patches/difflib@0.2.4.patch +0 -31
  25. package/src/@types/utils.ts +0 -58
  26. package/src/api.ts +0 -504
  27. package/src/cli/commands/_es5.ts +0 -2
  28. package/src/cli/commands/check.ts +0 -52
  29. package/src/cli/commands/drop.ts +0 -60
  30. package/src/cli/commands/introspect.ts +0 -772
  31. package/src/cli/commands/libSqlPushUtils.ts +0 -355
  32. package/src/cli/commands/migrate.ts +0 -1526
  33. package/src/cli/commands/mysqlIntrospect.ts +0 -53
  34. package/src/cli/commands/mysqlPushUtils.ts +0 -352
  35. package/src/cli/commands/mysqlUp.ts +0 -102
  36. package/src/cli/commands/pgIntrospect.ts +0 -55
  37. package/src/cli/commands/pgPushUtils.ts +0 -269
  38. package/src/cli/commands/pgUp.ts +0 -217
  39. package/src/cli/commands/push.ts +0 -637
  40. package/src/cli/commands/singlestoreIntrospect.ts +0 -53
  41. package/src/cli/commands/singlestorePushUtils.ts +0 -456
  42. package/src/cli/commands/singlestoreUp.ts +0 -1
  43. package/src/cli/commands/sqliteIntrospect.ts +0 -96
  44. package/src/cli/commands/sqlitePushUtils.ts +0 -322
  45. package/src/cli/commands/sqliteUp.ts +0 -52
  46. package/src/cli/commands/utils.ts +0 -858
  47. package/src/cli/connections.ts +0 -914
  48. package/src/cli/index.ts +0 -48
  49. package/src/cli/schema.ts +0 -794
  50. package/src/cli/selector-ui.ts +0 -38
  51. package/src/cli/utils.ts +0 -112
  52. package/src/cli/validations/cli.ts +0 -79
  53. package/src/cli/validations/common.ts +0 -193
  54. package/src/cli/validations/libsql.ts +0 -27
  55. package/src/cli/validations/mysql.ts +0 -61
  56. package/src/cli/validations/outputs.ts +0 -91
  57. package/src/cli/validations/postgres.ts +0 -83
  58. package/src/cli/validations/singlestore.ts +0 -61
  59. package/src/cli/validations/sqlite.ts +0 -104
  60. package/src/cli/validations/studio.ts +0 -24
  61. package/src/cli/views.ts +0 -658
  62. package/src/extensions/getTablesFilterByExtensions.ts +0 -16
  63. package/src/extensions/vector.ts +0 -10
  64. package/src/global.ts +0 -61
  65. package/src/introspect-mysql.ts +0 -1030
  66. package/src/introspect-pg.ts +0 -1435
  67. package/src/introspect-singlestore.ts +0 -913
  68. package/src/introspect-sqlite.ts +0 -533
  69. package/src/jsonDiffer.js +0 -882
  70. package/src/jsonStatements.ts +0 -3590
  71. package/src/loader.mjs +0 -57
  72. package/src/migrationPreparator.ts +0 -217
  73. package/src/schemaValidator.ts +0 -23
  74. package/src/serializer/index.ts +0 -142
  75. package/src/serializer/mysqlImports.ts +0 -38
  76. package/src/serializer/mysqlSchema.ts +0 -423
  77. package/src/serializer/mysqlSerializer.ts +0 -999
  78. package/src/serializer/pgImports.ts +0 -106
  79. package/src/serializer/pgSchema.ts +0 -937
  80. package/src/serializer/pgSerializer.ts +0 -2223
  81. package/src/serializer/singlestoreImports.ts +0 -38
  82. package/src/serializer/singlestoreSchema.ts +0 -257
  83. package/src/serializer/singlestoreSerializer.ts +0 -767
  84. package/src/serializer/sqliteImports.ts +0 -41
  85. package/src/serializer/sqliteSchema.ts +0 -352
  86. package/src/serializer/sqliteSerializer.ts +0 -931
  87. package/src/serializer/studio.ts +0 -694
  88. package/src/serializer/utils.ts +0 -45
  89. package/src/simulator.ts +0 -157
  90. package/src/snapshotsDiffer.ts +0 -4398
  91. package/src/sqlgenerator.ts +0 -4212
  92. package/src/statementCombiner.ts +0 -597
  93. package/src/utils/certs.ts +0 -44
  94. package/src/utils/words.ts +0 -1333
  95. package/src/utils.ts +0 -370
  96. package/tests/bin.test.ts +0 -58
  97. package/tests/cli/d1http.config.ts +0 -12
  98. package/tests/cli/drizzle.config.ts +0 -9
  99. package/tests/cli/durable-sqlite.config.ts +0 -7
  100. package/tests/cli/expo.config.ts +0 -7
  101. package/tests/cli/postgres.config.ts +0 -13
  102. package/tests/cli/postgres2.config.ts +0 -17
  103. package/tests/cli/schema.ts +0 -1
  104. package/tests/cli/turso.config.ts +0 -10
  105. package/tests/cli-export.test.ts +0 -79
  106. package/tests/cli-generate.test.ts +0 -259
  107. package/tests/cli-migrate.test.ts +0 -103
  108. package/tests/cli-push.test.ts +0 -126
  109. package/tests/common.ts +0 -15
  110. package/tests/indexes/common.ts +0 -21
  111. package/tests/indexes/pg.test.ts +0 -245
  112. package/tests/introspect/libsql.test.ts +0 -35
  113. package/tests/introspect/mysql.test.ts +0 -319
  114. package/tests/introspect/pg.test.ts +0 -894
  115. package/tests/introspect/singlestore.test.ts +0 -275
  116. package/tests/introspect/sqlite.test.ts +0 -122
  117. package/tests/libsql-checks.test.ts +0 -308
  118. package/tests/libsql-statements.test.ts +0 -989
  119. package/tests/libsql-views.test.ts +0 -218
  120. package/tests/migrate/libsq-schema.ts +0 -6
  121. package/tests/migrate/libsql-migrate.test.ts +0 -58
  122. package/tests/migrate/migrations/0000_little_blizzard.sql +0 -4
  123. package/tests/migrate/migrations/0001_nebulous_storm.sql +0 -10
  124. package/tests/migrate/migrations/meta/0000_snapshot.json +0 -40
  125. package/tests/migrate/migrations/meta/0001_snapshot.json +0 -40
  126. package/tests/migrate/migrations/meta/_journal.json +0 -20
  127. package/tests/mysql-checks.test.ts +0 -291
  128. package/tests/mysql-generated.test.ts +0 -1290
  129. package/tests/mysql-schemas.test.ts +0 -156
  130. package/tests/mysql-views.test.ts +0 -553
  131. package/tests/mysql.test.ts +0 -863
  132. package/tests/pg-array.test.ts +0 -368
  133. package/tests/pg-checks.test.ts +0 -329
  134. package/tests/pg-columns.test.ts +0 -484
  135. package/tests/pg-domains.test.ts +0 -306
  136. package/tests/pg-enums.test.ts +0 -751
  137. package/tests/pg-generated.test.ts +0 -529
  138. package/tests/pg-identity.test.ts +0 -447
  139. package/tests/pg-schemas.test.ts +0 -105
  140. package/tests/pg-sequences.test.ts +0 -298
  141. package/tests/pg-tables.test.ts +0 -1021
  142. package/tests/pg-views.test.ts +0 -1929
  143. package/tests/push/common.ts +0 -58
  144. package/tests/push/libsql.test.ts +0 -1400
  145. package/tests/push/mysql-push.test.ts +0 -345
  146. package/tests/push/mysql.test.ts +0 -788
  147. package/tests/push/pg.test.ts +0 -4341
  148. package/tests/push/singlestore-push.test.ts +0 -894
  149. package/tests/push/singlestore.test.ts +0 -444
  150. package/tests/push/sqlite.test.ts +0 -1613
  151. package/tests/rls/pg-policy.test.ts +0 -1656
  152. package/tests/rls/pg-role.test.ts +0 -234
  153. package/tests/schemaDiffer.ts +0 -2852
  154. package/tests/singlestore-generated.test.ts +0 -1290
  155. package/tests/singlestore-schemas.test.ts +0 -155
  156. package/tests/singlestore.test.ts +0 -978
  157. package/tests/sqlite-checks.test.ts +0 -308
  158. package/tests/sqlite-columns.test.ts +0 -1049
  159. package/tests/sqlite-generated.test.ts +0 -1726
  160. package/tests/sqlite-tables.test.ts +0 -637
  161. package/tests/sqlite-views.test.ts +0 -218
  162. package/tests/statements-combiner/libsql-statements-combiner.test.ts +0 -1812
  163. package/tests/statements-combiner/singlestore-statements-combiner.test.ts +0 -882
  164. package/tests/statements-combiner/sqlite-statements-combiner.test.ts +0 -1211
  165. package/tests/test/sqlite.test.ts +0 -39
  166. package/tests/testsinglestore.ts +0 -29
  167. package/tests/validations.test.ts +0 -869
  168. package/tests/wrap-param.test.ts +0 -16
  169. package/tsconfig.build.json +0 -4
  170. package/tsconfig.cli-types.json +0 -9
  171. package/tsconfig.json +0 -28
  172. package/vitest.config.ts +0 -34
package/src/cli/views.ts DELETED
@@ -1,658 +0,0 @@
1
- import chalk from 'chalk';
2
- import { Prompt, render, SelectState, TaskView } from 'hanji';
3
- import type { CommonSchema } from '../schemaValidator';
4
- import { objectValues } from '../utils';
5
- import type { Named, NamedWithSchema } from './commands/migrate';
6
-
7
- export const warning = (msg: string) => {
8
- render(`[${chalk.yellow('Warning')}] ${msg}`);
9
- };
10
- export const err = (msg: string) => {
11
- render(`${chalk.bold.red('Error')} ${msg}`);
12
- };
13
-
14
- export const info = (msg: string, greyMsg: string = ''): string => {
15
- return `${chalk.blue.bold('Info:')} ${msg} ${greyMsg ? chalk.grey(greyMsg) : ''}`.trim();
16
- };
17
- export const grey = (msg: string): string => {
18
- return chalk.grey(msg);
19
- };
20
-
21
- export const error = (error: string, greyMsg: string = ''): string => {
22
- return `${chalk.bgRed.bold(' Error ')} ${error} ${greyMsg ? chalk.grey(greyMsg) : ''}`.trim();
23
- };
24
-
25
- export const schema = (schema: CommonSchema): string => {
26
- type TableEntry = (typeof schema)['tables'][keyof (typeof schema)['tables']];
27
- const tables = Object.values(schema.tables) as unknown as TableEntry[];
28
-
29
- let msg = chalk.bold(`${tables.length} tables\n`);
30
-
31
- msg += tables
32
- .map((t) => {
33
- const columnsCount = Object.values(t.columns).length;
34
- const indexesCount = Object.values(t.indexes).length;
35
- let foreignKeys: number = 0;
36
- // Singlestore doesn't have foreign keys
37
- if (schema.dialect !== 'singlestore') {
38
- // @ts-expect-error
39
- foreignKeys = Object.values(t.foreignKeys).length;
40
- }
41
-
42
- return `${chalk.bold.blue(t.name)} ${
43
- chalk.gray(
44
- `${columnsCount} columns ${indexesCount} indexes ${foreignKeys} fks`,
45
- )
46
- }`;
47
- })
48
- .join('\n');
49
-
50
- msg += '\n';
51
-
52
- const enums = objectValues(
53
- 'enums' in schema
54
- ? 'values' in schema['enums']
55
- ? schema['enums']
56
- : {}
57
- : {},
58
- );
59
-
60
- if (enums.length > 0) {
61
- msg += '\n';
62
- msg += chalk.bold(`${enums.length} enums\n`);
63
-
64
- msg += enums
65
- .map((it) => {
66
- return `${chalk.bold.blue(it.name)} ${
67
- chalk.gray(
68
- `[${Object.values(it.values).join(', ')}]`,
69
- )
70
- }`;
71
- })
72
- .join('\n');
73
- msg += '\n';
74
- }
75
- return msg;
76
- };
77
-
78
- export interface RenamePropmtItem<T> {
79
- from: T;
80
- to: T;
81
- }
82
-
83
- export const isRenamePromptItem = <T extends Named>(
84
- item: RenamePropmtItem<T> | T,
85
- ): item is RenamePropmtItem<T> => {
86
- return 'from' in item && 'to' in item;
87
- };
88
-
89
- export class ResolveColumnSelect<T extends Named> extends Prompt<
90
- RenamePropmtItem<T> | T
91
- > {
92
- private readonly data: SelectState<RenamePropmtItem<T> | T>;
93
-
94
- constructor(
95
- private readonly tableName: string,
96
- private readonly base: Named,
97
- data: (RenamePropmtItem<T> | T)[],
98
- ) {
99
- super();
100
- this.on('attach', (terminal) => terminal.toggleCursor('hide'));
101
- this.data = new SelectState(data);
102
- this.data.bind(this);
103
- }
104
-
105
- render(status: 'idle' | 'submitted' | 'aborted'): string {
106
- if (status === 'submitted' || status === 'aborted') {
107
- return '\n';
108
- }
109
-
110
- let text = `\nIs ${
111
- chalk.bold.blue(
112
- this.base.name,
113
- )
114
- } column in ${
115
- chalk.bold.blue(
116
- this.tableName,
117
- )
118
- } table created or renamed from another column?\n`;
119
-
120
- const isSelectedRenamed = isRenamePromptItem(
121
- this.data.items[this.data.selectedIdx],
122
- );
123
-
124
- const selectedPrefix = isSelectedRenamed
125
- ? chalk.yellow('❯ ')
126
- : chalk.green('❯ ');
127
-
128
- const labelLength: number = this.data.items
129
- .filter((it) => isRenamePromptItem(it))
130
- .map((it: RenamePropmtItem<T>) => {
131
- return this.base.name.length + 3 + it['from'].name.length;
132
- })
133
- .reduce((a, b) => {
134
- if (a > b) {
135
- return a;
136
- }
137
- return b;
138
- }, 0);
139
-
140
- this.data.items.forEach((it, idx) => {
141
- const isSelected = idx === this.data.selectedIdx;
142
- const isRenamed = isRenamePromptItem(it);
143
- const title = isRenamed
144
- ? `${it.from.name} › ${it.to.name}`.padEnd(labelLength, ' ')
145
- : it.name.padEnd(labelLength, ' ');
146
- const label = isRenamed
147
- ? `${chalk.yellow('~')} ${title} ${chalk.gray('rename column')}`
148
- : `${chalk.green('+')} ${title} ${chalk.gray('create column')}`;
149
-
150
- text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`;
151
- text += idx != this.data.items.length - 1 ? '\n' : '';
152
- });
153
- return text;
154
- }
155
-
156
- result(): RenamePropmtItem<T> | T {
157
- return this.data.items[this.data.selectedIdx]!;
158
- }
159
- }
160
-
161
- export const tableKey = (it: NamedWithSchema) => {
162
- return it.schema === 'public' || !it.schema
163
- ? it.name
164
- : `${it.schema}.${it.name}`;
165
- };
166
-
167
- export class ResolveSelectNamed<T extends Named> extends Prompt<
168
- RenamePropmtItem<T> | T
169
- > {
170
- private readonly state: SelectState<RenamePropmtItem<T> | T>;
171
-
172
- constructor(
173
- private readonly base: T,
174
- data: (RenamePropmtItem<T> | T)[],
175
- private readonly entityType: 'role' | 'policy',
176
- ) {
177
- super();
178
- this.on('attach', (terminal) => terminal.toggleCursor('hide'));
179
- this.state = new SelectState(data);
180
- this.state.bind(this);
181
- this.base = base;
182
- }
183
-
184
- render(status: 'idle' | 'submitted' | 'aborted'): string {
185
- if (status === 'submitted' || status === 'aborted') {
186
- return '';
187
- }
188
- const key = this.base.name;
189
-
190
- let text = `\nIs ${chalk.bold.blue(key)} ${this.entityType} created or renamed from another ${this.entityType}?\n`;
191
-
192
- const isSelectedRenamed = isRenamePromptItem(
193
- this.state.items[this.state.selectedIdx],
194
- );
195
-
196
- const selectedPrefix = isSelectedRenamed
197
- ? chalk.yellow('❯ ')
198
- : chalk.green('❯ ');
199
-
200
- const labelLength: number = this.state.items
201
- .filter((it) => isRenamePromptItem(it))
202
- .map((_) => {
203
- const it = _ as RenamePropmtItem<T>;
204
- const keyFrom = it.from.name;
205
- return key.length + 3 + keyFrom.length;
206
- })
207
- .reduce((a, b) => {
208
- if (a > b) {
209
- return a;
210
- }
211
- return b;
212
- }, 0);
213
-
214
- const entityType = this.entityType;
215
- this.state.items.forEach((it, idx) => {
216
- const isSelected = idx === this.state.selectedIdx;
217
- const isRenamed = isRenamePromptItem(it);
218
-
219
- const title = isRenamed
220
- ? `${it.from.name} › ${it.to.name}`.padEnd(labelLength, ' ')
221
- : it.name.padEnd(labelLength, ' ');
222
-
223
- const label = isRenamed
224
- ? `${chalk.yellow('~')} ${title} ${chalk.gray(`rename ${entityType}`)}`
225
- : `${chalk.green('+')} ${title} ${chalk.gray(`create ${entityType}`)}`;
226
-
227
- text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`;
228
- text += idx != this.state.items.length - 1 ? '\n' : '';
229
- });
230
- return text;
231
- }
232
-
233
- result(): RenamePropmtItem<T> | T {
234
- return this.state.items[this.state.selectedIdx]!;
235
- }
236
- }
237
-
238
- export class ResolveSelect<T extends NamedWithSchema> extends Prompt<
239
- RenamePropmtItem<T> | T
240
- > {
241
- private readonly state: SelectState<RenamePropmtItem<T> | T>;
242
-
243
- constructor(
244
- private readonly base: T,
245
- data: (RenamePropmtItem<T> | T)[],
246
- private readonly entityType: 'table' | 'domain' | 'enum' | 'sequence' | 'view' | 'role',
247
- ) {
248
- super();
249
- this.on('attach', (terminal) => terminal.toggleCursor('hide'));
250
- this.state = new SelectState(data);
251
- this.state.bind(this);
252
- this.base = base;
253
- }
254
-
255
- render(status: 'idle' | 'submitted' | 'aborted'): string {
256
- if (status === 'submitted' || status === 'aborted') {
257
- return '';
258
- }
259
- const key = tableKey(this.base);
260
-
261
- let text = `\nIs ${chalk.bold.blue(key)} ${this.entityType} created or renamed from another ${this.entityType}?\n`;
262
-
263
- const isSelectedRenamed = isRenamePromptItem(
264
- this.state.items[this.state.selectedIdx],
265
- );
266
-
267
- const selectedPrefix = isSelectedRenamed
268
- ? chalk.yellow('❯ ')
269
- : chalk.green('❯ ');
270
-
271
- const labelLength: number = this.state.items
272
- .filter((it) => isRenamePromptItem(it))
273
- .map((_) => {
274
- const it = _ as RenamePropmtItem<T>;
275
- const keyFrom = tableKey(it.from);
276
- return key.length + 3 + keyFrom.length;
277
- })
278
- .reduce((a, b) => {
279
- if (a > b) {
280
- return a;
281
- }
282
- return b;
283
- }, 0);
284
-
285
- const entityType = this.entityType;
286
- this.state.items.forEach((it, idx) => {
287
- const isSelected = idx === this.state.selectedIdx;
288
- const isRenamed = isRenamePromptItem(it);
289
-
290
- const title = isRenamed
291
- ? `${tableKey(it.from)} › ${tableKey(it.to)}`.padEnd(labelLength, ' ')
292
- : tableKey(it).padEnd(labelLength, ' ');
293
-
294
- const label = isRenamed
295
- ? `${chalk.yellow('~')} ${title} ${chalk.gray(`rename ${entityType}`)}`
296
- : `${chalk.green('+')} ${title} ${chalk.gray(`create ${entityType}`)}`;
297
-
298
- text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`;
299
- text += idx != this.state.items.length - 1 ? '\n' : '';
300
- });
301
- return text;
302
- }
303
-
304
- result(): RenamePropmtItem<T> | T {
305
- return this.state.items[this.state.selectedIdx]!;
306
- }
307
- }
308
-
309
- export class ResolveSchemasSelect<T extends Named> extends Prompt<
310
- RenamePropmtItem<T> | T
311
- > {
312
- private readonly state: SelectState<RenamePropmtItem<T> | T>;
313
-
314
- constructor(private readonly base: Named, data: (RenamePropmtItem<T> | T)[]) {
315
- super();
316
- this.on('attach', (terminal) => terminal.toggleCursor('hide'));
317
- this.state = new SelectState(data);
318
- this.state.bind(this);
319
- this.base = base;
320
- }
321
-
322
- render(status: 'idle' | 'submitted' | 'aborted'): string {
323
- if (status === 'submitted' || status === 'aborted') {
324
- return '';
325
- }
326
-
327
- let text = `\nIs ${
328
- chalk.bold.blue(
329
- this.base.name,
330
- )
331
- } schema created or renamed from another schema?\n`;
332
- const isSelectedRenamed = isRenamePromptItem(
333
- this.state.items[this.state.selectedIdx],
334
- );
335
- const selectedPrefix = isSelectedRenamed
336
- ? chalk.yellow('❯ ')
337
- : chalk.green('❯ ');
338
-
339
- const labelLength: number = this.state.items
340
- .filter((it) => isRenamePromptItem(it))
341
- .map((it: RenamePropmtItem<T>) => {
342
- return this.base.name.length + 3 + it['from'].name.length;
343
- })
344
- .reduce((a, b) => {
345
- if (a > b) {
346
- return a;
347
- }
348
- return b;
349
- }, 0);
350
-
351
- this.state.items.forEach((it, idx) => {
352
- const isSelected = idx === this.state.selectedIdx;
353
- const isRenamed = isRenamePromptItem(it);
354
- const title = isRenamed
355
- ? `${it.from.name} › ${it.to.name}`.padEnd(labelLength, ' ')
356
- : it.name.padEnd(labelLength, ' ');
357
- const label = isRenamed
358
- ? `${chalk.yellow('~')} ${title} ${chalk.gray('rename schema')}`
359
- : `${chalk.green('+')} ${title} ${chalk.gray('create schema')}`;
360
-
361
- text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`;
362
- text += idx != this.state.items.length - 1 ? '\n' : '';
363
- });
364
- return text;
365
- }
366
-
367
- result(): RenamePropmtItem<T> | T {
368
- return this.state.items[this.state.selectedIdx]!;
369
- }
370
- }
371
-
372
- class Spinner {
373
- private offset: number = 0;
374
- private readonly iterator: () => void;
375
-
376
- constructor(private readonly frames: string[]) {
377
- this.iterator = () => {
378
- this.offset += 1;
379
- this.offset %= frames.length - 1;
380
- };
381
- }
382
-
383
- public tick = () => {
384
- this.iterator();
385
- };
386
-
387
- public value = () => {
388
- return this.frames[this.offset];
389
- };
390
- }
391
-
392
- const frames = function(values: string[]): () => string {
393
- let index = 0;
394
- const iterator = () => {
395
- const frame = values[index];
396
- index += 1;
397
- index %= values.length;
398
- return frame!;
399
- };
400
- return iterator;
401
- };
402
-
403
- type ValueOf<T> = T[keyof T];
404
- export type IntrospectStatus = 'fetching' | 'done';
405
- export type IntrospectStage =
406
- | 'tables'
407
- | 'columns'
408
- | 'enums'
409
- | 'indexes'
410
- | 'policies'
411
- | 'checks'
412
- | 'fks'
413
- | 'views';
414
-
415
- type IntrospectState = {
416
- [key in IntrospectStage]: {
417
- count: number;
418
- name: string;
419
- status: IntrospectStatus;
420
- };
421
- };
422
-
423
- export class IntrospectProgress extends TaskView {
424
- private readonly spinner: Spinner = new Spinner('⣷⣯⣟⡿⢿⣻⣽⣾'.split(''));
425
- private timeout: NodeJS.Timeout | undefined;
426
-
427
- private state: IntrospectState = {
428
- tables: {
429
- count: 0,
430
- name: 'tables',
431
- status: 'fetching',
432
- },
433
- columns: {
434
- count: 0,
435
- name: 'columns',
436
- status: 'fetching',
437
- },
438
- enums: {
439
- count: 0,
440
- name: 'enums',
441
- status: 'fetching',
442
- },
443
- indexes: {
444
- count: 0,
445
- name: 'indexes',
446
- status: 'fetching',
447
- },
448
- fks: {
449
- count: 0,
450
- name: 'foreign keys',
451
- status: 'fetching',
452
- },
453
- policies: {
454
- count: 0,
455
- name: 'policies',
456
- status: 'fetching',
457
- },
458
- checks: {
459
- count: 0,
460
- name: 'check constraints',
461
- status: 'fetching',
462
- },
463
- views: {
464
- count: 0,
465
- name: 'views',
466
- status: 'fetching',
467
- },
468
- };
469
-
470
- constructor(private readonly hasEnums: boolean = false) {
471
- super();
472
- this.timeout = setInterval(() => {
473
- this.spinner.tick();
474
- this.requestLayout();
475
- }, 128);
476
-
477
- this.on('detach', () => clearInterval(this.timeout));
478
- }
479
-
480
- public update(
481
- stage: IntrospectStage,
482
- count: number,
483
- status: IntrospectStatus,
484
- ) {
485
- this.state[stage].count = count;
486
- this.state[stage].status = status;
487
- this.requestLayout();
488
- }
489
-
490
- private formatCount = (count: number) => {
491
- const width: number = Math.max.apply(
492
- null,
493
- Object.values(this.state).map((it) => it.count.toFixed(0).length),
494
- );
495
-
496
- return count.toFixed(0).padEnd(width, ' ');
497
- };
498
-
499
- private statusText = (spinner: string, stage: ValueOf<IntrospectState>) => {
500
- const { name, count } = stage;
501
- const isDone = stage.status === 'done';
502
-
503
- const prefix = isDone ? `[${chalk.green('✓')}]` : `[${spinner}]`;
504
-
505
- const formattedCount = this.formatCount(count);
506
- const suffix = isDone
507
- ? `${formattedCount} ${name} fetched`
508
- : `${formattedCount} ${name} fetching`;
509
-
510
- return `${prefix} ${suffix}\n`;
511
- };
512
-
513
- render(): string {
514
- let info = '';
515
- const spin = this.spinner.value();
516
- info += this.statusText(spin, this.state.tables);
517
- info += this.statusText(spin, this.state.columns);
518
- info += this.hasEnums ? this.statusText(spin, this.state.enums) : '';
519
- info += this.statusText(spin, this.state.indexes);
520
- info += this.statusText(spin, this.state.fks);
521
- info += this.statusText(spin, this.state.policies);
522
- info += this.statusText(spin, this.state.checks);
523
- info += this.statusText(spin, this.state.views);
524
-
525
- return info;
526
- }
527
- }
528
-
529
- export class MigrateProgress extends TaskView {
530
- private readonly spinner: Spinner = new Spinner('⣷⣯⣟⡿⢿⣻⣽⣾'.split(''));
531
- private timeout: NodeJS.Timeout | undefined;
532
-
533
- constructor() {
534
- super();
535
- this.timeout = setInterval(() => {
536
- this.spinner.tick();
537
- this.requestLayout();
538
- }, 128);
539
-
540
- this.on('detach', () => clearInterval(this.timeout));
541
- }
542
-
543
- render(status: 'pending' | 'done'): string {
544
- if (status === 'pending') {
545
- const spin = this.spinner.value();
546
- return `[${spin}] applying migrations...`;
547
- }
548
- return `[${chalk.green('✓')}] migrations applied successfully!`;
549
- }
550
- }
551
-
552
- export class ProgressView extends TaskView {
553
- private readonly spinner: Spinner = new Spinner('⣷⣯⣟⡿⢿⣻⣽⣾'.split(''));
554
- private timeout: NodeJS.Timeout | undefined;
555
-
556
- constructor(
557
- private readonly progressText: string,
558
- private readonly successText: string,
559
- ) {
560
- super();
561
- this.timeout = setInterval(() => {
562
- this.spinner.tick();
563
- this.requestLayout();
564
- }, 128);
565
-
566
- this.on('detach', () => clearInterval(this.timeout));
567
- }
568
-
569
- render(status: 'pending' | 'done'): string {
570
- if (status === 'pending') {
571
- const spin = this.spinner.value();
572
- return `[${spin}] ${this.progressText}\n`;
573
- }
574
- return `[${chalk.green('✓')}] ${this.successText}\n`;
575
- }
576
- }
577
-
578
- export class DropMigrationView<T extends { tag: string }> extends Prompt<T> {
579
- private readonly data: SelectState<T>;
580
-
581
- constructor(data: T[]) {
582
- super();
583
- this.on('attach', (terminal) => terminal.toggleCursor('hide'));
584
- this.data = new SelectState(data);
585
- this.data.selectedIdx = data.length - 1;
586
- this.data.bind(this);
587
- }
588
-
589
- render(status: 'idle' | 'submitted' | 'aborted'): string {
590
- if (status === 'submitted' || status === 'aborted') {
591
- return '\n';
592
- }
593
-
594
- let text = chalk.bold('Please select migration to drop:\n');
595
- const selectedPrefix = chalk.yellow('❯ ');
596
-
597
- const data = trimmedRange(this.data.items, this.data.selectedIdx, 9);
598
- const labelLength: number = data.trimmed
599
- .map((it) => it.tag.length)
600
- .reduce((a, b) => {
601
- if (a > b) {
602
- return a;
603
- }
604
- return b;
605
- }, 0);
606
-
607
- text += data.startTrimmed ? ' ...\n' : '';
608
-
609
- data.trimmed.forEach((it, idx) => {
610
- const isSelected = idx === this.data.selectedIdx - data.offset;
611
- let title = it.tag.padEnd(labelLength, ' ');
612
- title = isSelected ? chalk.yellow(title) : title;
613
-
614
- text += isSelected ? `${selectedPrefix}${title}` : ` ${title}`;
615
- text += idx != this.data.items.length - 1 ? '\n' : '';
616
- });
617
-
618
- text += data.endTrimmed ? ' ...\n' : '';
619
- return text;
620
- }
621
-
622
- result(): T {
623
- return this.data.items[this.data.selectedIdx]!;
624
- }
625
- }
626
-
627
- export const trimmedRange = <T>(
628
- arr: T[],
629
- index: number,
630
- limitLines: number,
631
- ): {
632
- trimmed: T[];
633
- offset: number;
634
- startTrimmed: boolean;
635
- endTrimmed: boolean;
636
- } => {
637
- const limit = limitLines - 2;
638
- const sideLimit = Math.round(limit / 2);
639
-
640
- const endTrimmed = arr.length - sideLimit > index;
641
- const startTrimmed = index > sideLimit - 1;
642
-
643
- const paddingStart = Math.max(index + sideLimit - arr.length, 0);
644
- const paddingEnd = Math.min(index - sideLimit + 1, 0);
645
-
646
- const d1 = endTrimmed ? 1 : 0;
647
- const d2 = startTrimmed ? 0 : 1;
648
-
649
- const start = Math.max(0, index - sideLimit + d1 - paddingStart);
650
- const end = Math.min(arr.length, index + sideLimit + d2 - paddingEnd);
651
-
652
- return {
653
- trimmed: arr.slice(start, end),
654
- offset: start,
655
- startTrimmed,
656
- endTrimmed,
657
- };
658
- };
@@ -1,16 +0,0 @@
1
- import type { Config } from '../index';
2
-
3
- export const getTablesFilterByExtensions = ({
4
- extensionsFilters,
5
- dialect,
6
- }: Pick<Config, 'extensionsFilters' | 'dialect'>): string[] => {
7
- if (extensionsFilters) {
8
- if (
9
- extensionsFilters.includes('postgis')
10
- && dialect === 'postgresql'
11
- ) {
12
- return ['!geography_columns', '!geometry_columns', '!spatial_ref_sys'];
13
- }
14
- }
15
- return [];
16
- };
@@ -1,10 +0,0 @@
1
- export const vectorOps = [
2
- 'vector_l2_ops',
3
- 'vector_ip_ops',
4
- 'vector_cosine_ops',
5
- 'vector_l1_ops',
6
- 'bit_hamming_ops',
7
- 'bit_jaccard_ops',
8
- 'halfvec_l2_ops',
9
- 'sparsevec_l2_ops',
10
- ];