@anthonyalayo/drizzle-kit 1.0.2 → 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 +1 -1
  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,345 +0,0 @@
1
- import Docker from 'dockerode';
2
- import { sql } from 'drizzle-orm';
3
- import { check, int, mysqlTable, mysqlView } from 'drizzle-orm/mysql-core';
4
- import fs from 'fs';
5
- import getPort from 'get-port';
6
- import { Connection, createConnection } from 'mysql2/promise';
7
- import { diffTestSchemasPushMysql } from 'tests/schemaDiffer';
8
- import { v4 as uuid } from 'uuid';
9
- import { afterAll, beforeAll, expect, test } from 'vitest';
10
-
11
- let client: Connection;
12
- let mysqlContainer: Docker.Container;
13
-
14
- async function createDockerDB(): Promise<string> {
15
- const docker = new Docker();
16
- const port = await getPort({ port: 3306 });
17
- const image = 'mysql:8';
18
-
19
- const pullStream = await docker.pull(image);
20
- await new Promise((resolve, reject) =>
21
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
22
- docker.modem.followProgress(pullStream, (err) => err ? reject(err) : resolve(err))
23
- );
24
-
25
- mysqlContainer = await docker.createContainer({
26
- Image: image,
27
- Env: ['MYSQL_ROOT_PASSWORD=mysql', 'MYSQL_DATABASE=drizzle'],
28
- name: `drizzle-integration-tests-${uuid()}`,
29
- HostConfig: {
30
- AutoRemove: true,
31
- PortBindings: {
32
- '3306/tcp': [{ HostPort: `${port}` }],
33
- },
34
- },
35
- });
36
-
37
- await mysqlContainer.start();
38
-
39
- return `mysql://root:mysql@127.0.0.1:${port}/drizzle`;
40
- }
41
-
42
- beforeAll(async () => {
43
- const connectionString = process.env.MYSQL_CONNECTION_STRING ?? await createDockerDB();
44
-
45
- const sleep = 1000;
46
- let timeLeft = 20000;
47
- let connected = false;
48
- let lastError: unknown | undefined;
49
- do {
50
- try {
51
- client = await createConnection(connectionString);
52
- await client.connect();
53
- connected = true;
54
- break;
55
- } catch (e) {
56
- lastError = e;
57
- await new Promise((resolve) => setTimeout(resolve, sleep));
58
- timeLeft -= sleep;
59
- }
60
- } while (timeLeft > 0);
61
- if (!connected) {
62
- console.error('Cannot connect to MySQL');
63
- await client?.end().catch(console.error);
64
- await mysqlContainer?.stop().catch(console.error);
65
- throw lastError;
66
- }
67
- });
68
-
69
- afterAll(async () => {
70
- await client?.end().catch(console.error);
71
- await mysqlContainer?.stop().catch(console.error);
72
- });
73
-
74
- if (!fs.existsSync('tests/push/mysql')) {
75
- fs.mkdirSync('tests/push/mysql');
76
- }
77
-
78
- test('add check constraint to table', async () => {
79
- const schema1 = {
80
- test: mysqlTable('test', {
81
- id: int('id').primaryKey(),
82
- values: int('values'),
83
- }),
84
- };
85
- const schema2 = {
86
- test: mysqlTable('test', {
87
- id: int('id').primaryKey(),
88
- values: int('values'),
89
- }, (table) => ({
90
- checkConstraint1: check('some_check1', sql`${table.values} < 100`),
91
- checkConstraint2: check('some_check2', sql`'test' < 100`),
92
- })),
93
- };
94
-
95
- const { statements, sqlStatements } = await diffTestSchemasPushMysql(
96
- client,
97
- schema1,
98
- schema2,
99
- [],
100
- 'drizzle',
101
- false,
102
- );
103
-
104
- expect(statements).toStrictEqual([
105
- {
106
- type: 'create_check_constraint',
107
- tableName: 'test',
108
- schema: '',
109
- data: 'some_check1;\`test\`.\`values\` < 100',
110
- },
111
- {
112
- data: "some_check2;'test' < 100",
113
- schema: '',
114
- tableName: 'test',
115
- type: 'create_check_constraint',
116
- },
117
- ]);
118
- expect(sqlStatements).toStrictEqual([
119
- 'ALTER TABLE \`test\` ADD CONSTRAINT \`some_check1\` CHECK (\`test\`.\`values\` < 100);',
120
- `ALTER TABLE \`test\` ADD CONSTRAINT \`some_check2\` CHECK ('test' < 100);`,
121
- ]);
122
-
123
- await client.query(`DROP TABLE \`test\`;`);
124
- });
125
-
126
- test('drop check constraint to table', async () => {
127
- const schema1 = {
128
- test: mysqlTable('test', {
129
- id: int('id').primaryKey(),
130
- values: int('values'),
131
- }, (table) => ({
132
- checkConstraint1: check('some_check1', sql`${table.values} < 100`),
133
- checkConstraint2: check('some_check2', sql`'test' < 100`),
134
- })),
135
- };
136
- const schema2 = {
137
- test: mysqlTable('test', {
138
- id: int('id').primaryKey(),
139
- values: int('values'),
140
- }),
141
- };
142
-
143
- const { statements, sqlStatements } = await diffTestSchemasPushMysql(
144
- client,
145
- schema1,
146
- schema2,
147
- [],
148
- 'drizzle',
149
- false,
150
- );
151
-
152
- expect(statements).toStrictEqual([
153
- {
154
- type: 'delete_check_constraint',
155
- tableName: 'test',
156
- schema: '',
157
- constraintName: 'some_check1',
158
- },
159
- {
160
- constraintName: 'some_check2',
161
- schema: '',
162
- tableName: 'test',
163
- type: 'delete_check_constraint',
164
- },
165
- ]);
166
- expect(sqlStatements).toStrictEqual([
167
- 'ALTER TABLE \`test\` DROP CONSTRAINT \`some_check1\`;',
168
- `ALTER TABLE \`test\` DROP CONSTRAINT \`some_check2\`;`,
169
- ]);
170
-
171
- await client.query(`DROP TABLE \`test\`;`);
172
- });
173
-
174
- test('db has checks. Push with same names', async () => {
175
- const schema1 = {
176
- test: mysqlTable('test', {
177
- id: int('id').primaryKey(),
178
- values: int('values').default(1),
179
- }, (table) => ({
180
- checkConstraint: check('some_check', sql`${table.values} < 100`),
181
- })),
182
- };
183
- const schema2 = {
184
- test: mysqlTable('test', {
185
- id: int('id').primaryKey(),
186
- values: int('values').default(1),
187
- }, (table) => ({
188
- checkConstraint: check('some_check', sql`some new value`),
189
- })),
190
- };
191
-
192
- const { statements, sqlStatements } = await diffTestSchemasPushMysql(
193
- client,
194
- schema1,
195
- schema2,
196
- [],
197
- 'drizzle',
198
- );
199
-
200
- expect(statements).toStrictEqual([]);
201
- expect(sqlStatements).toStrictEqual([]);
202
-
203
- await client.query(`DROP TABLE \`test\`;`);
204
- });
205
-
206
- test('create view', async () => {
207
- const table = mysqlTable('test', {
208
- id: int('id').primaryKey(),
209
- });
210
-
211
- const schema1 = {
212
- test: table,
213
- };
214
-
215
- const schema2 = {
216
- test: table,
217
- view: mysqlView('view').as((qb) => qb.select().from(table)),
218
- };
219
-
220
- const { statements, sqlStatements } = await diffTestSchemasPushMysql(
221
- client,
222
- schema1,
223
- schema2,
224
- [],
225
- 'drizzle',
226
- false,
227
- );
228
-
229
- expect(statements).toStrictEqual([
230
- {
231
- definition: 'select \`id\` from \`test\`',
232
- name: 'view',
233
- type: 'mysql_create_view',
234
- replace: false,
235
- sqlSecurity: 'definer',
236
- withCheckOption: undefined,
237
- algorithm: 'undefined',
238
- },
239
- ]);
240
- expect(sqlStatements).toStrictEqual([
241
- `CREATE ALGORITHM = undefined
242
- SQL SECURITY definer
243
- VIEW \`view\` AS (select \`id\` from \`test\`);`,
244
- ]);
245
-
246
- await client.query(`DROP TABLE \`test\`;`);
247
- });
248
-
249
- test('drop view', async () => {
250
- const table = mysqlTable('test', {
251
- id: int('id').primaryKey(),
252
- });
253
-
254
- const schema1 = {
255
- test: table,
256
- view: mysqlView('view').as((qb) => qb.select().from(table)),
257
- };
258
-
259
- const schema2 = {
260
- test: table,
261
- };
262
-
263
- const { statements, sqlStatements } = await diffTestSchemasPushMysql(
264
- client,
265
- schema1,
266
- schema2,
267
- [],
268
- 'drizzle',
269
- false,
270
- );
271
-
272
- expect(statements).toStrictEqual([
273
- {
274
- name: 'view',
275
- type: 'drop_view',
276
- },
277
- ]);
278
- expect(sqlStatements).toStrictEqual([
279
- 'DROP VIEW \`view\`;',
280
- ]);
281
- await client.query(`DROP TABLE \`test\`;`);
282
- await client.query(`DROP VIEW \`view\`;`);
283
- });
284
-
285
- test('alter view ".as"', async () => {
286
- const table = mysqlTable('test', {
287
- id: int('id').primaryKey(),
288
- });
289
-
290
- const schema1 = {
291
- test: table,
292
- view: mysqlView('view').as((qb) => qb.select().from(table).where(sql`${table.id} = 1`)),
293
- };
294
-
295
- const schema2 = {
296
- test: table,
297
- view: mysqlView('view').as((qb) => qb.select().from(table)),
298
- };
299
-
300
- const { statements, sqlStatements } = await diffTestSchemasPushMysql(
301
- client,
302
- schema1,
303
- schema2,
304
- [],
305
- 'drizzle',
306
- false,
307
- );
308
-
309
- expect(statements.length).toBe(0);
310
- expect(sqlStatements.length).toBe(0);
311
-
312
- await client.query(`DROP TABLE \`test\`;`);
313
- await client.query(`DROP VIEW \`view\`;`);
314
- });
315
-
316
- test('alter meta options with distinct in definition', async () => {
317
- const table = mysqlTable('test', {
318
- id: int('id').primaryKey(),
319
- });
320
-
321
- const schema1 = {
322
- test: table,
323
- view: mysqlView('view').withCheckOption('cascaded').sqlSecurity('definer').algorithm('merge').as((
324
- qb,
325
- ) => qb.selectDistinct().from(table).where(sql`${table.id} = 1`)),
326
- };
327
-
328
- const schema2 = {
329
- test: table,
330
- view: mysqlView('view').withCheckOption('cascaded').sqlSecurity('definer').algorithm('undefined').as((qb) =>
331
- qb.selectDistinct().from(table)
332
- ),
333
- };
334
-
335
- await expect(diffTestSchemasPushMysql(
336
- client,
337
- schema1,
338
- schema2,
339
- [],
340
- 'drizzle',
341
- false,
342
- )).rejects.toThrowError();
343
-
344
- await client.query(`DROP TABLE \`test\`;`);
345
- });