@anthonyalayo/drizzle-kit 1.0.2 → 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 +1 -1
- 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/cli/selector-ui.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { Prompt, SelectState } from 'hanji';
|
|
3
|
-
|
|
4
|
-
export class Select extends Prompt<{ index: number; value: string }> {
|
|
5
|
-
private readonly data: SelectState<{ label: string; value: string }>;
|
|
6
|
-
|
|
7
|
-
constructor(items: string[]) {
|
|
8
|
-
super();
|
|
9
|
-
this.on('attach', (terminal) => terminal.toggleCursor('hide'));
|
|
10
|
-
this.on('detach', (terminal) => terminal.toggleCursor('show'));
|
|
11
|
-
|
|
12
|
-
this.data = new SelectState(
|
|
13
|
-
items.map((it) => ({ label: it, value: `${it}-value` })),
|
|
14
|
-
);
|
|
15
|
-
this.data.bind(this);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
render(status: 'idle' | 'submitted' | 'aborted'): string {
|
|
19
|
-
if (status === 'submitted' || status === 'aborted') return '';
|
|
20
|
-
|
|
21
|
-
let text = ``;
|
|
22
|
-
this.data.items.forEach((it, idx) => {
|
|
23
|
-
text += idx === this.data.selectedIdx
|
|
24
|
-
? `${chalk.green('❯ ' + it.label)}`
|
|
25
|
-
: ` ${it.label}`;
|
|
26
|
-
text += idx != this.data.items.length - 1 ? '\n' : '';
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return text;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
result() {
|
|
33
|
-
return {
|
|
34
|
-
index: this.data.selectedIdx,
|
|
35
|
-
value: this.data.items[this.data.selectedIdx]!.value!,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/cli/utils.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import semver from 'semver';
|
|
2
|
-
import { err, warning } from './views';
|
|
3
|
-
|
|
4
|
-
export const assertExists = (it?: any) => {
|
|
5
|
-
if (!it) throw new Error();
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const ormVersionGt = async (version: string) => {
|
|
9
|
-
const { npmVersion } = await import('drizzle-orm/version');
|
|
10
|
-
if (!semver.gte(npmVersion, version)) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return true;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const assertStudioNodeVersion = () => {
|
|
17
|
-
if (semver.gte(process.version, '18.0.0')) return;
|
|
18
|
-
|
|
19
|
-
err('Drizzle Studio requires NodeJS v18 or above');
|
|
20
|
-
process.exit(1);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const checkPackage = async (it: string) => {
|
|
24
|
-
try {
|
|
25
|
-
await import(it);
|
|
26
|
-
return true;
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const assertPackages = async (...pkgs: string[]) => {
|
|
33
|
-
try {
|
|
34
|
-
for (let i = 0; i < pkgs.length; i++) {
|
|
35
|
-
const it = pkgs[i];
|
|
36
|
-
await import(it);
|
|
37
|
-
}
|
|
38
|
-
} catch (e) {
|
|
39
|
-
err(
|
|
40
|
-
`please install required packages: ${
|
|
41
|
-
pkgs
|
|
42
|
-
.map((it) => `'${it}'`)
|
|
43
|
-
.join(' ')
|
|
44
|
-
}`,
|
|
45
|
-
);
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// ex: either pg or postgres are needed
|
|
51
|
-
export const assertEitherPackage = async (
|
|
52
|
-
...pkgs: string[]
|
|
53
|
-
): Promise<string[]> => {
|
|
54
|
-
const availables = [] as string[];
|
|
55
|
-
for (let i = 0; i < pkgs.length; i++) {
|
|
56
|
-
try {
|
|
57
|
-
const it = pkgs[i];
|
|
58
|
-
await import(it);
|
|
59
|
-
availables.push(it);
|
|
60
|
-
} catch (e) {}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (availables.length > 0) {
|
|
64
|
-
return availables;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
err(
|
|
68
|
-
`Please install one of those packages are needed: ${
|
|
69
|
-
pkgs
|
|
70
|
-
.map((it) => `'${it}'`)
|
|
71
|
-
.join(' or ')
|
|
72
|
-
}`,
|
|
73
|
-
);
|
|
74
|
-
process.exit(1);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const requiredApiVersion = 10;
|
|
78
|
-
export const assertOrmCoreVersion = async () => {
|
|
79
|
-
try {
|
|
80
|
-
const { compatibilityVersion } = await import('drizzle-orm/version');
|
|
81
|
-
|
|
82
|
-
await import('drizzle-orm/relations');
|
|
83
|
-
|
|
84
|
-
if (compatibilityVersion && compatibilityVersion === requiredApiVersion) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!compatibilityVersion || compatibilityVersion < requiredApiVersion) {
|
|
89
|
-
console.log(
|
|
90
|
-
'This version of drizzle-kit requires newer version of drizzle-orm\nPlease update drizzle-orm package to the latest version 👍',
|
|
91
|
-
);
|
|
92
|
-
} else {
|
|
93
|
-
console.log(
|
|
94
|
-
'This version of drizzle-kit is outdated\nPlease update drizzle-kit package to the latest version 👍',
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
} catch (e) {
|
|
98
|
-
console.log('Please install latest version of drizzle-orm');
|
|
99
|
-
}
|
|
100
|
-
process.exit(1);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const ormCoreVersions = async () => {
|
|
104
|
-
try {
|
|
105
|
-
const { compatibilityVersion, npmVersion } = await import(
|
|
106
|
-
'drizzle-orm/version'
|
|
107
|
-
);
|
|
108
|
-
return { compatibilityVersion, npmVersion };
|
|
109
|
-
} catch (e) {
|
|
110
|
-
return {};
|
|
111
|
-
}
|
|
112
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { array, boolean, intersection, literal, object, string, TypeOf, union } from 'zod';
|
|
2
|
-
import { dialect } from '../../schemaValidator';
|
|
3
|
-
import { casing, casingType, prefix } from './common';
|
|
4
|
-
|
|
5
|
-
export const cliConfigGenerate = object({
|
|
6
|
-
dialect: dialect.optional(),
|
|
7
|
-
schema: union([string(), string().array()]).optional(),
|
|
8
|
-
out: string().optional().default('./drizzle'),
|
|
9
|
-
config: string().optional(),
|
|
10
|
-
name: string().optional(),
|
|
11
|
-
prefix: prefix.optional(),
|
|
12
|
-
breakpoints: boolean().optional().default(true),
|
|
13
|
-
custom: boolean().optional().default(false),
|
|
14
|
-
}).strict();
|
|
15
|
-
|
|
16
|
-
export type CliConfigGenerate = TypeOf<typeof cliConfigGenerate>;
|
|
17
|
-
|
|
18
|
-
export const pushParams = object({
|
|
19
|
-
dialect: dialect,
|
|
20
|
-
casing: casingType.optional(),
|
|
21
|
-
schema: union([string(), string().array()]),
|
|
22
|
-
tablesFilter: union([string(), string().array()]).optional(),
|
|
23
|
-
schemaFilter: union([string(), string().array()])
|
|
24
|
-
.optional()
|
|
25
|
-
.default(['public']),
|
|
26
|
-
extensionsFilters: literal('postgis').array().optional(),
|
|
27
|
-
verbose: boolean().optional(),
|
|
28
|
-
strict: boolean().optional(),
|
|
29
|
-
entities: object({
|
|
30
|
-
roles: boolean().or(object({
|
|
31
|
-
provider: string().optional(),
|
|
32
|
-
include: string().array().optional(),
|
|
33
|
-
exclude: string().array().optional(),
|
|
34
|
-
})).optional().default(false),
|
|
35
|
-
}).optional(),
|
|
36
|
-
}).passthrough();
|
|
37
|
-
|
|
38
|
-
export type PushParams = TypeOf<typeof pushParams>;
|
|
39
|
-
|
|
40
|
-
export const pullParams = object({
|
|
41
|
-
config: string().optional(),
|
|
42
|
-
dialect: dialect,
|
|
43
|
-
out: string().optional().default('drizzle'),
|
|
44
|
-
tablesFilter: union([string(), string().array()]).optional(),
|
|
45
|
-
schemaFilter: union([string(), string().array()])
|
|
46
|
-
.optional()
|
|
47
|
-
.default(['public']),
|
|
48
|
-
extensionsFilters: literal('postgis').array().optional(),
|
|
49
|
-
casing,
|
|
50
|
-
breakpoints: boolean().optional().default(true),
|
|
51
|
-
migrations: object({
|
|
52
|
-
prefix: prefix.optional().default('index'),
|
|
53
|
-
}).optional(),
|
|
54
|
-
entities: object({
|
|
55
|
-
roles: boolean().or(object({
|
|
56
|
-
provider: string().optional(),
|
|
57
|
-
include: string().array().optional(),
|
|
58
|
-
exclude: string().array().optional(),
|
|
59
|
-
})).optional().default(false),
|
|
60
|
-
}).optional(),
|
|
61
|
-
}).passthrough();
|
|
62
|
-
|
|
63
|
-
export type Entities = TypeOf<typeof pullParams>['entities'];
|
|
64
|
-
|
|
65
|
-
export type PullParams = TypeOf<typeof pullParams>;
|
|
66
|
-
|
|
67
|
-
export const configCheck = object({
|
|
68
|
-
dialect: dialect.optional(),
|
|
69
|
-
out: string().optional(),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
export const cliConfigCheck = intersection(
|
|
73
|
-
object({
|
|
74
|
-
config: string().optional(),
|
|
75
|
-
}),
|
|
76
|
-
configCheck,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
export type CliCheckConfig = TypeOf<typeof cliConfigCheck>;
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { UnionToIntersection } from 'hono/utils/types';
|
|
3
|
-
import { any, boolean, enum as enum_, literal, object, string, TypeOf, union } from 'zod';
|
|
4
|
-
import { dialect } from '../../schemaValidator';
|
|
5
|
-
import { outputs } from './outputs';
|
|
6
|
-
|
|
7
|
-
export type Commands =
|
|
8
|
-
| 'introspect'
|
|
9
|
-
| 'generate'
|
|
10
|
-
| 'check'
|
|
11
|
-
| 'up'
|
|
12
|
-
| 'drop'
|
|
13
|
-
| 'push'
|
|
14
|
-
| 'export';
|
|
15
|
-
|
|
16
|
-
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
|
17
|
-
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
18
|
-
type LastTupleElement<TArr extends any[]> = TArr extends [
|
|
19
|
-
...start: infer _,
|
|
20
|
-
end: infer Last,
|
|
21
|
-
] ? Last
|
|
22
|
-
: never;
|
|
23
|
-
|
|
24
|
-
export type UniqueArrayOfUnion<TUnion, TArray extends TUnion[]> = Exclude<
|
|
25
|
-
TUnion,
|
|
26
|
-
TArray[number]
|
|
27
|
-
> extends never ? [TUnion]
|
|
28
|
-
: [...TArray, Exclude<TUnion, TArray[number]>];
|
|
29
|
-
|
|
30
|
-
export const assertCollisions = <
|
|
31
|
-
T extends Record<string, unknown>,
|
|
32
|
-
TKeys extends (keyof T)[],
|
|
33
|
-
TRemainingKeys extends Exclude<keyof T, TKeys[number] | 'config'>[],
|
|
34
|
-
Exhaustive extends TRemainingKeys,
|
|
35
|
-
UNIQ extends UniqueArrayOfUnion<TRemainingKeys[number], Exhaustive>,
|
|
36
|
-
>(
|
|
37
|
-
command: Commands,
|
|
38
|
-
options: T,
|
|
39
|
-
whitelist: Exclude<TKeys, 'config'>,
|
|
40
|
-
remainingKeys: UniqueArrayOfUnion<TRemainingKeys[number], Exhaustive>,
|
|
41
|
-
): IsUnion<LastTupleElement<UNIQ>> extends false ? 'cli' | 'config' : TKeys => {
|
|
42
|
-
const { config, ...rest } = options;
|
|
43
|
-
|
|
44
|
-
let atLeastOneParam = false;
|
|
45
|
-
for (const key of Object.keys(rest)) {
|
|
46
|
-
if (whitelist.includes(key)) continue;
|
|
47
|
-
|
|
48
|
-
atLeastOneParam = atLeastOneParam || rest[key] !== undefined;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!config && atLeastOneParam) {
|
|
52
|
-
return 'cli' as any;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!atLeastOneParam) {
|
|
56
|
-
return 'config' as any;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// if config and cli - return error - write a reason
|
|
60
|
-
console.log(outputs.common.ambiguousParams(command));
|
|
61
|
-
process.exit(1);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const sqliteDriversLiterals = [
|
|
65
|
-
literal('d1-http'),
|
|
66
|
-
literal('expo'),
|
|
67
|
-
literal('durable-sqlite'),
|
|
68
|
-
] as const;
|
|
69
|
-
|
|
70
|
-
export const postgresqlDriversLiterals = [
|
|
71
|
-
literal('aws-data-api'),
|
|
72
|
-
literal('pglite'),
|
|
73
|
-
] as const;
|
|
74
|
-
|
|
75
|
-
export const prefixes = [
|
|
76
|
-
'index',
|
|
77
|
-
'timestamp',
|
|
78
|
-
'supabase',
|
|
79
|
-
'unix',
|
|
80
|
-
'none',
|
|
81
|
-
] as const;
|
|
82
|
-
export const prefix = enum_(prefixes);
|
|
83
|
-
export type Prefix = (typeof prefixes)[number];
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
const _: Prefix = '' as TypeOf<typeof prefix>;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const casingTypes = ['snake_case', 'camelCase'] as const;
|
|
90
|
-
export const casingType = enum_(casingTypes);
|
|
91
|
-
export type CasingType = (typeof casingTypes)[number];
|
|
92
|
-
|
|
93
|
-
export const sqliteDriver = union(sqliteDriversLiterals);
|
|
94
|
-
export const postgresDriver = union(postgresqlDriversLiterals);
|
|
95
|
-
export const driver = union([sqliteDriver, postgresDriver]);
|
|
96
|
-
|
|
97
|
-
export const configMigrations = object({
|
|
98
|
-
table: string().optional(),
|
|
99
|
-
schema: string().optional(),
|
|
100
|
-
prefix: prefix.optional().default('index'),
|
|
101
|
-
}).optional();
|
|
102
|
-
|
|
103
|
-
export const configCommonSchema = object({
|
|
104
|
-
dialect: dialect,
|
|
105
|
-
schema: union([string(), string().array()]).optional(),
|
|
106
|
-
out: string().optional(),
|
|
107
|
-
breakpoints: boolean().optional().default(true),
|
|
108
|
-
verbose: boolean().optional().default(false),
|
|
109
|
-
driver: driver.optional(),
|
|
110
|
-
tablesFilter: union([string(), string().array()]).optional(),
|
|
111
|
-
schemaFilter: union([string(), string().array()]).default(['public']),
|
|
112
|
-
migrations: configMigrations,
|
|
113
|
-
dbCredentials: any().optional(),
|
|
114
|
-
casing: casingType.optional(),
|
|
115
|
-
sql: boolean().default(true),
|
|
116
|
-
}).passthrough();
|
|
117
|
-
|
|
118
|
-
export const casing = union([literal('camel'), literal('preserve')]).default(
|
|
119
|
-
'camel',
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
export const introspectParams = object({
|
|
123
|
-
schema: union([string(), string().array()]).optional(),
|
|
124
|
-
out: string().optional().default('./drizzle'),
|
|
125
|
-
breakpoints: boolean().default(true),
|
|
126
|
-
tablesFilter: union([string(), string().array()]).optional(),
|
|
127
|
-
schemaFilter: union([string(), string().array()]).default(['public']),
|
|
128
|
-
introspect: object({
|
|
129
|
-
casing,
|
|
130
|
-
}).default({ casing: 'camel' }),
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
export type IntrospectParams = TypeOf<typeof introspectParams>;
|
|
134
|
-
export type Casing = TypeOf<typeof casing>;
|
|
135
|
-
|
|
136
|
-
export const configIntrospectCliSchema = object({
|
|
137
|
-
schema: union([string(), string().array()]).optional(),
|
|
138
|
-
out: string().optional().default('./drizzle'),
|
|
139
|
-
breakpoints: boolean().default(true),
|
|
140
|
-
tablesFilter: union([string(), string().array()]).optional(),
|
|
141
|
-
schemaFilter: union([string(), string().array()]).default(['public']),
|
|
142
|
-
introspectCasing: union([literal('camel'), literal('preserve')]).default(
|
|
143
|
-
'camel',
|
|
144
|
-
),
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
export const configGenerateSchema = object({
|
|
148
|
-
schema: union([string(), string().array()]),
|
|
149
|
-
out: string().optional().default('./drizzle'),
|
|
150
|
-
breakpoints: boolean().default(true),
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
export type GenerateSchema = TypeOf<typeof configGenerateSchema>;
|
|
154
|
-
|
|
155
|
-
export const configPushSchema = object({
|
|
156
|
-
dialect: dialect,
|
|
157
|
-
schema: union([string(), string().array()]),
|
|
158
|
-
tablesFilter: union([string(), string().array()]).optional(),
|
|
159
|
-
schemaFilter: union([string(), string().array()]).default(['public']),
|
|
160
|
-
verbose: boolean().default(false),
|
|
161
|
-
strict: boolean().default(false),
|
|
162
|
-
out: string().optional(),
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
export type CliConfig = TypeOf<typeof configCommonSchema>;
|
|
166
|
-
export const drivers = ['d1-http', 'expo', 'aws-data-api', 'pglite', 'durable-sqlite'] as const;
|
|
167
|
-
export type Driver = (typeof drivers)[number];
|
|
168
|
-
const _: Driver = '' as TypeOf<typeof driver>;
|
|
169
|
-
|
|
170
|
-
export const wrapParam = (
|
|
171
|
-
name: string,
|
|
172
|
-
param: any | undefined,
|
|
173
|
-
optional: boolean = false,
|
|
174
|
-
type?: 'url' | 'secret',
|
|
175
|
-
) => {
|
|
176
|
-
const check = `[${chalk.green('✓')}]`;
|
|
177
|
-
const cross = `[${chalk.red('x')}]`;
|
|
178
|
-
if (typeof param === 'string') {
|
|
179
|
-
if (param.length === 0) {
|
|
180
|
-
return ` ${cross} ${name}: ''`;
|
|
181
|
-
}
|
|
182
|
-
if (type === 'secret') {
|
|
183
|
-
return ` ${check} ${name}: '*****'`;
|
|
184
|
-
} else if (type === 'url') {
|
|
185
|
-
return ` ${check} ${name}: '${param.replace(/(?<=:\/\/[^:\n]*:)([^@]*)/, '****')}'`;
|
|
186
|
-
}
|
|
187
|
-
return ` ${check} ${name}: '${param}'`;
|
|
188
|
-
}
|
|
189
|
-
if (optional) {
|
|
190
|
-
return chalk.gray(` ${name}?: `);
|
|
191
|
-
}
|
|
192
|
-
return ` ${cross} ${name}: ${chalk.gray('undefined')}`;
|
|
193
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { softAssertUnreachable } from 'src/global';
|
|
2
|
-
import { object, string, TypeOf } from 'zod';
|
|
3
|
-
import { error } from '../views';
|
|
4
|
-
import { wrapParam } from './common';
|
|
5
|
-
|
|
6
|
-
export const libSQLCredentials = object({
|
|
7
|
-
url: string().min(1),
|
|
8
|
-
authToken: string().min(1).optional(),
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
export type LibSQLCredentials = {
|
|
12
|
-
url: string;
|
|
13
|
-
authToken?: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const _: LibSQLCredentials = {} as TypeOf<typeof libSQLCredentials>;
|
|
17
|
-
|
|
18
|
-
export const printConfigConnectionIssues = (
|
|
19
|
-
options: Record<string, unknown>,
|
|
20
|
-
command: 'generate' | 'migrate' | 'push' | 'pull' | 'studio',
|
|
21
|
-
) => {
|
|
22
|
-
let text = `Please provide required params for 'turso' dialect:\n`;
|
|
23
|
-
console.log(error(text));
|
|
24
|
-
console.log(wrapParam('url', options.url));
|
|
25
|
-
console.log(wrapParam('authToken', options.authToken, true, 'secret'));
|
|
26
|
-
process.exit(1);
|
|
27
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { boolean, coerce, object, string, TypeOf, union } from 'zod';
|
|
2
|
-
import { error } from '../views';
|
|
3
|
-
import { wrapParam } from './common';
|
|
4
|
-
import { outputs } from './outputs';
|
|
5
|
-
|
|
6
|
-
export const mysqlCredentials = union([
|
|
7
|
-
object({
|
|
8
|
-
host: string().min(1),
|
|
9
|
-
port: coerce.number().min(1).optional(),
|
|
10
|
-
user: string().min(1).optional(),
|
|
11
|
-
password: string().min(1).optional(),
|
|
12
|
-
database: string().min(1),
|
|
13
|
-
ssl: union([
|
|
14
|
-
string(),
|
|
15
|
-
object({
|
|
16
|
-
pfx: string().optional(),
|
|
17
|
-
key: string().optional(),
|
|
18
|
-
passphrase: string().optional(),
|
|
19
|
-
cert: string().optional(),
|
|
20
|
-
ca: union([string(), string().array()]).optional(),
|
|
21
|
-
crl: union([string(), string().array()]).optional(),
|
|
22
|
-
ciphers: string().optional(),
|
|
23
|
-
rejectUnauthorized: boolean().optional(),
|
|
24
|
-
}),
|
|
25
|
-
]).optional(),
|
|
26
|
-
}),
|
|
27
|
-
object({
|
|
28
|
-
url: string().min(1),
|
|
29
|
-
}),
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
export type MysqlCredentials = TypeOf<typeof mysqlCredentials>;
|
|
33
|
-
|
|
34
|
-
export const printCliConnectionIssues = (options: any) => {
|
|
35
|
-
const { uri, host, database } = options || {};
|
|
36
|
-
|
|
37
|
-
if (!uri && (!host || !database)) {
|
|
38
|
-
console.log(outputs.mysql.connection.required());
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const printConfigConnectionIssues = (
|
|
43
|
-
options: Record<string, unknown>,
|
|
44
|
-
) => {
|
|
45
|
-
if ('url' in options) {
|
|
46
|
-
let text = `Please provide required params for MySQL driver:\n`;
|
|
47
|
-
console.log(error(text));
|
|
48
|
-
console.log(wrapParam('url', options.url, false, 'url'));
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let text = `Please provide required params for MySQL driver:\n`;
|
|
53
|
-
console.log(error(text));
|
|
54
|
-
console.log(wrapParam('host', options.host));
|
|
55
|
-
console.log(wrapParam('port', options.port, true));
|
|
56
|
-
console.log(wrapParam('user', options.user, true));
|
|
57
|
-
console.log(wrapParam('password', options.password, true, 'secret'));
|
|
58
|
-
console.log(wrapParam('database', options.database));
|
|
59
|
-
console.log(wrapParam('ssl', options.ssl, true));
|
|
60
|
-
process.exit(1);
|
|
61
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { sqliteDriversLiterals } from './common';
|
|
3
|
-
|
|
4
|
-
export const withStyle = {
|
|
5
|
-
error: (str: string) => `${chalk.red(`${chalk.white.bgRed(' Invalid input ')} ${str}`)}`,
|
|
6
|
-
warning: (str: string) => `${chalk.white.bgGray(' Warning ')} ${str}`,
|
|
7
|
-
errorWarning: (str: string) => `${chalk.red(`${chalk.white.bgRed(' Warning ')} ${str}`)}`,
|
|
8
|
-
fullWarning: (str: string) => `${chalk.black.bgYellow(' Warning ')} ${chalk.bold(str)}`,
|
|
9
|
-
suggestion: (str: string) => `${chalk.white.bgGray(' Suggestion ')} ${str}`,
|
|
10
|
-
info: (str: string) => `${chalk.grey(str)}`,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const outputs = {
|
|
14
|
-
studio: {
|
|
15
|
-
drivers: (param: string) =>
|
|
16
|
-
withStyle.error(
|
|
17
|
-
`"${param}" is not a valid driver. Available drivers: "pg", "mysql2", "better-sqlite", "libsql", "turso". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`,
|
|
18
|
-
),
|
|
19
|
-
noCredentials: () =>
|
|
20
|
-
withStyle.error(
|
|
21
|
-
`Please specify a 'dbCredentials' param in config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`,
|
|
22
|
-
),
|
|
23
|
-
noDriver: () =>
|
|
24
|
-
withStyle.error(
|
|
25
|
-
`Please specify a 'driver' param in config. It will help drizzle to know how to query you database. You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`,
|
|
26
|
-
),
|
|
27
|
-
noDialect: () =>
|
|
28
|
-
withStyle.error(
|
|
29
|
-
`Please specify 'dialect' param in config, either of 'postgresql', 'mysql', 'sqlite', turso or singlestore`,
|
|
30
|
-
),
|
|
31
|
-
},
|
|
32
|
-
common: {
|
|
33
|
-
ambiguousParams: (command: string) =>
|
|
34
|
-
withStyle.error(
|
|
35
|
-
`You can't use both --config and other cli options for ${command} command`,
|
|
36
|
-
),
|
|
37
|
-
schema: (command: string) => withStyle.error(`"--schema" is a required field for ${command} command`),
|
|
38
|
-
},
|
|
39
|
-
postgres: {
|
|
40
|
-
connection: {
|
|
41
|
-
required: () =>
|
|
42
|
-
withStyle.error(
|
|
43
|
-
`Either "url" or "host", "database" are required for database connection`,
|
|
44
|
-
),
|
|
45
|
-
awsDataApi: () =>
|
|
46
|
-
withStyle.error(
|
|
47
|
-
"You need to provide 'database', 'secretArn' and 'resourceArn' for Drizzle Kit to connect to AWS Data API",
|
|
48
|
-
),
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
mysql: {
|
|
52
|
-
connection: {
|
|
53
|
-
driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
|
|
54
|
-
required: () =>
|
|
55
|
-
withStyle.error(
|
|
56
|
-
`Either "url" or "host", "database" are required for database connection`,
|
|
57
|
-
),
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
sqlite: {
|
|
61
|
-
connection: {
|
|
62
|
-
driver: () => {
|
|
63
|
-
const listOfDrivers = sqliteDriversLiterals
|
|
64
|
-
.map((it) => `'${it.value}'`)
|
|
65
|
-
.join(', ');
|
|
66
|
-
return withStyle.error(
|
|
67
|
-
`Either ${listOfDrivers} are available options for 'driver' param`,
|
|
68
|
-
);
|
|
69
|
-
},
|
|
70
|
-
url: (driver: string) =>
|
|
71
|
-
withStyle.error(
|
|
72
|
-
`"url" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`,
|
|
73
|
-
),
|
|
74
|
-
authToken: (driver: string) =>
|
|
75
|
-
withStyle.error(
|
|
76
|
-
`"authToken" is a required option for driver "${driver}". You can read more about drizzle.config: https://orm.drizzle.team/kit-docs/config-reference`,
|
|
77
|
-
),
|
|
78
|
-
},
|
|
79
|
-
introspect: {},
|
|
80
|
-
push: {},
|
|
81
|
-
},
|
|
82
|
-
singlestore: {
|
|
83
|
-
connection: {
|
|
84
|
-
driver: () => withStyle.error(`Only "mysql2" is available options for "--driver"`),
|
|
85
|
-
required: () =>
|
|
86
|
-
withStyle.error(
|
|
87
|
-
`Either "url" or "host", "database" are required for database connection`,
|
|
88
|
-
),
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { boolean, coerce, literal, object, string, TypeOf, undefined, union } from 'zod';
|
|
2
|
-
import { error } from '../views';
|
|
3
|
-
import { wrapParam } from './common';
|
|
4
|
-
|
|
5
|
-
export const postgresCredentials = union([
|
|
6
|
-
object({
|
|
7
|
-
driver: undefined(),
|
|
8
|
-
host: string().min(1),
|
|
9
|
-
port: coerce.number().min(1).optional(),
|
|
10
|
-
user: string().min(1).optional(),
|
|
11
|
-
password: string().min(1).optional(),
|
|
12
|
-
database: string().min(1),
|
|
13
|
-
ssl: union([
|
|
14
|
-
literal('require'),
|
|
15
|
-
literal('allow'),
|
|
16
|
-
literal('prefer'),
|
|
17
|
-
literal('verify-full'),
|
|
18
|
-
boolean(),
|
|
19
|
-
object({}).passthrough(),
|
|
20
|
-
]).optional(),
|
|
21
|
-
}).transform((o) => {
|
|
22
|
-
delete o.driver;
|
|
23
|
-
return o as Omit<typeof o, 'driver'>;
|
|
24
|
-
}),
|
|
25
|
-
object({
|
|
26
|
-
driver: undefined(),
|
|
27
|
-
url: string().min(1),
|
|
28
|
-
}).transform<{ url: string }>((o) => {
|
|
29
|
-
delete o.driver;
|
|
30
|
-
return o;
|
|
31
|
-
}),
|
|
32
|
-
object({
|
|
33
|
-
driver: literal('aws-data-api'),
|
|
34
|
-
database: string().min(1),
|
|
35
|
-
secretArn: string().min(1),
|
|
36
|
-
resourceArn: string().min(1),
|
|
37
|
-
}),
|
|
38
|
-
object({
|
|
39
|
-
driver: literal('pglite'),
|
|
40
|
-
url: string().min(1),
|
|
41
|
-
}),
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
export type PostgresCredentials = TypeOf<typeof postgresCredentials>;
|
|
45
|
-
|
|
46
|
-
export const printConfigConnectionIssues = (
|
|
47
|
-
options: Record<string, unknown>,
|
|
48
|
-
) => {
|
|
49
|
-
if (options.driver === 'aws-data-api') {
|
|
50
|
-
let text = `Please provide required params for AWS Data API driver:\n`;
|
|
51
|
-
console.log(error(text));
|
|
52
|
-
console.log(wrapParam('database', options.database));
|
|
53
|
-
console.log(wrapParam('secretArn', options.secretArn, false, 'secret'));
|
|
54
|
-
console.log(wrapParam('resourceArn', options.resourceArn, false, 'secret'));
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if ('url' in options) {
|
|
59
|
-
let text = `Please provide required params for Postgres driver:\n`;
|
|
60
|
-
console.log(error(text));
|
|
61
|
-
console.log(wrapParam('url', options.url, false, 'url'));
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if ('host' in options || 'database' in options) {
|
|
66
|
-
let text = `Please provide required params for Postgres driver:\n`;
|
|
67
|
-
console.log(error(text));
|
|
68
|
-
console.log(wrapParam('host', options.host));
|
|
69
|
-
console.log(wrapParam('port', options.port, true));
|
|
70
|
-
console.log(wrapParam('user', options.user, true));
|
|
71
|
-
console.log(wrapParam('password', options.password, true, 'secret'));
|
|
72
|
-
console.log(wrapParam('database', options.database));
|
|
73
|
-
console.log(wrapParam('ssl', options.ssl, true));
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
console.log(
|
|
78
|
-
error(
|
|
79
|
-
`Either connection "url" or "host", "database" are required for PostgreSQL database connection`,
|
|
80
|
-
),
|
|
81
|
-
);
|
|
82
|
-
process.exit(1);
|
|
83
|
-
};
|