@anthonyalayo/drizzle-kit 1.0.1

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 (161) hide show
  1. package/.gitignore +25 -0
  2. package/README.md +79 -0
  3. package/build.dev.ts +51 -0
  4. package/build.ts +112 -0
  5. package/imports-checker/analyze.ts +78 -0
  6. package/imports-checker/checker.ts +296 -0
  7. package/imports-checker/grammar/grammar.ohm +121 -0
  8. package/imports-checker/grammar/grammar.ohm-bundle.d.ts +164 -0
  9. package/imports-checker/grammar/grammar.ohm-bundle.js +753 -0
  10. package/imports-checker/index.ts +48 -0
  11. package/package.json +142 -0
  12. package/patches/difflib@0.2.4.patch +31 -0
  13. package/src/@types/utils.ts +58 -0
  14. package/src/api.ts +504 -0
  15. package/src/cli/commands/_es5.ts +2 -0
  16. package/src/cli/commands/check.ts +52 -0
  17. package/src/cli/commands/drop.ts +60 -0
  18. package/src/cli/commands/introspect.ts +772 -0
  19. package/src/cli/commands/libSqlPushUtils.ts +355 -0
  20. package/src/cli/commands/migrate.ts +1526 -0
  21. package/src/cli/commands/mysqlIntrospect.ts +53 -0
  22. package/src/cli/commands/mysqlPushUtils.ts +352 -0
  23. package/src/cli/commands/mysqlUp.ts +102 -0
  24. package/src/cli/commands/pgIntrospect.ts +55 -0
  25. package/src/cli/commands/pgPushUtils.ts +269 -0
  26. package/src/cli/commands/pgUp.ts +217 -0
  27. package/src/cli/commands/push.ts +637 -0
  28. package/src/cli/commands/singlestoreIntrospect.ts +53 -0
  29. package/src/cli/commands/singlestorePushUtils.ts +456 -0
  30. package/src/cli/commands/singlestoreUp.ts +1 -0
  31. package/src/cli/commands/sqliteIntrospect.ts +96 -0
  32. package/src/cli/commands/sqlitePushUtils.ts +322 -0
  33. package/src/cli/commands/sqliteUp.ts +52 -0
  34. package/src/cli/commands/utils.ts +858 -0
  35. package/src/cli/connections.ts +914 -0
  36. package/src/cli/index.ts +48 -0
  37. package/src/cli/schema.ts +794 -0
  38. package/src/cli/selector-ui.ts +38 -0
  39. package/src/cli/utils.ts +112 -0
  40. package/src/cli/validations/cli.ts +79 -0
  41. package/src/cli/validations/common.ts +193 -0
  42. package/src/cli/validations/libsql.ts +27 -0
  43. package/src/cli/validations/mysql.ts +61 -0
  44. package/src/cli/validations/outputs.ts +91 -0
  45. package/src/cli/validations/postgres.ts +83 -0
  46. package/src/cli/validations/singlestore.ts +61 -0
  47. package/src/cli/validations/sqlite.ts +104 -0
  48. package/src/cli/validations/studio.ts +24 -0
  49. package/src/cli/views.ts +658 -0
  50. package/src/extensions/getTablesFilterByExtensions.ts +16 -0
  51. package/src/extensions/vector.ts +10 -0
  52. package/src/global.ts +61 -0
  53. package/src/index.ts +326 -0
  54. package/src/introspect-mysql.ts +1030 -0
  55. package/src/introspect-pg.ts +1435 -0
  56. package/src/introspect-singlestore.ts +913 -0
  57. package/src/introspect-sqlite.ts +533 -0
  58. package/src/jsonDiffer.js +882 -0
  59. package/src/jsonStatements.ts +3590 -0
  60. package/src/loader.mjs +57 -0
  61. package/src/migrationPreparator.ts +217 -0
  62. package/src/schemaValidator.ts +23 -0
  63. package/src/serializer/index.ts +142 -0
  64. package/src/serializer/mysqlImports.ts +38 -0
  65. package/src/serializer/mysqlSchema.ts +423 -0
  66. package/src/serializer/mysqlSerializer.ts +999 -0
  67. package/src/serializer/pgImports.ts +106 -0
  68. package/src/serializer/pgSchema.ts +937 -0
  69. package/src/serializer/pgSerializer.ts +2223 -0
  70. package/src/serializer/singlestoreImports.ts +38 -0
  71. package/src/serializer/singlestoreSchema.ts +257 -0
  72. package/src/serializer/singlestoreSerializer.ts +767 -0
  73. package/src/serializer/sqliteImports.ts +41 -0
  74. package/src/serializer/sqliteSchema.ts +352 -0
  75. package/src/serializer/sqliteSerializer.ts +931 -0
  76. package/src/serializer/studio.ts +694 -0
  77. package/src/serializer/utils.ts +45 -0
  78. package/src/simulator.ts +157 -0
  79. package/src/snapshotsDiffer.ts +4398 -0
  80. package/src/sqlgenerator.ts +4212 -0
  81. package/src/statementCombiner.ts +597 -0
  82. package/src/utils/certs.ts +44 -0
  83. package/src/utils/words.ts +1333 -0
  84. package/src/utils.ts +370 -0
  85. package/tests/bin.test.ts +58 -0
  86. package/tests/cli/d1http.config.ts +12 -0
  87. package/tests/cli/drizzle.config.ts +9 -0
  88. package/tests/cli/durable-sqlite.config.ts +7 -0
  89. package/tests/cli/expo.config.ts +7 -0
  90. package/tests/cli/postgres.config.ts +13 -0
  91. package/tests/cli/postgres2.config.ts +17 -0
  92. package/tests/cli/schema.ts +1 -0
  93. package/tests/cli/turso.config.ts +10 -0
  94. package/tests/cli-export.test.ts +79 -0
  95. package/tests/cli-generate.test.ts +259 -0
  96. package/tests/cli-migrate.test.ts +103 -0
  97. package/tests/cli-push.test.ts +126 -0
  98. package/tests/common.ts +15 -0
  99. package/tests/indexes/common.ts +21 -0
  100. package/tests/indexes/pg.test.ts +245 -0
  101. package/tests/introspect/libsql.test.ts +35 -0
  102. package/tests/introspect/mysql.test.ts +319 -0
  103. package/tests/introspect/pg.test.ts +894 -0
  104. package/tests/introspect/singlestore.test.ts +275 -0
  105. package/tests/introspect/sqlite.test.ts +122 -0
  106. package/tests/libsql-checks.test.ts +308 -0
  107. package/tests/libsql-statements.test.ts +989 -0
  108. package/tests/libsql-views.test.ts +218 -0
  109. package/tests/migrate/libsq-schema.ts +6 -0
  110. package/tests/migrate/libsql-migrate.test.ts +58 -0
  111. package/tests/migrate/migrations/0000_little_blizzard.sql +4 -0
  112. package/tests/migrate/migrations/0001_nebulous_storm.sql +10 -0
  113. package/tests/migrate/migrations/meta/0000_snapshot.json +40 -0
  114. package/tests/migrate/migrations/meta/0001_snapshot.json +40 -0
  115. package/tests/migrate/migrations/meta/_journal.json +20 -0
  116. package/tests/mysql-checks.test.ts +291 -0
  117. package/tests/mysql-generated.test.ts +1290 -0
  118. package/tests/mysql-schemas.test.ts +156 -0
  119. package/tests/mysql-views.test.ts +553 -0
  120. package/tests/mysql.test.ts +863 -0
  121. package/tests/pg-array.test.ts +368 -0
  122. package/tests/pg-checks.test.ts +329 -0
  123. package/tests/pg-columns.test.ts +484 -0
  124. package/tests/pg-domains.test.ts +306 -0
  125. package/tests/pg-enums.test.ts +751 -0
  126. package/tests/pg-generated.test.ts +529 -0
  127. package/tests/pg-identity.test.ts +447 -0
  128. package/tests/pg-schemas.test.ts +105 -0
  129. package/tests/pg-sequences.test.ts +298 -0
  130. package/tests/pg-tables.test.ts +1021 -0
  131. package/tests/pg-views.test.ts +1929 -0
  132. package/tests/push/common.ts +58 -0
  133. package/tests/push/libsql.test.ts +1400 -0
  134. package/tests/push/mysql-push.test.ts +345 -0
  135. package/tests/push/mysql.test.ts +788 -0
  136. package/tests/push/pg.test.ts +4341 -0
  137. package/tests/push/singlestore-push.test.ts +894 -0
  138. package/tests/push/singlestore.test.ts +444 -0
  139. package/tests/push/sqlite.test.ts +1613 -0
  140. package/tests/rls/pg-policy.test.ts +1656 -0
  141. package/tests/rls/pg-role.test.ts +234 -0
  142. package/tests/schemaDiffer.ts +2852 -0
  143. package/tests/singlestore-generated.test.ts +1290 -0
  144. package/tests/singlestore-schemas.test.ts +155 -0
  145. package/tests/singlestore.test.ts +978 -0
  146. package/tests/sqlite-checks.test.ts +308 -0
  147. package/tests/sqlite-columns.test.ts +1049 -0
  148. package/tests/sqlite-generated.test.ts +1726 -0
  149. package/tests/sqlite-tables.test.ts +637 -0
  150. package/tests/sqlite-views.test.ts +218 -0
  151. package/tests/statements-combiner/libsql-statements-combiner.test.ts +1812 -0
  152. package/tests/statements-combiner/singlestore-statements-combiner.test.ts +882 -0
  153. package/tests/statements-combiner/sqlite-statements-combiner.test.ts +1211 -0
  154. package/tests/test/sqlite.test.ts +39 -0
  155. package/tests/testsinglestore.ts +29 -0
  156. package/tests/validations.test.ts +869 -0
  157. package/tests/wrap-param.test.ts +16 -0
  158. package/tsconfig.build.json +4 -0
  159. package/tsconfig.cli-types.json +9 -0
  160. package/tsconfig.json +28 -0
  161. package/vitest.config.ts +34 -0
@@ -0,0 +1,447 @@
1
+ import { integer, pgSequence, pgTable } from 'drizzle-orm/pg-core';
2
+ import { expect, test } from 'vitest';
3
+ import { diffTestSchemas } from './schemaDiffer';
4
+
5
+ // same table - no diff
6
+ // 2. identity always/by default - no params +
7
+ // 3. identity always/by default - with a few params +
8
+ // 4. identity always/by default - with all params +
9
+
10
+ // diff table with create statement
11
+ // 2. identity always/by default - no params +
12
+ // 3. identity always/by default - with a few params +
13
+ // 4. identity always/by default - with all params +
14
+
15
+ // diff for drop statement
16
+ // 2. identity always/by default - no params, with params +
17
+
18
+ // diff for alters
19
+ // 2. identity always/by default - no params -> add param +
20
+ // 3. identity always/by default - with a few params - remove/add/change params +
21
+ // 4. identity always/by default - with all params - remove/add/change params +
22
+
23
+ test('create table: identity always/by default - no params', async () => {
24
+ const from = {};
25
+
26
+ const to = {
27
+ users: pgTable('users', {
28
+ id: integer('id').generatedByDefaultAsIdentity(),
29
+ }),
30
+ };
31
+
32
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
33
+
34
+ expect(statements).toStrictEqual([
35
+ {
36
+ columns: [
37
+ {
38
+ identity: 'users_id_seq;byDefault;1;2147483647;1;1;1;false',
39
+ name: 'id',
40
+ notNull: true,
41
+ primaryKey: false,
42
+ type: 'integer',
43
+ },
44
+ ],
45
+ compositePKs: [],
46
+ compositePkName: '',
47
+ schema: '',
48
+ policies: [],
49
+ isRLSEnabled: false,
50
+ tableName: 'users',
51
+ type: 'create_table',
52
+ uniqueConstraints: [],
53
+ checkConstraints: [],
54
+ },
55
+ ]);
56
+ expect(sqlStatements).toStrictEqual([
57
+ 'CREATE TABLE "users" (\n\t"id" integer GENERATED BY DEFAULT AS IDENTITY (sequence name "users_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1)\n);\n',
58
+ ]);
59
+ });
60
+
61
+ test('create table: identity always/by default - few params', async () => {
62
+ const from = {};
63
+
64
+ const to = {
65
+ users: pgTable('users', {
66
+ id: integer('id').generatedByDefaultAsIdentity({
67
+ name: 'custom_seq',
68
+ increment: 4,
69
+ }),
70
+ }),
71
+ };
72
+
73
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
74
+
75
+ expect(statements).toStrictEqual([
76
+ {
77
+ columns: [
78
+ {
79
+ identity: 'custom_seq;byDefault;1;2147483647;4;1;1;false',
80
+ name: 'id',
81
+ notNull: true,
82
+ primaryKey: false,
83
+ type: 'integer',
84
+ },
85
+ ],
86
+ compositePKs: [],
87
+ compositePkName: '',
88
+ policies: [],
89
+ schema: '',
90
+ isRLSEnabled: false,
91
+ tableName: 'users',
92
+ type: 'create_table',
93
+ uniqueConstraints: [],
94
+ checkConstraints: [],
95
+ },
96
+ ]);
97
+ expect(sqlStatements).toStrictEqual([
98
+ 'CREATE TABLE "users" (\n\t"id" integer GENERATED BY DEFAULT AS IDENTITY (sequence name "custom_seq" INCREMENT BY 4 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1)\n);\n',
99
+ ]);
100
+ });
101
+
102
+ test('create table: identity always/by default - all params', async () => {
103
+ const from = {};
104
+
105
+ const to = {
106
+ users: pgTable('users', {
107
+ id: integer('id').generatedByDefaultAsIdentity({
108
+ name: 'custom_seq',
109
+ increment: 4,
110
+ minValue: 3,
111
+ maxValue: 1000,
112
+ cache: 200,
113
+ cycle: false,
114
+ }),
115
+ }),
116
+ };
117
+
118
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
119
+
120
+ expect(statements).toStrictEqual([
121
+ {
122
+ columns: [
123
+ {
124
+ identity: 'custom_seq;byDefault;3;1000;4;3;200;false',
125
+ name: 'id',
126
+ notNull: true,
127
+ primaryKey: false,
128
+ type: 'integer',
129
+ },
130
+ ],
131
+ compositePKs: [],
132
+ compositePkName: '',
133
+ policies: [],
134
+ isRLSEnabled: false,
135
+ schema: '',
136
+ tableName: 'users',
137
+ type: 'create_table',
138
+ uniqueConstraints: [],
139
+ checkConstraints: [],
140
+ },
141
+ ]);
142
+ expect(sqlStatements).toStrictEqual([
143
+ 'CREATE TABLE "users" (\n\t"id" integer GENERATED BY DEFAULT AS IDENTITY (sequence name "custom_seq" INCREMENT BY 4 MINVALUE 3 MAXVALUE 1000 START WITH 3 CACHE 200)\n);\n',
144
+ ]);
145
+ });
146
+
147
+ test('no diff: identity always/by default - no params', async () => {
148
+ const from = {
149
+ users: pgTable('users', {
150
+ id: integer('id').generatedByDefaultAsIdentity(),
151
+ }),
152
+ };
153
+
154
+ const to = {
155
+ users: pgTable('users', {
156
+ id: integer('id').generatedByDefaultAsIdentity(),
157
+ }),
158
+ };
159
+
160
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
161
+
162
+ expect(statements).toStrictEqual([]);
163
+ expect(sqlStatements).toStrictEqual([]);
164
+ });
165
+
166
+ test('no diff: identity always/by default - few params', async () => {
167
+ const from = {
168
+ users: pgTable('users', {
169
+ id: integer('id').generatedByDefaultAsIdentity({
170
+ name: 'custom_seq',
171
+ increment: 4,
172
+ }),
173
+ }),
174
+ };
175
+
176
+ const to = {
177
+ users: pgTable('users', {
178
+ id: integer('id').generatedByDefaultAsIdentity({
179
+ name: 'custom_seq',
180
+ increment: 4,
181
+ }),
182
+ }),
183
+ };
184
+
185
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
186
+
187
+ expect(statements).toStrictEqual([]);
188
+ expect(sqlStatements).toStrictEqual([]);
189
+ });
190
+
191
+ test('no diff: identity always/by default - all params', async () => {
192
+ const from = {
193
+ users: pgTable('users', {
194
+ id: integer('id').generatedByDefaultAsIdentity({
195
+ name: 'custom_seq',
196
+ increment: 4,
197
+ minValue: 3,
198
+ maxValue: 1000,
199
+ cache: 200,
200
+ cycle: false,
201
+ }),
202
+ }),
203
+ };
204
+
205
+ const to = {
206
+ users: pgTable('users', {
207
+ id: integer('id').generatedByDefaultAsIdentity({
208
+ name: 'custom_seq',
209
+ increment: 4,
210
+ minValue: 3,
211
+ maxValue: 1000,
212
+ cache: 200,
213
+ cycle: false,
214
+ }),
215
+ }),
216
+ };
217
+
218
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
219
+
220
+ expect(statements).toStrictEqual([]);
221
+ expect(sqlStatements).toStrictEqual([]);
222
+ });
223
+
224
+ test('drop identity from a column - no params', async () => {
225
+ const from = {
226
+ users: pgTable('users', {
227
+ id: integer('id').generatedByDefaultAsIdentity(),
228
+ }),
229
+ };
230
+
231
+ const to = {
232
+ users: pgTable('users', {
233
+ id: integer('id'),
234
+ }),
235
+ };
236
+
237
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
238
+
239
+ expect(statements).toStrictEqual([
240
+ {
241
+ columnName: 'id',
242
+ schema: '',
243
+ tableName: 'users',
244
+ type: 'alter_table_alter_column_drop_identity',
245
+ },
246
+ ]);
247
+ expect(sqlStatements).toStrictEqual([
248
+ `ALTER TABLE \"users\" ALTER COLUMN \"id\" DROP IDENTITY;`,
249
+ ]);
250
+ });
251
+
252
+ test('drop identity from a column - few params', async () => {
253
+ const from = {
254
+ users: pgTable('users', {
255
+ id: integer('id').generatedByDefaultAsIdentity({
256
+ startWith: 100,
257
+ increment: 3,
258
+ }),
259
+ }),
260
+ };
261
+
262
+ const to = {
263
+ users: pgTable('users', {
264
+ id: integer('id'),
265
+ }),
266
+ };
267
+
268
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
269
+
270
+ expect(statements).toStrictEqual([
271
+ {
272
+ columnName: 'id',
273
+ schema: '',
274
+ tableName: 'users',
275
+ type: 'alter_table_alter_column_drop_identity',
276
+ },
277
+ ]);
278
+ expect(sqlStatements).toStrictEqual([
279
+ `ALTER TABLE \"users\" ALTER COLUMN \"id\" DROP IDENTITY;`,
280
+ ]);
281
+ });
282
+
283
+ test('drop identity from a column - all params', async () => {
284
+ const from = {
285
+ users: pgTable('users', {
286
+ id: integer('id').generatedByDefaultAsIdentity({
287
+ startWith: 100,
288
+ increment: 3,
289
+ cache: 100,
290
+ cycle: true,
291
+ }),
292
+ }),
293
+ };
294
+
295
+ const to = {
296
+ users: pgTable('users', {
297
+ id: integer('id'),
298
+ }),
299
+ };
300
+
301
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
302
+
303
+ expect(statements).toStrictEqual([
304
+ {
305
+ columnName: 'id',
306
+ schema: '',
307
+ tableName: 'users',
308
+ type: 'alter_table_alter_column_drop_identity',
309
+ },
310
+ ]);
311
+ expect(sqlStatements).toStrictEqual([
312
+ `ALTER TABLE \"users\" ALTER COLUMN \"id\" DROP IDENTITY;`,
313
+ ]);
314
+ });
315
+
316
+ test('alter identity from a column - no params', async () => {
317
+ const from = {
318
+ users: pgTable('users', {
319
+ id: integer('id').generatedByDefaultAsIdentity(),
320
+ }),
321
+ };
322
+
323
+ const to = {
324
+ users: pgTable('users', {
325
+ id: integer('id').generatedByDefaultAsIdentity({ startWith: 100 }),
326
+ }),
327
+ };
328
+
329
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
330
+
331
+ expect(statements).toStrictEqual([
332
+ {
333
+ columnName: 'id',
334
+ identity: 'users_id_seq;byDefault;1;2147483647;1;100;1;false',
335
+ oldIdentity: 'users_id_seq;byDefault;1;2147483647;1;1;1;false',
336
+ schema: '',
337
+ tableName: 'users',
338
+ type: 'alter_table_alter_column_change_identity',
339
+ },
340
+ ]);
341
+ expect(sqlStatements).toStrictEqual([
342
+ 'ALTER TABLE "users" ALTER COLUMN "id" SET START WITH 100;',
343
+ ]);
344
+ });
345
+
346
+ test('alter identity from a column - few params', async () => {
347
+ const from = {
348
+ users: pgTable('users', {
349
+ id: integer('id').generatedByDefaultAsIdentity({ startWith: 100 }),
350
+ }),
351
+ };
352
+
353
+ const to = {
354
+ users: pgTable('users', {
355
+ id: integer('id').generatedByDefaultAsIdentity({
356
+ startWith: 100,
357
+ cache: 10,
358
+ }),
359
+ }),
360
+ };
361
+
362
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
363
+
364
+ expect(statements).toStrictEqual([
365
+ {
366
+ columnName: 'id',
367
+ identity: 'users_id_seq;byDefault;1;2147483647;1;100;10;false',
368
+ oldIdentity: 'users_id_seq;byDefault;1;2147483647;1;100;1;false',
369
+ schema: '',
370
+ tableName: 'users',
371
+ type: 'alter_table_alter_column_change_identity',
372
+ },
373
+ ]);
374
+ expect(sqlStatements).toStrictEqual([
375
+ 'ALTER TABLE "users" ALTER COLUMN "id" SET CACHE 10;',
376
+ ]);
377
+ });
378
+
379
+ test('alter identity from a column - by default to always', async () => {
380
+ const from = {
381
+ users: pgTable('users', {
382
+ id: integer('id').generatedByDefaultAsIdentity(),
383
+ }),
384
+ };
385
+
386
+ const to = {
387
+ users: pgTable('users', {
388
+ id: integer('id').generatedAlwaysAsIdentity({
389
+ startWith: 100,
390
+ cache: 10,
391
+ }),
392
+ }),
393
+ };
394
+
395
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
396
+
397
+ expect(statements).toStrictEqual([
398
+ {
399
+ columnName: 'id',
400
+ identity: 'users_id_seq;always;1;2147483647;1;100;10;false',
401
+ oldIdentity: 'users_id_seq;byDefault;1;2147483647;1;1;1;false',
402
+ schema: '',
403
+ tableName: 'users',
404
+ type: 'alter_table_alter_column_change_identity',
405
+ },
406
+ ]);
407
+ expect(sqlStatements).toStrictEqual([
408
+ 'ALTER TABLE "users" ALTER COLUMN "id" SET GENERATED ALWAYS;',
409
+ 'ALTER TABLE "users" ALTER COLUMN "id" SET START WITH 100;',
410
+ 'ALTER TABLE "users" ALTER COLUMN "id" SET CACHE 10;',
411
+ ]);
412
+ });
413
+
414
+ test('alter identity from a column - always to by default', async () => {
415
+ const from = {
416
+ users: pgTable('users', {
417
+ id: integer('id').generatedAlwaysAsIdentity(),
418
+ }),
419
+ };
420
+
421
+ const to = {
422
+ users: pgTable('users', {
423
+ id: integer('id').generatedByDefaultAsIdentity({
424
+ startWith: 100,
425
+ cache: 10,
426
+ }),
427
+ }),
428
+ };
429
+
430
+ const { statements, sqlStatements } = await diffTestSchemas(from, to, []);
431
+
432
+ expect(statements).toStrictEqual([
433
+ {
434
+ columnName: 'id',
435
+ identity: 'users_id_seq;byDefault;1;2147483647;1;100;10;false',
436
+ oldIdentity: 'users_id_seq;always;1;2147483647;1;1;1;false',
437
+ schema: '',
438
+ tableName: 'users',
439
+ type: 'alter_table_alter_column_change_identity',
440
+ },
441
+ ]);
442
+ expect(sqlStatements).toStrictEqual([
443
+ 'ALTER TABLE "users" ALTER COLUMN "id" SET GENERATED BY DEFAULT;',
444
+ 'ALTER TABLE "users" ALTER COLUMN "id" SET START WITH 100;',
445
+ 'ALTER TABLE "users" ALTER COLUMN "id" SET CACHE 10;',
446
+ ]);
447
+ });
@@ -0,0 +1,105 @@
1
+ import { pgSchema } from 'drizzle-orm/pg-core';
2
+ import { expect, test } from 'vitest';
3
+ import { diffTestSchemas } from './schemaDiffer';
4
+
5
+ test('add schema #1', async () => {
6
+ const to = {
7
+ devSchema: pgSchema('dev'),
8
+ };
9
+
10
+ const { statements } = await diffTestSchemas({}, to, []);
11
+
12
+ expect(statements.length).toBe(1);
13
+ expect(statements[0]).toStrictEqual({
14
+ type: 'create_schema',
15
+ name: 'dev',
16
+ });
17
+ });
18
+
19
+ test('add schema #2', async () => {
20
+ const from = {
21
+ devSchema: pgSchema('dev'),
22
+ };
23
+ const to = {
24
+ devSchema: pgSchema('dev'),
25
+ devSchema2: pgSchema('dev2'),
26
+ };
27
+
28
+ const { statements } = await diffTestSchemas(from, to, []);
29
+
30
+ expect(statements.length).toBe(1);
31
+ expect(statements[0]).toStrictEqual({
32
+ type: 'create_schema',
33
+ name: 'dev2',
34
+ });
35
+ });
36
+
37
+ test('delete schema #1', async () => {
38
+ const from = {
39
+ devSchema: pgSchema('dev'),
40
+ };
41
+
42
+ const { statements } = await diffTestSchemas(from, {}, []);
43
+
44
+ expect(statements.length).toBe(1);
45
+ expect(statements[0]).toStrictEqual({
46
+ type: 'drop_schema',
47
+ name: 'dev',
48
+ });
49
+ });
50
+
51
+ test('delete schema #2', async () => {
52
+ const from = {
53
+ devSchema: pgSchema('dev'),
54
+ devSchema2: pgSchema('dev2'),
55
+ };
56
+ const to = {
57
+ devSchema: pgSchema('dev'),
58
+ };
59
+
60
+ const { statements } = await diffTestSchemas(from, to, []);
61
+
62
+ expect(statements.length).toBe(1);
63
+ expect(statements[0]).toStrictEqual({
64
+ type: 'drop_schema',
65
+ name: 'dev2',
66
+ });
67
+ });
68
+
69
+ test('rename schema #1', async () => {
70
+ const from = {
71
+ devSchema: pgSchema('dev'),
72
+ };
73
+ const to = {
74
+ devSchema2: pgSchema('dev2'),
75
+ };
76
+
77
+ const { statements } = await diffTestSchemas(from, to, ['dev->dev2']);
78
+
79
+ expect(statements.length).toBe(1);
80
+ expect(statements[0]).toStrictEqual({
81
+ type: 'rename_schema',
82
+ from: 'dev',
83
+ to: 'dev2',
84
+ });
85
+ });
86
+
87
+ test('rename schema #2', async () => {
88
+ const from = {
89
+ devSchema: pgSchema('dev'),
90
+ devSchema1: pgSchema('dev1'),
91
+ };
92
+ const to = {
93
+ devSchema: pgSchema('dev'),
94
+ devSchema2: pgSchema('dev2'),
95
+ };
96
+
97
+ const { statements } = await diffTestSchemas(from, to, ['dev1->dev2']);
98
+
99
+ expect(statements.length).toBe(1);
100
+ expect(statements[0]).toStrictEqual({
101
+ type: 'rename_schema',
102
+ from: 'dev1',
103
+ to: 'dev2',
104
+ });
105
+ });