@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,48 +0,0 @@
1
- import chalk from 'chalk';
2
- import { analyzeImports, ChainLink } from './checker';
3
-
4
- const issues = analyzeImports({
5
- basePath: './drizzle-kit',
6
- localPaths: ['src'],
7
- whiteList: [
8
- '@drizzle-team/brocli',
9
- 'json-diff',
10
- 'path',
11
- 'fs',
12
- 'fs/*',
13
- 'url',
14
- 'zod',
15
- 'node:*',
16
- 'hono',
17
- 'glob',
18
- 'hono/*',
19
- 'hono/**/*',
20
- '@hono/*',
21
- 'crypto',
22
- 'hanji',
23
- ],
24
- entry: './drizzle-kit/src/cli/index.ts',
25
- logger: true,
26
- ignoreTypes: true,
27
- }).issues;
28
-
29
- const chainToString = (chains: ChainLink[]) => {
30
- if (chains.length === 0) throw new Error();
31
-
32
- let out = chains[0]!.file + '\n';
33
- let indentation = 0;
34
- for (let chain of chains) {
35
- out += ' '.repeat(indentation)
36
- + '└'
37
- + chain.import
38
- + ` ${chalk.gray(chain.file)}\n`;
39
- indentation += 1;
40
- }
41
- return out;
42
- };
43
-
44
- console.log();
45
- for (const issue of issues) {
46
- console.log(chalk.red(issue.imports.map((it) => it.name).join('\n')));
47
- console.log(issue.accessChains.map((it) => chainToString(it)).join('\n'));
48
- }
@@ -1,31 +0,0 @@
1
- diff --git a/lib/difflib.js b/lib/difflib.js
2
- index 80d250e7e18bdc972df3621ee5c05ffff0e3659f..94916f33dbae0d3eea6f74e2c619c4c6f52cc125 100644
3
- --- a/lib/difflib.js
4
- +++ b/lib/difflib.js
5
- @@ -17,7 +17,7 @@ Function restore(delta, which):
6
-
7
- Function unifiedDiff(a, b):
8
- For two lists of strings, return a delta in unified diff format.
9
- -
10
- +.
11
- Class SequenceMatcher:
12
- A flexible class for comparing pairs of sequences of any type.
13
-
14
- @@ -75,7 +75,7 @@ Class Differ:
15
-
16
- SequenceMatcher = (function() {
17
-
18
- - SequenceMatcher.name = 'SequenceMatcher';
19
- + // SequenceMatcher.name = 'SequenceMatcher';
20
-
21
- /*
22
- SequenceMatcher is a flexible class for comparing pairs of sequences of
23
- @@ -737,7 +737,7 @@ Class Differ:
24
-
25
- Differ = (function() {
26
-
27
- - Differ.name = 'Differ';
28
- + // Differ.name = 'Differ';
29
-
30
- /*
31
- Differ is a class for comparing sequences of lines of text, and
@@ -1,58 +0,0 @@
1
- declare global {
2
- interface String {
3
- trimChar(char: string): string;
4
- squashSpaces(): string;
5
- capitalise(): string;
6
- camelCase(): string;
7
- snake_case(): string;
8
-
9
- concatIf(it: string, condition: boolean): string;
10
- }
11
-
12
- interface Array<T> {
13
- random(): T;
14
- }
15
- }
16
-
17
- import camelcase from 'camelcase';
18
-
19
- String.prototype.trimChar = function(char: string) {
20
- let start = 0;
21
- let end = this.length;
22
-
23
- while (start < end && this[start] === char) ++start;
24
- while (end > start && this[end - 1] === char) --end;
25
-
26
- // this.toString() due to ava deep equal issue with String { "value" }
27
- return start > 0 || end < this.length
28
- ? this.substring(start, end)
29
- : this.toString();
30
- };
31
-
32
- String.prototype.squashSpaces = function() {
33
- return this.replace(/ +/g, ' ').trim();
34
- };
35
-
36
- String.prototype.camelCase = function() {
37
- return camelcase(String(this));
38
- };
39
-
40
- String.prototype.capitalise = function() {
41
- return this && this.length > 0
42
- ? `${this[0].toUpperCase()}${this.slice(1)}`
43
- : String(this);
44
- };
45
-
46
- String.prototype.concatIf = function(it: string, condition: boolean) {
47
- return condition ? `${this}${it}` : String(this);
48
- };
49
-
50
- String.prototype.snake_case = function() {
51
- return this && this.length > 0 ? `${this.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)}` : String(this);
52
- };
53
-
54
- Array.prototype.random = function() {
55
- return this[~~(Math.random() * this.length)];
56
- };
57
-
58
- export {};
package/src/api.ts DELETED
@@ -1,504 +0,0 @@
1
- import { randomUUID } from 'crypto';
2
- import { LibSQLDatabase } from 'drizzle-orm/libsql';
3
- import type { MySql2Database } from 'drizzle-orm/mysql2';
4
- import { PgDatabase } from 'drizzle-orm/pg-core';
5
- import { SingleStoreDriverDatabase } from 'drizzle-orm/singlestore';
6
- import {
7
- columnsResolver,
8
- domainsResolver,
9
- enumsResolver,
10
- indPolicyResolver,
11
- mySqlViewsResolver,
12
- policyResolver,
13
- roleResolver,
14
- schemasResolver,
15
- sequencesResolver,
16
- sqliteViewsResolver,
17
- tablesResolver,
18
- viewsResolver,
19
- } from './cli/commands/migrate';
20
- import { pgPushIntrospect } from './cli/commands/pgIntrospect';
21
- import { pgSuggestions } from './cli/commands/pgPushUtils';
22
- import { updateUpToV6 as upPgV6, updateUpToV7 as upPgV7 } from './cli/commands/pgUp';
23
- import { sqlitePushIntrospect } from './cli/commands/sqliteIntrospect';
24
- import { logSuggestionsAndReturn } from './cli/commands/sqlitePushUtils';
25
- import type { CasingType } from './cli/validations/common';
26
- import { getTablesFilterByExtensions } from './extensions/getTablesFilterByExtensions';
27
- import { originUUID } from './global';
28
- import type { Config } from './index';
29
- import { fillPgSnapshot } from './migrationPreparator';
30
- import { MySqlSchema as MySQLSchemaKit, mysqlSchema, squashMysqlScheme } from './serializer/mysqlSchema';
31
- import { generateMySqlSnapshot } from './serializer/mysqlSerializer';
32
- import { prepareFromExports } from './serializer/pgImports';
33
- import { PgSchema as PgSchemaKit, pgSchema, squashPgScheme } from './serializer/pgSchema';
34
- import { generatePgSnapshot } from './serializer/pgSerializer';
35
- import {
36
- SingleStoreSchema as SingleStoreSchemaKit,
37
- singlestoreSchema,
38
- squashSingleStoreScheme,
39
- } from './serializer/singlestoreSchema';
40
- import { generateSingleStoreSnapshot } from './serializer/singlestoreSerializer';
41
- import { SQLiteSchema as SQLiteSchemaKit, sqliteSchema, squashSqliteScheme } from './serializer/sqliteSchema';
42
- import { generateSqliteSnapshot } from './serializer/sqliteSerializer';
43
- import type { DB, SQLiteDB } from './utils';
44
- export type DrizzleSnapshotJSON = PgSchemaKit;
45
- export type DrizzleSQLiteSnapshotJSON = SQLiteSchemaKit;
46
- export type DrizzleMySQLSnapshotJSON = MySQLSchemaKit;
47
- export type DrizzleSingleStoreSnapshotJSON = SingleStoreSchemaKit;
48
-
49
- export const generateDrizzleJson = (
50
- imports: Record<string, unknown>,
51
- prevId?: string,
52
- schemaFilters?: string[],
53
- casing?: CasingType,
54
- ): PgSchemaKit => {
55
- const prepared = prepareFromExports(imports);
56
-
57
- const id = randomUUID();
58
-
59
- const snapshot = generatePgSnapshot(
60
- prepared.tables,
61
- prepared.domains,
62
- prepared.enums,
63
- prepared.schemas,
64
- prepared.sequences,
65
- prepared.roles,
66
- prepared.policies,
67
- prepared.views,
68
- prepared.matViews,
69
- casing,
70
- schemaFilters,
71
- );
72
-
73
- return fillPgSnapshot({
74
- serialized: snapshot,
75
- id,
76
- idPrev: prevId ?? originUUID,
77
- });
78
- };
79
-
80
- export const generateMigration = async (
81
- prev: DrizzleSnapshotJSON,
82
- cur: DrizzleSnapshotJSON,
83
- ) => {
84
- const { applyPgSnapshotsDiff } = await import('./snapshotsDiffer');
85
-
86
- const validatedPrev = pgSchema.parse(prev);
87
- const validatedCur = pgSchema.parse(cur);
88
-
89
- const squashedPrev = squashPgScheme(validatedPrev);
90
- const squashedCur = squashPgScheme(validatedCur);
91
-
92
- const { sqlStatements, _meta } = await applyPgSnapshotsDiff(
93
- squashedPrev,
94
- squashedCur,
95
- schemasResolver,
96
- domainsResolver,
97
- enumsResolver,
98
- sequencesResolver,
99
- policyResolver,
100
- indPolicyResolver,
101
- roleResolver,
102
- tablesResolver,
103
- columnsResolver,
104
- viewsResolver,
105
- validatedPrev,
106
- validatedCur,
107
- );
108
-
109
- return sqlStatements;
110
- };
111
-
112
- export const pushSchema = async (
113
- imports: Record<string, unknown>,
114
- drizzleInstance: PgDatabase<any>,
115
- schemaFilters?: string[],
116
- tablesFilter?: string[],
117
- extensionsFilters?: Config['extensionsFilters'],
118
- ) => {
119
- const { applyPgSnapshotsDiff } = await import('./snapshotsDiffer');
120
- const { sql } = await import('drizzle-orm');
121
- const filters = (tablesFilter ?? []).concat(
122
- getTablesFilterByExtensions({ extensionsFilters, dialect: 'postgresql' }),
123
- );
124
-
125
- const db: DB = {
126
- query: async (query: string, params?: any[]) => {
127
- const res = await drizzleInstance.execute(sql.raw(query));
128
- return res.rows;
129
- },
130
- };
131
-
132
- const cur = generateDrizzleJson(imports);
133
- const { schema: prev } = await pgPushIntrospect(
134
- db,
135
- filters,
136
- schemaFilters ?? ['public'],
137
- undefined,
138
- );
139
-
140
- const validatedPrev = pgSchema.parse(prev);
141
- const validatedCur = pgSchema.parse(cur);
142
-
143
- const squashedPrev = squashPgScheme(validatedPrev, 'push');
144
- const squashedCur = squashPgScheme(validatedCur, 'push');
145
-
146
- const { statements } = await applyPgSnapshotsDiff(
147
- squashedPrev,
148
- squashedCur,
149
- schemasResolver,
150
- domainsResolver,
151
- enumsResolver,
152
- sequencesResolver,
153
- policyResolver,
154
- indPolicyResolver,
155
- roleResolver,
156
- tablesResolver,
157
- columnsResolver,
158
- viewsResolver,
159
- validatedPrev,
160
- validatedCur,
161
- 'push',
162
- );
163
-
164
- const { shouldAskForApprove, statementsToExecute, infoToPrint } = await pgSuggestions(db, statements);
165
-
166
- return {
167
- hasDataLoss: shouldAskForApprove,
168
- warnings: infoToPrint,
169
- statementsToExecute,
170
- apply: async () => {
171
- for (const dStmnt of statementsToExecute) {
172
- await db.query(dStmnt);
173
- }
174
- },
175
- };
176
- };
177
-
178
- // SQLite
179
-
180
- export const generateSQLiteDrizzleJson = async (
181
- imports: Record<string, unknown>,
182
- prevId?: string,
183
- casing?: CasingType,
184
- ): Promise<SQLiteSchemaKit> => {
185
- const { prepareFromExports } = await import('./serializer/sqliteImports');
186
-
187
- const prepared = prepareFromExports(imports);
188
-
189
- const id = randomUUID();
190
-
191
- const snapshot = generateSqliteSnapshot(prepared.tables, prepared.views, casing);
192
-
193
- return {
194
- ...snapshot,
195
- id,
196
- prevId: prevId ?? originUUID,
197
- };
198
- };
199
-
200
- export const generateSQLiteMigration = async (
201
- prev: DrizzleSQLiteSnapshotJSON,
202
- cur: DrizzleSQLiteSnapshotJSON,
203
- ) => {
204
- const { applySqliteSnapshotsDiff } = await import('./snapshotsDiffer');
205
-
206
- const validatedPrev = sqliteSchema.parse(prev);
207
- const validatedCur = sqliteSchema.parse(cur);
208
-
209
- const squashedPrev = squashSqliteScheme(validatedPrev);
210
- const squashedCur = squashSqliteScheme(validatedCur);
211
-
212
- const { sqlStatements } = await applySqliteSnapshotsDiff(
213
- squashedPrev,
214
- squashedCur,
215
- tablesResolver,
216
- columnsResolver,
217
- sqliteViewsResolver,
218
- validatedPrev,
219
- validatedCur,
220
- );
221
-
222
- return sqlStatements;
223
- };
224
-
225
- export const pushSQLiteSchema = async (
226
- imports: Record<string, unknown>,
227
- drizzleInstance: LibSQLDatabase<any>,
228
- ) => {
229
- const { applySqliteSnapshotsDiff } = await import('./snapshotsDiffer');
230
- const { sql } = await import('drizzle-orm');
231
-
232
- const db: SQLiteDB = {
233
- query: async (query: string, params?: any[]) => {
234
- const res = drizzleInstance.all<any>(sql.raw(query));
235
- return res;
236
- },
237
- run: async (query: string) => {
238
- return Promise.resolve(drizzleInstance.run(sql.raw(query))).then(
239
- () => {},
240
- );
241
- },
242
- };
243
-
244
- const cur = await generateSQLiteDrizzleJson(imports);
245
- const { schema: prev } = await sqlitePushIntrospect(db, []);
246
-
247
- const validatedPrev = sqliteSchema.parse(prev);
248
- const validatedCur = sqliteSchema.parse(cur);
249
-
250
- const squashedPrev = squashSqliteScheme(validatedPrev, 'push');
251
- const squashedCur = squashSqliteScheme(validatedCur, 'push');
252
-
253
- const { statements, _meta } = await applySqliteSnapshotsDiff(
254
- squashedPrev,
255
- squashedCur,
256
- tablesResolver,
257
- columnsResolver,
258
- sqliteViewsResolver,
259
- validatedPrev,
260
- validatedCur,
261
- 'push',
262
- );
263
-
264
- const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn(
265
- db,
266
- statements,
267
- squashedPrev,
268
- squashedCur,
269
- _meta!,
270
- );
271
-
272
- return {
273
- hasDataLoss: shouldAskForApprove,
274
- warnings: infoToPrint,
275
- statementsToExecute,
276
- apply: async () => {
277
- for (const dStmnt of statementsToExecute) {
278
- await db.query(dStmnt);
279
- }
280
- },
281
- };
282
- };
283
-
284
- // MySQL
285
-
286
- export const generateMySQLDrizzleJson = async (
287
- imports: Record<string, unknown>,
288
- prevId?: string,
289
- casing?: CasingType,
290
- ): Promise<MySQLSchemaKit> => {
291
- const { prepareFromExports } = await import('./serializer/mysqlImports');
292
-
293
- const prepared = prepareFromExports(imports);
294
-
295
- const id = randomUUID();
296
-
297
- const snapshot = generateMySqlSnapshot(prepared.tables, prepared.views, casing);
298
-
299
- return {
300
- ...snapshot,
301
- id,
302
- prevId: prevId ?? originUUID,
303
- };
304
- };
305
-
306
- export const generateMySQLMigration = async (
307
- prev: DrizzleMySQLSnapshotJSON,
308
- cur: DrizzleMySQLSnapshotJSON,
309
- ) => {
310
- const { applyMysqlSnapshotsDiff } = await import('./snapshotsDiffer');
311
-
312
- const validatedPrev = mysqlSchema.parse(prev);
313
- const validatedCur = mysqlSchema.parse(cur);
314
-
315
- const squashedPrev = squashMysqlScheme(validatedPrev);
316
- const squashedCur = squashMysqlScheme(validatedCur);
317
-
318
- const { sqlStatements } = await applyMysqlSnapshotsDiff(
319
- squashedPrev,
320
- squashedCur,
321
- tablesResolver,
322
- columnsResolver,
323
- mySqlViewsResolver,
324
- validatedPrev,
325
- validatedCur,
326
- );
327
-
328
- return sqlStatements;
329
- };
330
-
331
- export const pushMySQLSchema = async (
332
- imports: Record<string, unknown>,
333
- drizzleInstance: MySql2Database<any>,
334
- databaseName: string,
335
- ) => {
336
- const { applyMysqlSnapshotsDiff } = await import('./snapshotsDiffer');
337
- const { logSuggestionsAndReturn } = await import(
338
- './cli/commands/mysqlPushUtils'
339
- );
340
- const { mysqlPushIntrospect } = await import(
341
- './cli/commands/mysqlIntrospect'
342
- );
343
- const { sql } = await import('drizzle-orm');
344
-
345
- const db: DB = {
346
- query: async (query: string, params?: any[]) => {
347
- const res = await drizzleInstance.execute(sql.raw(query));
348
- return res[0] as unknown as any[];
349
- },
350
- };
351
- const cur = await generateMySQLDrizzleJson(imports);
352
- const { schema: prev } = await mysqlPushIntrospect(db, databaseName, []);
353
-
354
- const validatedPrev = mysqlSchema.parse(prev);
355
- const validatedCur = mysqlSchema.parse(cur);
356
-
357
- const squashedPrev = squashMysqlScheme(validatedPrev);
358
- const squashedCur = squashMysqlScheme(validatedCur);
359
-
360
- const { statements } = await applyMysqlSnapshotsDiff(
361
- squashedPrev,
362
- squashedCur,
363
- tablesResolver,
364
- columnsResolver,
365
- mySqlViewsResolver,
366
- validatedPrev,
367
- validatedCur,
368
- 'push',
369
- );
370
-
371
- const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn(
372
- db,
373
- statements,
374
- validatedCur,
375
- );
376
-
377
- return {
378
- hasDataLoss: shouldAskForApprove,
379
- warnings: infoToPrint,
380
- statementsToExecute,
381
- apply: async () => {
382
- for (const dStmnt of statementsToExecute) {
383
- await db.query(dStmnt);
384
- }
385
- },
386
- };
387
- };
388
-
389
- // SingleStore
390
-
391
- export const generateSingleStoreDrizzleJson = async (
392
- imports: Record<string, unknown>,
393
- prevId?: string,
394
- casing?: CasingType,
395
- ): Promise<SingleStoreSchemaKit> => {
396
- const { prepareFromExports } = await import('./serializer/singlestoreImports');
397
-
398
- const prepared = prepareFromExports(imports);
399
-
400
- const id = randomUUID();
401
-
402
- const snapshot = generateSingleStoreSnapshot(prepared.tables, /* prepared.views, */ casing);
403
-
404
- return {
405
- ...snapshot,
406
- id,
407
- prevId: prevId ?? originUUID,
408
- };
409
- };
410
-
411
- export const generateSingleStoreMigration = async (
412
- prev: DrizzleSingleStoreSnapshotJSON,
413
- cur: DrizzleSingleStoreSnapshotJSON,
414
- ) => {
415
- const { applySingleStoreSnapshotsDiff } = await import('./snapshotsDiffer');
416
-
417
- const validatedPrev = singlestoreSchema.parse(prev);
418
- const validatedCur = singlestoreSchema.parse(cur);
419
-
420
- const squashedPrev = squashSingleStoreScheme(validatedPrev);
421
- const squashedCur = squashSingleStoreScheme(validatedCur);
422
-
423
- const { sqlStatements } = await applySingleStoreSnapshotsDiff(
424
- squashedPrev,
425
- squashedCur,
426
- tablesResolver,
427
- columnsResolver,
428
- /* singleStoreViewsResolver, */
429
- validatedPrev,
430
- validatedCur,
431
- 'push',
432
- );
433
-
434
- return sqlStatements;
435
- };
436
-
437
- export const pushSingleStoreSchema = async (
438
- imports: Record<string, unknown>,
439
- drizzleInstance: SingleStoreDriverDatabase<any>,
440
- databaseName: string,
441
- ) => {
442
- const { applySingleStoreSnapshotsDiff } = await import('./snapshotsDiffer');
443
- const { logSuggestionsAndReturn } = await import(
444
- './cli/commands/singlestorePushUtils'
445
- );
446
- const { singlestorePushIntrospect } = await import(
447
- './cli/commands/singlestoreIntrospect'
448
- );
449
- const { sql } = await import('drizzle-orm');
450
-
451
- const db: DB = {
452
- query: async (query: string) => {
453
- const res = await drizzleInstance.execute(sql.raw(query));
454
- return res[0] as unknown as any[];
455
- },
456
- };
457
- const cur = await generateSingleStoreDrizzleJson(imports);
458
- const { schema: prev } = await singlestorePushIntrospect(db, databaseName, []);
459
-
460
- const validatedPrev = singlestoreSchema.parse(prev);
461
- const validatedCur = singlestoreSchema.parse(cur);
462
-
463
- const squashedPrev = squashSingleStoreScheme(validatedPrev);
464
- const squashedCur = squashSingleStoreScheme(validatedCur);
465
-
466
- const { statements } = await applySingleStoreSnapshotsDiff(
467
- squashedPrev,
468
- squashedCur,
469
- tablesResolver,
470
- columnsResolver,
471
- /* singleStoreViewsResolver, */
472
- validatedPrev,
473
- validatedCur,
474
- 'push',
475
- );
476
-
477
- const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn(
478
- db,
479
- statements,
480
- validatedCur,
481
- validatedPrev,
482
- );
483
-
484
- return {
485
- hasDataLoss: shouldAskForApprove,
486
- warnings: infoToPrint,
487
- statementsToExecute,
488
- apply: async () => {
489
- for (const dStmnt of statementsToExecute) {
490
- await db.query(dStmnt);
491
- }
492
- },
493
- };
494
- };
495
-
496
- export const upPgSnapshot = (snapshot: Record<string, unknown>) => {
497
- if (snapshot.version === '5') {
498
- return upPgV7(upPgV6(snapshot));
499
- }
500
- if (snapshot.version === '6') {
501
- return upPgV7(snapshot);
502
- }
503
- return snapshot;
504
- };
@@ -1,2 +0,0 @@
1
- const _ = '';
2
- export default _;
@@ -1,52 +0,0 @@
1
- import { Dialect } from '../../schemaValidator';
2
- import { prepareOutFolder, validateWithReport } from '../../utils';
3
-
4
- export const checkHandler = (out: string, dialect: Dialect) => {
5
- const { snapshots } = prepareOutFolder(out, dialect);
6
- const report = validateWithReport(snapshots, dialect);
7
-
8
- if (report.nonLatest.length > 0) {
9
- console.log(
10
- report.nonLatest
11
- .map((it) => {
12
- return `${it} is not of the latest version, please run "drizzle-kit up"`;
13
- })
14
- .join('\n'),
15
- );
16
- process.exit(1);
17
- }
18
-
19
- if (report.malformed.length) {
20
- const message = report.malformed
21
- .map((it) => {
22
- return `${it} data is malformed`;
23
- })
24
- .join('\n');
25
- console.log(message);
26
- }
27
-
28
- const collisionEntries = Object.entries(report.idsMap).filter(
29
- (it) => it[1].snapshots.length > 1,
30
- );
31
-
32
- const message = collisionEntries
33
- .map((it) => {
34
- const data = it[1];
35
- return `[${
36
- data.snapshots.join(
37
- ', ',
38
- )
39
- }] are pointing to a parent snapshot: ${data.parent}/snapshot.json which is a collision.`;
40
- })
41
- .join('\n');
42
-
43
- if (message) {
44
- console.log(message);
45
- }
46
-
47
- const abort = report.malformed.length!! || collisionEntries.length > 0;
48
-
49
- if (abort) {
50
- process.exit(1);
51
- }
52
- };