@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
package/src/utils.ts ADDED
@@ -0,0 +1,370 @@
1
+ import type { RunResult } from 'better-sqlite3';
2
+ import chalk from 'chalk';
3
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs';
4
+ import { join } from 'path';
5
+ import { parse } from 'url';
6
+ import type { NamedWithSchema } from './cli/commands/migrate';
7
+ import { info } from './cli/views';
8
+ import { assertUnreachable, snapshotVersion } from './global';
9
+ import type { Dialect } from './schemaValidator';
10
+ import { backwardCompatibleMysqlSchema } from './serializer/mysqlSchema';
11
+ import { backwardCompatiblePgSchema } from './serializer/pgSchema';
12
+ import { backwardCompatibleSingleStoreSchema } from './serializer/singlestoreSchema';
13
+ import { backwardCompatibleSqliteSchema } from './serializer/sqliteSchema';
14
+ import type { ProxyParams } from './serializer/studio';
15
+
16
+ export type Proxy = (params: ProxyParams) => Promise<any[]>;
17
+
18
+ export type SqliteProxy = {
19
+ proxy: (params: ProxyParams) => Promise<any[] | RunResult>;
20
+ };
21
+
22
+ export type DB = {
23
+ query: <T extends any = any>(sql: string, params?: any[]) => Promise<T[]>;
24
+ };
25
+
26
+ export type SQLiteDB = {
27
+ query: <T extends any = any>(sql: string, params?: any[]) => Promise<T[]>;
28
+ run(query: string): Promise<void>;
29
+ };
30
+
31
+ export type LibSQLDB = {
32
+ query: <T extends any = any>(sql: string, params?: any[]) => Promise<T[]>;
33
+ run(query: string): Promise<void>;
34
+ batchWithPragma?(queries: string[]): Promise<void>;
35
+ };
36
+
37
+ export const copy = <T>(it: T): T => {
38
+ return JSON.parse(JSON.stringify(it));
39
+ };
40
+
41
+ export const objectValues = <T extends object>(obj: T): Array<T[keyof T]> => {
42
+ return Object.values(obj);
43
+ };
44
+
45
+ export const assertV1OutFolder = (out: string) => {
46
+ if (!existsSync(out)) return;
47
+
48
+ const oldMigrationFolders = readdirSync(out).filter(
49
+ (it) => it.length === 14 && /^\d+$/.test(it),
50
+ );
51
+
52
+ if (oldMigrationFolders.length > 0) {
53
+ console.log(
54
+ `Your migrations folder format is outdated, please run ${
55
+ chalk.green.bold(
56
+ `drizzle-kit up`,
57
+ )
58
+ }`,
59
+ );
60
+ process.exit(1);
61
+ }
62
+ };
63
+
64
+ export type Journal = {
65
+ version: string;
66
+ dialect: Dialect;
67
+ entries: {
68
+ idx: number;
69
+ version: string;
70
+ when: number;
71
+ tag: string;
72
+ breakpoints: boolean;
73
+ }[];
74
+ };
75
+
76
+ export const dryJournal = (dialect: Dialect): Journal => {
77
+ return {
78
+ version: snapshotVersion,
79
+ dialect,
80
+ entries: [],
81
+ };
82
+ };
83
+
84
+ // export const preparePushFolder = (dialect: Dialect) => {
85
+ // const out = ".drizzle";
86
+ // let snapshot: string = "";
87
+ // if (!existsSync(join(out))) {
88
+ // mkdirSync(out);
89
+ // snapshot = JSON.stringify(dryJournal(dialect));
90
+ // } else {
91
+ // snapshot = readdirSync(out)[0];
92
+ // }
93
+
94
+ // return { snapshot };
95
+ // };
96
+
97
+ export const prepareOutFolder = (out: string, dialect: Dialect) => {
98
+ const meta = join(out, 'meta');
99
+ const journalPath = join(meta, '_journal.json');
100
+
101
+ if (!existsSync(join(out, 'meta'))) {
102
+ mkdirSync(meta, { recursive: true });
103
+ writeFileSync(journalPath, JSON.stringify(dryJournal(dialect)));
104
+ }
105
+
106
+ const journal = JSON.parse(readFileSync(journalPath).toString());
107
+
108
+ const snapshots = readdirSync(meta)
109
+ .filter((it) => !it.startsWith('_'))
110
+ .map((it) => join(meta, it));
111
+
112
+ snapshots.sort();
113
+ return { meta, snapshots, journal };
114
+ };
115
+
116
+ const validatorForDialect = (dialect: Dialect) => {
117
+ switch (dialect) {
118
+ case 'postgresql':
119
+ return { validator: backwardCompatiblePgSchema, version: 7 };
120
+ case 'sqlite':
121
+ return { validator: backwardCompatibleSqliteSchema, version: 6 };
122
+ case 'turso':
123
+ return { validator: backwardCompatibleSqliteSchema, version: 6 };
124
+ case 'mysql':
125
+ return { validator: backwardCompatibleMysqlSchema, version: 5 };
126
+ case 'singlestore':
127
+ return { validator: backwardCompatibleSingleStoreSchema, version: 1 };
128
+ }
129
+ };
130
+
131
+ export const validateWithReport = (snapshots: string[], dialect: Dialect) => {
132
+ // ✅ check if drizzle-kit can handle snapshot version
133
+ // ✅ check if snapshot is of the last version
134
+ // ✅ check if id of the snapshot is valid
135
+ // ✅ collect {} of prev id -> snapshotName[], if there's more than one - tell about collision
136
+ const { validator, version } = validatorForDialect(dialect);
137
+
138
+ const result = snapshots.reduce(
139
+ (accum, it) => {
140
+ const raw = JSON.parse(readFileSync(`./${it}`).toString());
141
+
142
+ accum.rawMap[it] = raw;
143
+
144
+ if (raw['version'] && Number(raw['version']) > version) {
145
+ console.log(
146
+ info(
147
+ `${it} snapshot is of unsupported version, please update drizzle-kit`,
148
+ ),
149
+ );
150
+ process.exit(0);
151
+ }
152
+
153
+ const result = validator.safeParse(raw);
154
+ if (!result.success) {
155
+ accum.malformed.push(it);
156
+ return accum;
157
+ }
158
+
159
+ const snapshot = result.data;
160
+ if (snapshot.version !== String(version)) {
161
+ accum.nonLatest.push(it);
162
+ return accum;
163
+ }
164
+
165
+ // only if latest version here
166
+ const idEntry = accum.idsMap[snapshot['prevId']] ?? {
167
+ parent: it,
168
+ snapshots: [],
169
+ };
170
+ idEntry.snapshots.push(it);
171
+ accum.idsMap[snapshot['prevId']] = idEntry;
172
+
173
+ return accum;
174
+ },
175
+ {
176
+ malformed: [],
177
+ nonLatest: [],
178
+ idToNameMap: {},
179
+ idsMap: {},
180
+ rawMap: {},
181
+ } as {
182
+ malformed: string[];
183
+ nonLatest: string[];
184
+ idsMap: Record<string, { parent: string; snapshots: string[] }>;
185
+ rawMap: Record<string, any>;
186
+ },
187
+ );
188
+
189
+ return result;
190
+ };
191
+
192
+ export const prepareMigrationFolder = (
193
+ outFolder: string = 'drizzle',
194
+ dialect: Dialect,
195
+ ) => {
196
+ const { snapshots, journal } = prepareOutFolder(outFolder, dialect);
197
+ const report = validateWithReport(snapshots, dialect);
198
+ if (report.nonLatest.length > 0) {
199
+ console.log(
200
+ report.nonLatest
201
+ .map((it) => {
202
+ return `${it}/snapshot.json is not of the latest version`;
203
+ })
204
+ .concat(`Run ${chalk.green.bold(`drizzle-kit up`)}`)
205
+ .join('\n'),
206
+ );
207
+ process.exit(0);
208
+ }
209
+
210
+ if (report.malformed.length) {
211
+ const message = report.malformed
212
+ .map((it) => {
213
+ return `${it} data is malformed`;
214
+ })
215
+ .join('\n');
216
+ console.log(message);
217
+ }
218
+
219
+ const collisionEntries = Object.entries(report.idsMap).filter(
220
+ (it) => it[1].snapshots.length > 1,
221
+ );
222
+
223
+ const message = collisionEntries
224
+ .map((it) => {
225
+ const data = it[1];
226
+ return `[${
227
+ data.snapshots.join(
228
+ ', ',
229
+ )
230
+ }] are pointing to a parent snapshot: ${data.parent}/snapshot.json which is a collision.`;
231
+ })
232
+ .join('\n')
233
+ .trim();
234
+ if (message) {
235
+ console.log(chalk.red.bold('Error:'), message);
236
+ }
237
+
238
+ const abort = report.malformed.length!! || collisionEntries.length > 0;
239
+
240
+ if (abort) {
241
+ process.exit(0);
242
+ }
243
+
244
+ return { snapshots, journal };
245
+ };
246
+
247
+ export const prepareMigrationMeta = (
248
+ schemas: { from: string; to: string }[],
249
+ tables: { from: NamedWithSchema; to: NamedWithSchema }[],
250
+ columns: {
251
+ from: { table: string; schema: string; column: string };
252
+ to: { table: string; schema: string; column: string };
253
+ }[],
254
+ ) => {
255
+ const _meta = {
256
+ schemas: {} as Record<string, string>,
257
+ tables: {} as Record<string, string>,
258
+ columns: {} as Record<string, string>,
259
+ };
260
+
261
+ schemas.forEach((it) => {
262
+ const from = schemaRenameKey(it.from);
263
+ const to = schemaRenameKey(it.to);
264
+ _meta.schemas[from] = to;
265
+ });
266
+ tables.forEach((it) => {
267
+ const from = tableRenameKey(it.from);
268
+ const to = tableRenameKey(it.to);
269
+ _meta.tables[from] = to;
270
+ });
271
+
272
+ columns.forEach((it) => {
273
+ const from = columnRenameKey(it.from.table, it.from.schema, it.from.column);
274
+ const to = columnRenameKey(it.to.table, it.to.schema, it.to.column);
275
+ _meta.columns[from] = to;
276
+ });
277
+
278
+ return _meta;
279
+ };
280
+
281
+ export const schemaRenameKey = (it: string) => {
282
+ return it;
283
+ };
284
+
285
+ export const tableRenameKey = (it: NamedWithSchema) => {
286
+ const out = it.schema ? `"${it.schema}"."${it.name}"` : `"${it.name}"`;
287
+ return out;
288
+ };
289
+
290
+ export const columnRenameKey = (
291
+ table: string,
292
+ schema: string,
293
+ column: string,
294
+ ) => {
295
+ const out = schema
296
+ ? `"${schema}"."${table}"."${column}"`
297
+ : `"${table}"."${column}"`;
298
+ return out;
299
+ };
300
+
301
+ export const kloudMeta = () => {
302
+ return {
303
+ pg: [5],
304
+ mysql: [] as number[],
305
+ sqlite: [] as number[],
306
+ };
307
+ };
308
+
309
+ export const normaliseSQLiteUrl = (
310
+ it: string,
311
+ type: 'libsql' | 'better-sqlite',
312
+ ) => {
313
+ if (type === 'libsql') {
314
+ if (it.startsWith('file:')) {
315
+ return it;
316
+ }
317
+ try {
318
+ const url = parse(it);
319
+ if (url.protocol === null) {
320
+ return `file:${it}`;
321
+ }
322
+ return it;
323
+ } catch (e) {
324
+ return `file:${it}`;
325
+ }
326
+ }
327
+
328
+ if (type === 'better-sqlite') {
329
+ if (it.startsWith('file:')) {
330
+ return it.substring(5);
331
+ }
332
+
333
+ return it;
334
+ }
335
+
336
+ assertUnreachable(type);
337
+ };
338
+
339
+ export const normalisePGliteUrl = (
340
+ it: string,
341
+ ) => {
342
+ if (it.startsWith('file:')) {
343
+ return it.substring(5);
344
+ }
345
+
346
+ return it;
347
+ };
348
+
349
+ export function isPgArrayType(sqlType: string) {
350
+ return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
351
+ }
352
+
353
+ export function findAddedAndRemoved(columnNames1: string[], columnNames2: string[]) {
354
+ const set1 = new Set(columnNames1);
355
+ const set2 = new Set(columnNames2);
356
+
357
+ const addedColumns = columnNames2.filter((it) => !set1.has(it));
358
+ const removedColumns = columnNames1.filter((it) => !set2.has(it));
359
+
360
+ return { addedColumns, removedColumns };
361
+ }
362
+
363
+ export function escapeSingleQuotes(str: string) {
364
+ return str.replace(/'/g, "''");
365
+ }
366
+
367
+ export function unescapeSingleQuotes(str: string, ignoreFirstAndLastChar: boolean) {
368
+ const regex = ignoreFirstAndLastChar ? /(?<!^)'(?!$)/g : /'/g;
369
+ return str.replace(/''/g, "'").replace(regex, "\\'");
370
+ }
@@ -0,0 +1,58 @@
1
+ import chalk from 'chalk';
2
+ import { assert, test } from 'vitest';
3
+ import { analyzeImports, ChainLink } from '../imports-checker/checker';
4
+
5
+ test('imports-issues', () => {
6
+ const issues = analyzeImports({
7
+ basePath: '.',
8
+ localPaths: ['src'],
9
+ whiteList: [
10
+ '@drizzle-team/brocli',
11
+ 'json-diff',
12
+ 'path',
13
+ 'fs',
14
+ 'fs/*',
15
+ 'url',
16
+ 'zod',
17
+ 'node:*',
18
+ 'hono',
19
+ 'glob',
20
+ 'hono/*',
21
+ 'hono/**/*',
22
+ '@hono/*',
23
+ 'crypto',
24
+ 'hanji',
25
+ 'chalk',
26
+ 'dotenv/config',
27
+ 'camelcase',
28
+ 'semver',
29
+ 'env-paths',
30
+ ],
31
+ entry: 'src/cli/index.ts',
32
+ logger: true,
33
+ ignoreTypes: true,
34
+ }).issues;
35
+
36
+ const chainToString = (chains: ChainLink[]) => {
37
+ if (chains.length === 0) throw new Error();
38
+
39
+ let out = chains[0]!.file + '\n';
40
+ let indentation = 0;
41
+ for (let chain of chains) {
42
+ out += ' '.repeat(indentation)
43
+ + '└'
44
+ + chain.import
45
+ + ` ${chalk.gray(chain.file)}\n`;
46
+ indentation += 1;
47
+ }
48
+ return out;
49
+ };
50
+
51
+ console.log();
52
+ for (const issue of issues) {
53
+ console.log(chalk.red(issue.imports.map((it) => it.name).join('\n')));
54
+ console.log(issue.accessChains.map((it) => chainToString(it)).join('\n'));
55
+ }
56
+
57
+ assert.equal(issues.length, 0);
58
+ });
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from '../../src';
2
+
3
+ export default defineConfig({
4
+ schema: './schema.ts',
5
+ dialect: 'sqlite',
6
+ driver: 'd1-http',
7
+ dbCredentials: {
8
+ accountId: 'accid',
9
+ databaseId: 'dbid',
10
+ token: 'token',
11
+ },
12
+ });
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from '../../src';
2
+
3
+ export default defineConfig({
4
+ schema: './schema.ts',
5
+ dialect: 'postgresql',
6
+ dbCredentials: {
7
+ url: 'postgresql://postgres:postgres@127.0.0.1:5432/db',
8
+ },
9
+ });
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from '../../src';
2
+
3
+ export default defineConfig({
4
+ schema: './schema.ts',
5
+ dialect: 'sqlite',
6
+ driver: 'durable-sqlite',
7
+ });
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from '../../src';
2
+
3
+ export default defineConfig({
4
+ schema: './schema.ts',
5
+ dialect: 'sqlite',
6
+ driver: 'expo',
7
+ });
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from '../../src';
2
+
3
+ export default defineConfig({
4
+ schema: './schema.ts',
5
+ dialect: 'postgresql',
6
+ dbCredentials: {
7
+ host: '127.0.0.1',
8
+ port: 5432,
9
+ user: 'postgresql',
10
+ password: 'postgres',
11
+ database: 'db',
12
+ },
13
+ });
@@ -0,0 +1,17 @@
1
+ import { defineConfig } from '../../src';
2
+
3
+ export default defineConfig({
4
+ schema: './schema.ts',
5
+ dialect: 'postgresql',
6
+ dbCredentials: {
7
+ host: '127.0.0.1',
8
+ port: 5432,
9
+ user: 'postgresql',
10
+ password: 'postgres',
11
+ database: 'db',
12
+ },
13
+ migrations: {
14
+ schema: 'custom',
15
+ table: 'custom',
16
+ },
17
+ });
@@ -0,0 +1 @@
1
+ // mock
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from '../../src';
2
+
3
+ export default defineConfig({
4
+ schema: './schema.ts',
5
+ dialect: 'turso',
6
+ dbCredentials: {
7
+ url: 'turso.dev',
8
+ authToken: 'token',
9
+ },
10
+ });
@@ -0,0 +1,79 @@
1
+ import { test as brotest } from '@drizzle-team/brocli';
2
+ import { assert, expect, test } from 'vitest';
3
+ import { exportRaw } from '../src/cli/schema';
4
+
5
+ // good:
6
+ // #1 drizzle-kit export --dialect=postgresql --schema=schema.ts
7
+ // #3 drizzle-kit export
8
+ // #3 drizzle-kit export --config=drizzle1.config.ts
9
+
10
+ // errors:
11
+ // #1 drizzle-kit export --schema=src/schema.ts
12
+ // #2 drizzle-kit export --dialect=postgresql
13
+ // #3 drizzle-kit export --dialect=postgresql2
14
+ // #4 drizzle-kit export --config=drizzle.config.ts --schema=schema.ts
15
+ // #5 drizzle-kit export --config=drizzle.config.ts --dialect=postgresql
16
+
17
+ test('export #1', async (t) => {
18
+ const res = await brotest(
19
+ exportRaw,
20
+ '--dialect=postgresql --schema=schema.ts',
21
+ );
22
+
23
+ if (res.type !== 'handler') assert.fail(res.type, 'handler');
24
+
25
+ expect(res.options).toStrictEqual({
26
+ dialect: 'postgresql',
27
+ schema: 'schema.ts',
28
+ sql: true,
29
+ });
30
+ });
31
+
32
+ test('export #2', async (t) => {
33
+ const res = await brotest(exportRaw, '');
34
+
35
+ if (res.type !== 'handler') assert.fail(res.type, 'handler');
36
+ expect(res.options).toStrictEqual({
37
+ dialect: 'postgresql',
38
+ schema: './schema.ts',
39
+ sql: true,
40
+ });
41
+ });
42
+
43
+ // custom config path
44
+ test('export #3', async (t) => {
45
+ const res = await brotest(exportRaw, '--config=expo.config.ts');
46
+ assert.equal(res.type, 'handler');
47
+ if (res.type !== 'handler') assert.fail(res.type, 'handler');
48
+ expect(res.options).toStrictEqual({
49
+ dialect: 'sqlite',
50
+ schema: './schema.ts',
51
+ sql: true,
52
+ });
53
+ });
54
+
55
+ // --- errors ---
56
+ test('err #1', async (t) => {
57
+ const res = await brotest(exportRaw, '--schema=src/schema.ts');
58
+ assert.equal(res.type, 'error');
59
+ });
60
+
61
+ test('err #2', async (t) => {
62
+ const res = await brotest(exportRaw, '--dialect=postgresql');
63
+ assert.equal(res.type, 'error');
64
+ });
65
+
66
+ test('err #3', async (t) => {
67
+ const res = await brotest(exportRaw, '--dialect=postgresql2');
68
+ assert.equal(res.type, 'error');
69
+ });
70
+
71
+ test('err #4', async (t) => {
72
+ const res = await brotest(exportRaw, '--config=drizzle.config.ts --schema=schema.ts');
73
+ assert.equal(res.type, 'error');
74
+ });
75
+
76
+ test('err #5', async (t) => {
77
+ const res = await brotest(exportRaw, '--config=drizzle.config.ts --dialect=postgresql');
78
+ assert.equal(res.type, 'error');
79
+ });