@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.
- package/api.d.mts +2891 -0
- package/api.d.ts +2891 -0
- package/api.js +47534 -0
- package/api.mjs +47521 -0
- package/bin.cjs +80043 -0
- package/{src/index.ts → index-Z-1TKnbX.d.mts} +123 -141
- package/index-Z-1TKnbX.d.ts +308 -0
- package/index.d.mts +2 -0
- package/index.d.ts +2 -0
- package/index.js +32 -0
- package/index.mjs +7 -0
- package/package.json +2 -2
- package/utils.js +6056 -0
- package/utils.mjs +6032 -0
- package/.gitignore +0 -25
- package/build.dev.ts +0 -51
- package/build.ts +0 -112
- package/imports-checker/analyze.ts +0 -78
- package/imports-checker/checker.ts +0 -296
- package/imports-checker/grammar/grammar.ohm +0 -121
- package/imports-checker/grammar/grammar.ohm-bundle.d.ts +0 -164
- package/imports-checker/grammar/grammar.ohm-bundle.js +0 -753
- package/imports-checker/index.ts +0 -48
- package/patches/difflib@0.2.4.patch +0 -31
- package/src/@types/utils.ts +0 -58
- package/src/api.ts +0 -504
- package/src/cli/commands/_es5.ts +0 -2
- package/src/cli/commands/check.ts +0 -52
- package/src/cli/commands/drop.ts +0 -60
- package/src/cli/commands/introspect.ts +0 -772
- package/src/cli/commands/libSqlPushUtils.ts +0 -355
- package/src/cli/commands/migrate.ts +0 -1526
- package/src/cli/commands/mysqlIntrospect.ts +0 -53
- package/src/cli/commands/mysqlPushUtils.ts +0 -352
- package/src/cli/commands/mysqlUp.ts +0 -102
- package/src/cli/commands/pgIntrospect.ts +0 -55
- package/src/cli/commands/pgPushUtils.ts +0 -269
- package/src/cli/commands/pgUp.ts +0 -217
- package/src/cli/commands/push.ts +0 -637
- package/src/cli/commands/singlestoreIntrospect.ts +0 -53
- package/src/cli/commands/singlestorePushUtils.ts +0 -456
- package/src/cli/commands/singlestoreUp.ts +0 -1
- package/src/cli/commands/sqliteIntrospect.ts +0 -96
- package/src/cli/commands/sqlitePushUtils.ts +0 -322
- package/src/cli/commands/sqliteUp.ts +0 -52
- package/src/cli/commands/utils.ts +0 -858
- package/src/cli/connections.ts +0 -914
- package/src/cli/index.ts +0 -48
- package/src/cli/schema.ts +0 -794
- package/src/cli/selector-ui.ts +0 -38
- package/src/cli/utils.ts +0 -112
- package/src/cli/validations/cli.ts +0 -79
- package/src/cli/validations/common.ts +0 -193
- package/src/cli/validations/libsql.ts +0 -27
- package/src/cli/validations/mysql.ts +0 -61
- package/src/cli/validations/outputs.ts +0 -91
- package/src/cli/validations/postgres.ts +0 -83
- package/src/cli/validations/singlestore.ts +0 -61
- package/src/cli/validations/sqlite.ts +0 -104
- package/src/cli/validations/studio.ts +0 -24
- package/src/cli/views.ts +0 -658
- package/src/extensions/getTablesFilterByExtensions.ts +0 -16
- package/src/extensions/vector.ts +0 -10
- package/src/global.ts +0 -61
- package/src/introspect-mysql.ts +0 -1030
- package/src/introspect-pg.ts +0 -1435
- package/src/introspect-singlestore.ts +0 -913
- package/src/introspect-sqlite.ts +0 -533
- package/src/jsonDiffer.js +0 -882
- package/src/jsonStatements.ts +0 -3590
- package/src/loader.mjs +0 -57
- package/src/migrationPreparator.ts +0 -217
- package/src/schemaValidator.ts +0 -23
- package/src/serializer/index.ts +0 -142
- package/src/serializer/mysqlImports.ts +0 -38
- package/src/serializer/mysqlSchema.ts +0 -423
- package/src/serializer/mysqlSerializer.ts +0 -999
- package/src/serializer/pgImports.ts +0 -106
- package/src/serializer/pgSchema.ts +0 -937
- package/src/serializer/pgSerializer.ts +0 -2223
- package/src/serializer/singlestoreImports.ts +0 -38
- package/src/serializer/singlestoreSchema.ts +0 -257
- package/src/serializer/singlestoreSerializer.ts +0 -767
- package/src/serializer/sqliteImports.ts +0 -41
- package/src/serializer/sqliteSchema.ts +0 -352
- package/src/serializer/sqliteSerializer.ts +0 -931
- package/src/serializer/studio.ts +0 -694
- package/src/serializer/utils.ts +0 -45
- package/src/simulator.ts +0 -157
- package/src/snapshotsDiffer.ts +0 -4398
- package/src/sqlgenerator.ts +0 -4212
- package/src/statementCombiner.ts +0 -597
- package/src/utils/certs.ts +0 -44
- package/src/utils/words.ts +0 -1333
- package/src/utils.ts +0 -370
- package/tests/bin.test.ts +0 -58
- package/tests/cli/d1http.config.ts +0 -12
- package/tests/cli/drizzle.config.ts +0 -9
- package/tests/cli/durable-sqlite.config.ts +0 -7
- package/tests/cli/expo.config.ts +0 -7
- package/tests/cli/postgres.config.ts +0 -13
- package/tests/cli/postgres2.config.ts +0 -17
- package/tests/cli/schema.ts +0 -1
- package/tests/cli/turso.config.ts +0 -10
- package/tests/cli-export.test.ts +0 -79
- package/tests/cli-generate.test.ts +0 -259
- package/tests/cli-migrate.test.ts +0 -103
- package/tests/cli-push.test.ts +0 -126
- package/tests/common.ts +0 -15
- package/tests/indexes/common.ts +0 -21
- package/tests/indexes/pg.test.ts +0 -245
- package/tests/introspect/libsql.test.ts +0 -35
- package/tests/introspect/mysql.test.ts +0 -319
- package/tests/introspect/pg.test.ts +0 -894
- package/tests/introspect/singlestore.test.ts +0 -275
- package/tests/introspect/sqlite.test.ts +0 -122
- package/tests/libsql-checks.test.ts +0 -308
- package/tests/libsql-statements.test.ts +0 -989
- package/tests/libsql-views.test.ts +0 -218
- package/tests/migrate/libsq-schema.ts +0 -6
- package/tests/migrate/libsql-migrate.test.ts +0 -58
- package/tests/migrate/migrations/0000_little_blizzard.sql +0 -4
- package/tests/migrate/migrations/0001_nebulous_storm.sql +0 -10
- package/tests/migrate/migrations/meta/0000_snapshot.json +0 -40
- package/tests/migrate/migrations/meta/0001_snapshot.json +0 -40
- package/tests/migrate/migrations/meta/_journal.json +0 -20
- package/tests/mysql-checks.test.ts +0 -291
- package/tests/mysql-generated.test.ts +0 -1290
- package/tests/mysql-schemas.test.ts +0 -156
- package/tests/mysql-views.test.ts +0 -553
- package/tests/mysql.test.ts +0 -863
- package/tests/pg-array.test.ts +0 -368
- package/tests/pg-checks.test.ts +0 -329
- package/tests/pg-columns.test.ts +0 -484
- package/tests/pg-domains.test.ts +0 -306
- package/tests/pg-enums.test.ts +0 -751
- package/tests/pg-generated.test.ts +0 -529
- package/tests/pg-identity.test.ts +0 -447
- package/tests/pg-schemas.test.ts +0 -105
- package/tests/pg-sequences.test.ts +0 -298
- package/tests/pg-tables.test.ts +0 -1021
- package/tests/pg-views.test.ts +0 -1929
- package/tests/push/common.ts +0 -58
- package/tests/push/libsql.test.ts +0 -1400
- package/tests/push/mysql-push.test.ts +0 -345
- package/tests/push/mysql.test.ts +0 -788
- package/tests/push/pg.test.ts +0 -4341
- package/tests/push/singlestore-push.test.ts +0 -894
- package/tests/push/singlestore.test.ts +0 -444
- package/tests/push/sqlite.test.ts +0 -1613
- package/tests/rls/pg-policy.test.ts +0 -1656
- package/tests/rls/pg-role.test.ts +0 -234
- package/tests/schemaDiffer.ts +0 -2852
- package/tests/singlestore-generated.test.ts +0 -1290
- package/tests/singlestore-schemas.test.ts +0 -155
- package/tests/singlestore.test.ts +0 -978
- package/tests/sqlite-checks.test.ts +0 -308
- package/tests/sqlite-columns.test.ts +0 -1049
- package/tests/sqlite-generated.test.ts +0 -1726
- package/tests/sqlite-tables.test.ts +0 -637
- package/tests/sqlite-views.test.ts +0 -218
- package/tests/statements-combiner/libsql-statements-combiner.test.ts +0 -1812
- package/tests/statements-combiner/singlestore-statements-combiner.test.ts +0 -882
- package/tests/statements-combiner/sqlite-statements-combiner.test.ts +0 -1211
- package/tests/test/sqlite.test.ts +0 -39
- package/tests/testsinglestore.ts +0 -29
- package/tests/validations.test.ts +0 -869
- package/tests/wrap-param.test.ts +0 -16
- package/tsconfig.build.json +0 -4
- package/tsconfig.cli-types.json +0 -9
- package/tsconfig.json +0 -28
- package/vitest.config.ts +0 -34
package/src/utils.ts
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
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
|
-
}
|
package/tests/bin.test.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/cli/expo.config.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/cli/schema.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// mock
|
package/tests/cli-export.test.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
});
|