@anthonyalayo/drizzle-kit 1.0.1 → 1.0.4

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
@@ -1,41 +0,0 @@
1
- import { is } from 'drizzle-orm';
2
- import { AnySQLiteTable, SQLiteTable, SQLiteView } from 'drizzle-orm/sqlite-core';
3
- import { safeRegister } from '../cli/commands/utils';
4
-
5
- export const prepareFromExports = (exports: Record<string, unknown>) => {
6
- const tables: AnySQLiteTable[] = [];
7
- const views: SQLiteView[] = [];
8
-
9
- const i0values = Object.values(exports);
10
- i0values.forEach((t) => {
11
- if (is(t, SQLiteTable)) {
12
- tables.push(t);
13
- }
14
-
15
- if (is(t, SQLiteView)) {
16
- views.push(t);
17
- }
18
- });
19
-
20
- return { tables, views };
21
- };
22
-
23
- export const prepareFromSqliteImports = async (imports: string[]) => {
24
- const tables: AnySQLiteTable[] = [];
25
- const views: SQLiteView[] = [];
26
-
27
- const { unregister } = await safeRegister();
28
- for (let i = 0; i < imports.length; i++) {
29
- const it = imports[i];
30
-
31
- const i0: Record<string, unknown> = require(`${it}`);
32
- const prepared = prepareFromExports(i0);
33
-
34
- tables.push(...prepared.tables);
35
- views.push(...prepared.views);
36
- }
37
-
38
- unregister();
39
-
40
- return { tables: Array.from(new Set(tables)), views };
41
- };
@@ -1,352 +0,0 @@
1
- import { any, boolean, enum as enumType, literal, object, record, string, TypeOf, union } from 'zod';
2
- import { customMapEntries, mapValues, originUUID } from '../global';
3
-
4
- // ------- V3 --------
5
- const index = object({
6
- name: string(),
7
- columns: string().array(),
8
- where: string().optional(),
9
- isUnique: boolean(),
10
- }).strict();
11
-
12
- const fk = object({
13
- name: string(),
14
- tableFrom: string(),
15
- columnsFrom: string().array(),
16
- tableTo: string(),
17
- columnsTo: string().array(),
18
- onUpdate: string().optional(),
19
- onDelete: string().optional(),
20
- }).strict();
21
-
22
- const compositePK = object({
23
- columns: string().array(),
24
- name: string().optional(),
25
- }).strict();
26
-
27
- const column = object({
28
- name: string(),
29
- type: string(),
30
- primaryKey: boolean(),
31
- notNull: boolean(),
32
- autoincrement: boolean().optional(),
33
- default: any().optional(),
34
- generated: object({
35
- type: enumType(['stored', 'virtual']),
36
- as: string(),
37
- }).optional(),
38
- }).strict();
39
-
40
- const tableV3 = object({
41
- name: string(),
42
- columns: record(string(), column),
43
- indexes: record(string(), index),
44
- foreignKeys: record(string(), fk),
45
- }).strict();
46
-
47
- const uniqueConstraint = object({
48
- name: string(),
49
- columns: string().array(),
50
- }).strict();
51
-
52
- const checkConstraint = object({
53
- name: string(),
54
- value: string(),
55
- }).strict();
56
-
57
- const table = object({
58
- name: string(),
59
- columns: record(string(), column),
60
- indexes: record(string(), index),
61
- foreignKeys: record(string(), fk),
62
- compositePrimaryKeys: record(string(), compositePK),
63
- uniqueConstraints: record(string(), uniqueConstraint).default({}),
64
- checkConstraints: record(string(), checkConstraint).default({}),
65
- }).strict();
66
-
67
- export const view = object({
68
- name: string(),
69
- columns: record(string(), column),
70
- definition: string().optional(),
71
- isExisting: boolean(),
72
- }).strict();
73
-
74
- // use main dialect
75
- const dialect = enumType(['sqlite']);
76
-
77
- const schemaHash = object({
78
- id: string(),
79
- prevId: string(),
80
- }).strict();
81
-
82
- export const schemaInternalV3 = object({
83
- version: literal('3'),
84
- dialect: dialect,
85
- tables: record(string(), tableV3),
86
- enums: object({}),
87
- }).strict();
88
-
89
- export const schemaInternalV4 = object({
90
- version: literal('4'),
91
- dialect: dialect,
92
- tables: record(string(), table),
93
- views: record(string(), view).default({}),
94
- enums: object({}),
95
- }).strict();
96
-
97
- export const schemaInternalV5 = object({
98
- version: literal('5'),
99
- dialect: dialect,
100
- tables: record(string(), table),
101
- enums: object({}),
102
- _meta: object({
103
- tables: record(string(), string()),
104
- columns: record(string(), string()),
105
- }),
106
- }).strict();
107
-
108
- export const kitInternals = object({
109
- indexes: record(
110
- string(),
111
- object({
112
- columns: record(
113
- string(),
114
- object({ isExpression: boolean().optional() }).optional(),
115
- ),
116
- }).optional(),
117
- ).optional(),
118
- }).optional();
119
-
120
- const latestVersion = literal('6');
121
- export const schemaInternal = object({
122
- version: latestVersion,
123
- dialect: dialect,
124
- tables: record(string(), table),
125
- views: record(string(), view).default({}),
126
- enums: object({}),
127
- _meta: object({
128
- tables: record(string(), string()),
129
- columns: record(string(), string()),
130
- }),
131
- internal: kitInternals,
132
- }).strict();
133
-
134
- export const schemaV3 = schemaInternalV3.merge(schemaHash).strict();
135
- export const schemaV4 = schemaInternalV4.merge(schemaHash).strict();
136
- export const schemaV5 = schemaInternalV5.merge(schemaHash).strict();
137
- export const schema = schemaInternal.merge(schemaHash).strict();
138
-
139
- const tableSquashed = object({
140
- name: string(),
141
- columns: record(string(), column),
142
- indexes: record(string(), string()),
143
- foreignKeys: record(string(), string()),
144
- compositePrimaryKeys: record(string(), string()),
145
- uniqueConstraints: record(string(), string()).default({}),
146
- checkConstraints: record(string(), string()).default({}),
147
- }).strict();
148
-
149
- export const schemaSquashed = object({
150
- version: latestVersion,
151
- dialect: dialect,
152
- tables: record(string(), tableSquashed),
153
- views: record(string(), view),
154
- enums: any(),
155
- }).strict();
156
-
157
- export type Dialect = TypeOf<typeof dialect>;
158
- export type Column = TypeOf<typeof column>;
159
- export type Table = TypeOf<typeof table>;
160
- export type SQLiteSchema = TypeOf<typeof schema>;
161
- export type SQLiteSchemaV3 = TypeOf<typeof schemaV3>;
162
- export type SQLiteSchemaV4 = TypeOf<typeof schemaV4>;
163
- export type SQLiteSchemaInternal = TypeOf<typeof schemaInternal>;
164
- export type SQLiteSchemaSquashed = TypeOf<typeof schemaSquashed>;
165
- export type SQLiteKitInternals = TypeOf<typeof kitInternals>;
166
- export type Index = TypeOf<typeof index>;
167
- export type ForeignKey = TypeOf<typeof fk>;
168
- export type PrimaryKey = TypeOf<typeof compositePK>;
169
- export type UniqueConstraint = TypeOf<typeof uniqueConstraint>;
170
- export type CheckConstraint = TypeOf<typeof checkConstraint>;
171
- export type View = TypeOf<typeof view>;
172
-
173
- export const SQLiteSquasher = {
174
- squashIdx: (idx: Index) => {
175
- index.parse(idx);
176
- return `${idx.name};${idx.columns.join(',')};${idx.isUnique};${idx.where ?? ''}`;
177
- },
178
- unsquashIdx: (input: string): Index => {
179
- const [name, columnsString, isUnique, where] = input.split(';');
180
-
181
- const result: Index = index.parse({
182
- name,
183
- columns: columnsString.split(','),
184
- isUnique: isUnique === 'true',
185
- where: where ?? undefined,
186
- });
187
- return result;
188
- },
189
- squashUnique: (unq: UniqueConstraint) => {
190
- return `${unq.name};${unq.columns.join(',')}`;
191
- },
192
- unsquashUnique: (unq: string): UniqueConstraint => {
193
- const [name, columns] = unq.split(';');
194
- return { name, columns: columns.split(',') };
195
- },
196
- squashFK: (fk: ForeignKey) => {
197
- return `${fk.name};${fk.tableFrom};${fk.columnsFrom.join(',')};${fk.tableTo};${fk.columnsTo.join(',')};${
198
- fk.onUpdate ?? ''
199
- };${fk.onDelete ?? ''}`;
200
- },
201
- unsquashFK: (input: string): ForeignKey => {
202
- const [
203
- name,
204
- tableFrom,
205
- columnsFromStr,
206
- tableTo,
207
- columnsToStr,
208
- onUpdate,
209
- onDelete,
210
- ] = input.split(';');
211
-
212
- const result: ForeignKey = fk.parse({
213
- name,
214
- tableFrom,
215
- columnsFrom: columnsFromStr.split(','),
216
- tableTo,
217
- columnsTo: columnsToStr.split(','),
218
- onUpdate,
219
- onDelete,
220
- });
221
- return result;
222
- },
223
- squashPushFK: (fk: ForeignKey) => {
224
- return `${fk.tableFrom};${fk.columnsFrom.join(',')};${fk.tableTo};${fk.columnsTo.join(',')};${fk.onUpdate ?? ''};${
225
- fk.onDelete ?? ''
226
- }`;
227
- },
228
- unsquashPushFK: (input: string): ForeignKey => {
229
- const [
230
- tableFrom,
231
- columnsFromStr,
232
- tableTo,
233
- columnsToStr,
234
- onUpdate,
235
- onDelete,
236
- ] = input.split(';');
237
-
238
- const result: ForeignKey = fk.parse({
239
- name: '',
240
- tableFrom,
241
- columnsFrom: columnsFromStr.split(','),
242
- tableTo,
243
- columnsTo: columnsToStr.split(','),
244
- onUpdate,
245
- onDelete,
246
- });
247
- return result;
248
- },
249
- squashPK: (pk: PrimaryKey) => {
250
- return pk.columns.join(',');
251
- },
252
- unsquashPK: (pk: string) => {
253
- return pk.split(',');
254
- },
255
- squashCheck: (check: CheckConstraint) => {
256
- return `${check.name};${check.value}`;
257
- },
258
- unsquashCheck: (input: string): CheckConstraint => {
259
- const [
260
- name,
261
- value,
262
- ] = input.split(';');
263
-
264
- return { name, value };
265
- },
266
- };
267
-
268
- export const squashSqliteScheme = (
269
- json: SQLiteSchema | SQLiteSchemaV4,
270
- action?: 'push' | undefined,
271
- ): SQLiteSchemaSquashed => {
272
- const mappedTables = Object.fromEntries(
273
- Object.entries(json.tables).map((it) => {
274
- const squashedIndexes = mapValues(it[1].indexes, (index: Index) => {
275
- return SQLiteSquasher.squashIdx(index);
276
- });
277
-
278
- const squashedFKs = customMapEntries<string, ForeignKey>(
279
- it[1].foreignKeys,
280
- (key, value) => {
281
- return action === 'push'
282
- ? [
283
- SQLiteSquasher.squashPushFK(value),
284
- SQLiteSquasher.squashPushFK(value),
285
- ]
286
- : [key, SQLiteSquasher.squashFK(value)];
287
- },
288
- );
289
-
290
- const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
291
- return SQLiteSquasher.squashPK(pk);
292
- });
293
-
294
- const squashedUniqueConstraints = mapValues(
295
- it[1].uniqueConstraints,
296
- (unq) => {
297
- return SQLiteSquasher.squashUnique(unq);
298
- },
299
- );
300
-
301
- const squashedCheckConstraints = mapValues(
302
- it[1].checkConstraints,
303
- (check) => {
304
- return SQLiteSquasher.squashCheck(check);
305
- },
306
- );
307
-
308
- return [
309
- it[0],
310
- {
311
- name: it[1].name,
312
- columns: it[1].columns,
313
- indexes: squashedIndexes,
314
- foreignKeys: squashedFKs,
315
- compositePrimaryKeys: squashedPKs,
316
- uniqueConstraints: squashedUniqueConstraints,
317
- checkConstraints: squashedCheckConstraints,
318
- },
319
- ];
320
- }),
321
- );
322
-
323
- return {
324
- version: '6',
325
- dialect: json.dialect,
326
- tables: mappedTables,
327
- views: json.views,
328
- enums: json.enums,
329
- };
330
- };
331
-
332
- export const drySQLite = schema.parse({
333
- version: '6',
334
- dialect: 'sqlite',
335
- id: originUUID,
336
- prevId: '',
337
- tables: {},
338
- views: {},
339
- enums: {},
340
- _meta: {
341
- tables: {},
342
- columns: {},
343
- },
344
- });
345
-
346
- export const sqliteSchemaV3 = schemaV3;
347
- export const sqliteSchemaV4 = schemaV4;
348
- export const sqliteSchemaV5 = schemaV5;
349
- export const sqliteSchema = schema;
350
- export const SQLiteSchemaSquashed = schemaSquashed;
351
-
352
- export const backwardCompatibleSqliteSchema = union([sqliteSchemaV5, schema]);