@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/loader.mjs DELETED
@@ -1,57 +0,0 @@
1
- import esbuild from 'esbuild';
2
- import { readFileSync } from 'fs';
3
- import * as path from 'path';
4
-
5
- const parse = (it) => {
6
- if (!it) return { drizzle: false };
7
-
8
- if (it.endsWith('__drizzle__')) {
9
- const offset = it.startsWith('file://') ? 'file://'.length : 0;
10
- const clean = it.slice(offset, -'__drizzle__'.length);
11
- return { drizzle: true, clean, original: it };
12
- }
13
- return { drizzle: false, clean: it };
14
- };
15
-
16
- export function resolve(specifier, context, nextResolve) {
17
- const { drizzle, clean } = parse(specifier);
18
- if (drizzle && !clean.endsWith('.ts') && !clean.endsWith('.mts')) {
19
- return nextResolve(clean);
20
- }
21
-
22
- if (drizzle) {
23
- return {
24
- shortCircuit: true,
25
- url: `file://${specifier}`,
26
- };
27
- }
28
-
29
- const parsedParent = parse(context.parentURL);
30
- const parentURL = parsedParent.drizzle
31
- ? new URL(`file://${path.resolve(parsedParent.clean)}`)
32
- : context.parentURL;
33
-
34
- // Let Node.js handle all other specifiers.
35
- return nextResolve(specifier, { ...context, parentURL });
36
- }
37
-
38
- export async function load(url, context, defaultLoad) {
39
- const { drizzle, clean } = parse(url);
40
- if (drizzle) {
41
- const file = readFileSync(clean, 'utf-8');
42
- if (clean.endsWith('.ts') || clean.endsWith('.mts')) {
43
- const source = esbuild.transformSync(file, {
44
- loader: 'ts',
45
- format: 'esm',
46
- });
47
- return {
48
- format: 'module',
49
- shortCircuit: true,
50
- source: source.code,
51
- };
52
- }
53
- }
54
-
55
- // let Node.js handle all other URLs
56
- return defaultLoad(url, context, defaultLoad);
57
- }
@@ -1,217 +0,0 @@
1
- import { randomUUID } from 'crypto';
2
- import fs from 'fs';
3
- import { CasingType } from './cli/validations/common';
4
- import { serializeMySql, serializePg, serializeSingleStore, serializeSQLite } from './serializer';
5
- import { dryMySql, MySqlSchema, mysqlSchema } from './serializer/mysqlSchema';
6
- import { dryPg, PgSchema, pgSchema, PgSchemaInternal } from './serializer/pgSchema';
7
- import { drySingleStore, SingleStoreSchema, singlestoreSchema } from './serializer/singlestoreSchema';
8
- import { drySQLite, SQLiteSchema, sqliteSchema } from './serializer/sqliteSchema';
9
-
10
- export const prepareMySqlDbPushSnapshot = async (
11
- prev: MySqlSchema,
12
- schemaPath: string | string[],
13
- casing: CasingType | undefined,
14
- ): Promise<{ prev: MySqlSchema; cur: MySqlSchema }> => {
15
- const serialized = await serializeMySql(schemaPath, casing);
16
-
17
- const id = randomUUID();
18
- const idPrev = prev.id;
19
-
20
- const { version, dialect, ...rest } = serialized;
21
- const result: MySqlSchema = { version, dialect, id, prevId: idPrev, ...rest };
22
-
23
- return { prev, cur: result };
24
- };
25
-
26
- export const prepareSingleStoreDbPushSnapshot = async (
27
- prev: SingleStoreSchema,
28
- schemaPath: string | string[],
29
- casing: CasingType | undefined,
30
- ): Promise<{ prev: SingleStoreSchema; cur: SingleStoreSchema }> => {
31
- const serialized = await serializeSingleStore(schemaPath, casing);
32
-
33
- const id = randomUUID();
34
- const idPrev = prev.id;
35
-
36
- const { version, dialect, ...rest } = serialized;
37
- const result: SingleStoreSchema = { version, dialect, id, prevId: idPrev, ...rest };
38
-
39
- return { prev, cur: result };
40
- };
41
-
42
- export const prepareSQLiteDbPushSnapshot = async (
43
- prev: SQLiteSchema,
44
- schemaPath: string | string[],
45
- casing: CasingType | undefined,
46
- ): Promise<{ prev: SQLiteSchema; cur: SQLiteSchema }> => {
47
- const serialized = await serializeSQLite(schemaPath, casing);
48
-
49
- const id = randomUUID();
50
- const idPrev = prev.id;
51
-
52
- const { version, dialect, ...rest } = serialized;
53
- const result: SQLiteSchema = {
54
- version,
55
- dialect,
56
- id,
57
- prevId: idPrev,
58
- ...rest,
59
- };
60
-
61
- return { prev, cur: result };
62
- };
63
-
64
- export const preparePgDbPushSnapshot = async (
65
- prev: PgSchema,
66
- schemaPath: string | string[],
67
- casing: CasingType | undefined,
68
- schemaFilter: string[] = ['public'],
69
- ): Promise<{ prev: PgSchema; cur: PgSchema }> => {
70
- const serialized = await serializePg(schemaPath, casing, schemaFilter);
71
-
72
- const id = randomUUID();
73
- const idPrev = prev.id;
74
-
75
- const { version, dialect, ...rest } = serialized;
76
- const result: PgSchema = { version, dialect, id, prevId: idPrev, ...rest };
77
-
78
- return { prev, cur: result };
79
- };
80
-
81
- export const prepareMySqlMigrationSnapshot = async (
82
- migrationFolders: string[],
83
- schemaPath: string | string[],
84
- casing: CasingType | undefined,
85
- ): Promise<{ prev: MySqlSchema; cur: MySqlSchema; custom: MySqlSchema }> => {
86
- const prevSnapshot = mysqlSchema.parse(
87
- preparePrevSnapshot(migrationFolders, dryMySql),
88
- );
89
- const serialized = await serializeMySql(schemaPath, casing);
90
-
91
- const id = randomUUID();
92
- const idPrev = prevSnapshot.id;
93
-
94
- const { version, dialect, ...rest } = serialized;
95
- const result: MySqlSchema = { version, dialect, id, prevId: idPrev, ...rest };
96
-
97
- const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
98
-
99
- // that's for custom migrations, when we need new IDs, but old snapshot
100
- const custom: MySqlSchema = {
101
- id,
102
- prevId: idPrev,
103
- ...prevRest,
104
- };
105
-
106
- return { prev: prevSnapshot, cur: result, custom };
107
- };
108
-
109
- export const prepareSingleStoreMigrationSnapshot = async (
110
- migrationFolders: string[],
111
- schemaPath: string | string[],
112
- casing: CasingType | undefined,
113
- ): Promise<{ prev: SingleStoreSchema; cur: SingleStoreSchema; custom: SingleStoreSchema }> => {
114
- const prevSnapshot = singlestoreSchema.parse(
115
- preparePrevSnapshot(migrationFolders, drySingleStore),
116
- );
117
- const serialized = await serializeSingleStore(schemaPath, casing);
118
-
119
- const id = randomUUID();
120
- const idPrev = prevSnapshot.id;
121
-
122
- const { version, dialect, ...rest } = serialized;
123
- const result: SingleStoreSchema = { version, dialect, id, prevId: idPrev, ...rest };
124
-
125
- const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
126
-
127
- // that's for custom migrations, when we need new IDs, but old snapshot
128
- const custom: SingleStoreSchema = {
129
- id,
130
- prevId: idPrev,
131
- ...prevRest,
132
- };
133
-
134
- return { prev: prevSnapshot, cur: result, custom };
135
- };
136
-
137
- export const prepareSqliteMigrationSnapshot = async (
138
- snapshots: string[],
139
- schemaPath: string | string[],
140
- casing: CasingType | undefined,
141
- ): Promise<{ prev: SQLiteSchema; cur: SQLiteSchema; custom: SQLiteSchema }> => {
142
- const prevSnapshot = sqliteSchema.parse(
143
- preparePrevSnapshot(snapshots, drySQLite),
144
- );
145
- const serialized = await serializeSQLite(schemaPath, casing);
146
-
147
- const id = randomUUID();
148
- const idPrev = prevSnapshot.id;
149
-
150
- const { version, dialect, ...rest } = serialized;
151
- const result: SQLiteSchema = {
152
- version,
153
- dialect,
154
- id,
155
- prevId: idPrev,
156
- ...rest,
157
- };
158
-
159
- const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
160
-
161
- // that's for custom migrations, when we need new IDs, but old snapshot
162
- const custom: SQLiteSchema = {
163
- id,
164
- prevId: idPrev,
165
- ...prevRest,
166
- };
167
-
168
- return { prev: prevSnapshot, cur: result, custom };
169
- };
170
-
171
- export const fillPgSnapshot = ({
172
- serialized,
173
- id,
174
- idPrev,
175
- }: {
176
- serialized: PgSchemaInternal;
177
- id: string;
178
- idPrev: string;
179
- }): PgSchema => {
180
- // const id = randomUUID();
181
- return { id, prevId: idPrev, ...serialized };
182
- };
183
-
184
- export const preparePgMigrationSnapshot = async (
185
- snapshots: string[],
186
- schemaPath: string | string[],
187
- casing: CasingType | undefined,
188
- ): Promise<{ prev: PgSchema; cur: PgSchema; custom: PgSchema }> => {
189
- const prevSnapshot = pgSchema.parse(preparePrevSnapshot(snapshots, dryPg));
190
- const serialized = await serializePg(schemaPath, casing);
191
-
192
- const id = randomUUID();
193
- const idPrev = prevSnapshot.id;
194
-
195
- // const { version, dialect, ...rest } = serialized;
196
-
197
- const result: PgSchema = { id, prevId: idPrev, ...serialized };
198
-
199
- const { id: _ignoredId, prevId: _ignoredPrevId, ...prevRest } = prevSnapshot;
200
-
201
- // that's for custom migrations, when we need new IDs, but old snapshot
202
- const custom: PgSchema = fillPgSnapshot({ serialized: prevRest, id, idPrev });
203
-
204
- return { prev: prevSnapshot, cur: result, custom };
205
- };
206
-
207
- const preparePrevSnapshot = (snapshots: string[], defaultPrev: any) => {
208
- let prevSnapshot: any;
209
-
210
- if (snapshots.length === 0) {
211
- prevSnapshot = defaultPrev;
212
- } else {
213
- const lastSnapshot = snapshots[snapshots.length - 1];
214
- prevSnapshot = JSON.parse(fs.readFileSync(lastSnapshot).toString());
215
- }
216
- return prevSnapshot;
217
- };
@@ -1,23 +0,0 @@
1
- import { enum as enumType, TypeOf, union } from 'zod';
2
- import { mysqlSchema, mysqlSchemaSquashed } from './serializer/mysqlSchema';
3
- import { pgSchema, pgSchemaSquashed } from './serializer/pgSchema';
4
- import { singlestoreSchema, singlestoreSchemaSquashed } from './serializer/singlestoreSchema';
5
- import { sqliteSchema, SQLiteSchemaSquashed } from './serializer/sqliteSchema';
6
-
7
- export const dialects = ['postgresql', 'mysql', 'sqlite', 'turso', 'singlestore'] as const;
8
- export const dialect = enumType(dialects);
9
-
10
- export type Dialect = (typeof dialects)[number];
11
- const _: Dialect = '' as TypeOf<typeof dialect>;
12
-
13
- const commonSquashedSchema = union([
14
- pgSchemaSquashed,
15
- mysqlSchemaSquashed,
16
- SQLiteSchemaSquashed,
17
- singlestoreSchemaSquashed,
18
- ]);
19
-
20
- const commonSchema = union([pgSchema, mysqlSchema, sqliteSchema, singlestoreSchema]);
21
-
22
- export type CommonSquashedSchema = TypeOf<typeof commonSquashedSchema>;
23
- export type CommonSchema = TypeOf<typeof commonSchema>;
@@ -1,142 +0,0 @@
1
- import chalk from 'chalk';
2
- import fs from 'fs';
3
- import * as glob from 'glob';
4
- import Path from 'path';
5
- import { CasingType } from 'src/cli/validations/common';
6
- import { error } from '../cli/views';
7
- import type { MySqlSchemaInternal } from './mysqlSchema';
8
- import type { PgSchemaInternal } from './pgSchema';
9
- import { SingleStoreSchemaInternal } from './singlestoreSchema';
10
- import type { SQLiteSchemaInternal } from './sqliteSchema';
11
-
12
- export const serializeMySql = async (
13
- path: string | string[],
14
- casing: CasingType | undefined,
15
- ): Promise<MySqlSchemaInternal> => {
16
- const filenames = prepareFilenames(path);
17
-
18
- console.log(chalk.gray(`Reading schema files:\n${filenames.join('\n')}\n`));
19
-
20
- const { prepareFromMySqlImports } = await import('./mysqlImports');
21
- const { generateMySqlSnapshot } = await import('./mysqlSerializer');
22
-
23
- const { tables, views } = await prepareFromMySqlImports(filenames);
24
-
25
- return generateMySqlSnapshot(tables, views, casing);
26
- };
27
-
28
- export const serializePg = async (
29
- path: string | string[],
30
- casing: CasingType | undefined,
31
- schemaFilter?: string[],
32
- ): Promise<PgSchemaInternal> => {
33
- const filenames = prepareFilenames(path);
34
-
35
- const { prepareFromPgImports } = await import('./pgImports');
36
- const { generatePgSnapshot } = await import('./pgSerializer');
37
-
38
- const { tables, domains, enums, schemas, sequences, views, matViews, roles, policies } = await prepareFromPgImports(
39
- filenames,
40
- );
41
-
42
- return generatePgSnapshot(
43
- tables,
44
- domains,
45
- enums,
46
- schemas,
47
- sequences,
48
- roles,
49
- policies,
50
- views,
51
- matViews,
52
- casing,
53
- schemaFilter,
54
- );
55
- };
56
-
57
- export const serializeSQLite = async (
58
- path: string | string[],
59
- casing: CasingType | undefined,
60
- ): Promise<SQLiteSchemaInternal> => {
61
- const filenames = prepareFilenames(path);
62
-
63
- const { prepareFromSqliteImports } = await import('./sqliteImports');
64
- const { generateSqliteSnapshot } = await import('./sqliteSerializer');
65
- const { tables, views } = await prepareFromSqliteImports(filenames);
66
- return generateSqliteSnapshot(tables, views, casing);
67
- };
68
-
69
- export const serializeSingleStore = async (
70
- path: string | string[],
71
- casing: CasingType | undefined,
72
- ): Promise<SingleStoreSchemaInternal> => {
73
- const filenames = prepareFilenames(path);
74
-
75
- console.log(chalk.gray(`Reading schema files:\n${filenames.join('\n')}\n`));
76
-
77
- const { prepareFromSingleStoreImports } = await import('./singlestoreImports');
78
- const { generateSingleStoreSnapshot } = await import('./singlestoreSerializer');
79
-
80
- const { tables /* views */ } = await prepareFromSingleStoreImports(filenames);
81
-
82
- return generateSingleStoreSnapshot(tables, /* views, */ casing);
83
- };
84
-
85
- export const prepareFilenames = (path: string | string[]) => {
86
- if (typeof path === 'string') {
87
- path = [path];
88
- }
89
- const prefix = process.env.TEST_CONFIG_PATH_PREFIX || '';
90
-
91
- const result = path.reduce((result, cur) => {
92
- const globbed = glob.sync(`${prefix}${cur}`);
93
-
94
- globbed.forEach((it) => {
95
- const fileName = fs.lstatSync(it).isDirectory() ? null : Path.resolve(it);
96
-
97
- const filenames = fileName
98
- ? [fileName!]
99
- : fs.readdirSync(it).map((file) => Path.join(Path.resolve(it), file));
100
-
101
- filenames
102
- .filter((file) => !fs.lstatSync(file).isDirectory())
103
- .forEach((file) => result.add(file));
104
- });
105
-
106
- return result;
107
- }, new Set<string>());
108
- const res = [...result];
109
-
110
- // TODO: properly handle and test
111
- const errors = res.filter((it) => {
112
- return !(
113
- it.endsWith('.ts')
114
- || it.endsWith('.js')
115
- || it.endsWith('.cjs')
116
- || it.endsWith('.mjs')
117
- || it.endsWith('.mts')
118
- || it.endsWith('.cts')
119
- );
120
- });
121
-
122
- // when schema: "./schema" and not "./schema.ts"
123
- if (res.length === 0) {
124
- console.log(
125
- error(
126
- `No schema files found for path config [${
127
- path
128
- .map((it) => `'${it}'`)
129
- .join(', ')
130
- }]`,
131
- ),
132
- );
133
- console.log(
134
- error(
135
- `If path represents a file - please make sure to use .ts or other extension in the path`,
136
- ),
137
- );
138
- process.exit(1);
139
- }
140
-
141
- return res;
142
- };
@@ -1,38 +0,0 @@
1
- import { is } from 'drizzle-orm';
2
- import { AnyMySqlTable, MySqlTable, MySqlView } from 'drizzle-orm/mysql-core';
3
- import { safeRegister } from '../cli/commands/utils';
4
-
5
- export const prepareFromExports = (exports: Record<string, unknown>) => {
6
- const tables: AnyMySqlTable[] = [];
7
- const views: MySqlView[] = [];
8
-
9
- const i0values = Object.values(exports);
10
- i0values.forEach((t) => {
11
- if (is(t, MySqlTable)) {
12
- tables.push(t);
13
- }
14
-
15
- if (is(t, MySqlView)) {
16
- views.push(t);
17
- }
18
- });
19
-
20
- return { tables, views };
21
- };
22
-
23
- export const prepareFromMySqlImports = async (imports: string[]) => {
24
- const tables: AnyMySqlTable[] = [];
25
- const views: MySqlView[] = [];
26
-
27
- const { unregister } = await safeRegister();
28
- for (let i = 0; i < imports.length; i++) {
29
- const it = imports[i];
30
- const i0: Record<string, unknown> = require(`${it}`);
31
- const prepared = prepareFromExports(i0);
32
-
33
- tables.push(...prepared.tables);
34
- views.push(...prepared.views);
35
- }
36
- unregister();
37
- return { tables: Array.from(new Set(tables)), views };
38
- };