@anthonyalayo/drizzle-kit 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +25 -0
- package/README.md +79 -0
- package/build.dev.ts +51 -0
- package/build.ts +112 -0
- package/imports-checker/analyze.ts +78 -0
- package/imports-checker/checker.ts +296 -0
- package/imports-checker/grammar/grammar.ohm +121 -0
- package/imports-checker/grammar/grammar.ohm-bundle.d.ts +164 -0
- package/imports-checker/grammar/grammar.ohm-bundle.js +753 -0
- package/imports-checker/index.ts +48 -0
- package/package.json +142 -0
- package/patches/difflib@0.2.4.patch +31 -0
- package/src/@types/utils.ts +58 -0
- package/src/api.ts +504 -0
- package/src/cli/commands/_es5.ts +2 -0
- package/src/cli/commands/check.ts +52 -0
- package/src/cli/commands/drop.ts +60 -0
- package/src/cli/commands/introspect.ts +772 -0
- package/src/cli/commands/libSqlPushUtils.ts +355 -0
- package/src/cli/commands/migrate.ts +1526 -0
- package/src/cli/commands/mysqlIntrospect.ts +53 -0
- package/src/cli/commands/mysqlPushUtils.ts +352 -0
- package/src/cli/commands/mysqlUp.ts +102 -0
- package/src/cli/commands/pgIntrospect.ts +55 -0
- package/src/cli/commands/pgPushUtils.ts +269 -0
- package/src/cli/commands/pgUp.ts +217 -0
- package/src/cli/commands/push.ts +637 -0
- package/src/cli/commands/singlestoreIntrospect.ts +53 -0
- package/src/cli/commands/singlestorePushUtils.ts +456 -0
- package/src/cli/commands/singlestoreUp.ts +1 -0
- package/src/cli/commands/sqliteIntrospect.ts +96 -0
- package/src/cli/commands/sqlitePushUtils.ts +322 -0
- package/src/cli/commands/sqliteUp.ts +52 -0
- package/src/cli/commands/utils.ts +858 -0
- package/src/cli/connections.ts +914 -0
- package/src/cli/index.ts +48 -0
- package/src/cli/schema.ts +794 -0
- package/src/cli/selector-ui.ts +38 -0
- package/src/cli/utils.ts +112 -0
- package/src/cli/validations/cli.ts +79 -0
- package/src/cli/validations/common.ts +193 -0
- package/src/cli/validations/libsql.ts +27 -0
- package/src/cli/validations/mysql.ts +61 -0
- package/src/cli/validations/outputs.ts +91 -0
- package/src/cli/validations/postgres.ts +83 -0
- package/src/cli/validations/singlestore.ts +61 -0
- package/src/cli/validations/sqlite.ts +104 -0
- package/src/cli/validations/studio.ts +24 -0
- package/src/cli/views.ts +658 -0
- package/src/extensions/getTablesFilterByExtensions.ts +16 -0
- package/src/extensions/vector.ts +10 -0
- package/src/global.ts +61 -0
- package/src/index.ts +326 -0
- package/src/introspect-mysql.ts +1030 -0
- package/src/introspect-pg.ts +1435 -0
- package/src/introspect-singlestore.ts +913 -0
- package/src/introspect-sqlite.ts +533 -0
- package/src/jsonDiffer.js +882 -0
- package/src/jsonStatements.ts +3590 -0
- package/src/loader.mjs +57 -0
- package/src/migrationPreparator.ts +217 -0
- package/src/schemaValidator.ts +23 -0
- package/src/serializer/index.ts +142 -0
- package/src/serializer/mysqlImports.ts +38 -0
- package/src/serializer/mysqlSchema.ts +423 -0
- package/src/serializer/mysqlSerializer.ts +999 -0
- package/src/serializer/pgImports.ts +106 -0
- package/src/serializer/pgSchema.ts +937 -0
- package/src/serializer/pgSerializer.ts +2223 -0
- package/src/serializer/singlestoreImports.ts +38 -0
- package/src/serializer/singlestoreSchema.ts +257 -0
- package/src/serializer/singlestoreSerializer.ts +767 -0
- package/src/serializer/sqliteImports.ts +41 -0
- package/src/serializer/sqliteSchema.ts +352 -0
- package/src/serializer/sqliteSerializer.ts +931 -0
- package/src/serializer/studio.ts +694 -0
- package/src/serializer/utils.ts +45 -0
- package/src/simulator.ts +157 -0
- package/src/snapshotsDiffer.ts +4398 -0
- package/src/sqlgenerator.ts +4212 -0
- package/src/statementCombiner.ts +597 -0
- package/src/utils/certs.ts +44 -0
- package/src/utils/words.ts +1333 -0
- package/src/utils.ts +370 -0
- package/tests/bin.test.ts +58 -0
- package/tests/cli/d1http.config.ts +12 -0
- package/tests/cli/drizzle.config.ts +9 -0
- package/tests/cli/durable-sqlite.config.ts +7 -0
- package/tests/cli/expo.config.ts +7 -0
- package/tests/cli/postgres.config.ts +13 -0
- package/tests/cli/postgres2.config.ts +17 -0
- package/tests/cli/schema.ts +1 -0
- package/tests/cli/turso.config.ts +10 -0
- package/tests/cli-export.test.ts +79 -0
- package/tests/cli-generate.test.ts +259 -0
- package/tests/cli-migrate.test.ts +103 -0
- package/tests/cli-push.test.ts +126 -0
- package/tests/common.ts +15 -0
- package/tests/indexes/common.ts +21 -0
- package/tests/indexes/pg.test.ts +245 -0
- package/tests/introspect/libsql.test.ts +35 -0
- package/tests/introspect/mysql.test.ts +319 -0
- package/tests/introspect/pg.test.ts +894 -0
- package/tests/introspect/singlestore.test.ts +275 -0
- package/tests/introspect/sqlite.test.ts +122 -0
- package/tests/libsql-checks.test.ts +308 -0
- package/tests/libsql-statements.test.ts +989 -0
- package/tests/libsql-views.test.ts +218 -0
- package/tests/migrate/libsq-schema.ts +6 -0
- package/tests/migrate/libsql-migrate.test.ts +58 -0
- package/tests/migrate/migrations/0000_little_blizzard.sql +4 -0
- package/tests/migrate/migrations/0001_nebulous_storm.sql +10 -0
- package/tests/migrate/migrations/meta/0000_snapshot.json +40 -0
- package/tests/migrate/migrations/meta/0001_snapshot.json +40 -0
- package/tests/migrate/migrations/meta/_journal.json +20 -0
- package/tests/mysql-checks.test.ts +291 -0
- package/tests/mysql-generated.test.ts +1290 -0
- package/tests/mysql-schemas.test.ts +156 -0
- package/tests/mysql-views.test.ts +553 -0
- package/tests/mysql.test.ts +863 -0
- package/tests/pg-array.test.ts +368 -0
- package/tests/pg-checks.test.ts +329 -0
- package/tests/pg-columns.test.ts +484 -0
- package/tests/pg-domains.test.ts +306 -0
- package/tests/pg-enums.test.ts +751 -0
- package/tests/pg-generated.test.ts +529 -0
- package/tests/pg-identity.test.ts +447 -0
- package/tests/pg-schemas.test.ts +105 -0
- package/tests/pg-sequences.test.ts +298 -0
- package/tests/pg-tables.test.ts +1021 -0
- package/tests/pg-views.test.ts +1929 -0
- package/tests/push/common.ts +58 -0
- package/tests/push/libsql.test.ts +1400 -0
- package/tests/push/mysql-push.test.ts +345 -0
- package/tests/push/mysql.test.ts +788 -0
- package/tests/push/pg.test.ts +4341 -0
- package/tests/push/singlestore-push.test.ts +894 -0
- package/tests/push/singlestore.test.ts +444 -0
- package/tests/push/sqlite.test.ts +1613 -0
- package/tests/rls/pg-policy.test.ts +1656 -0
- package/tests/rls/pg-role.test.ts +234 -0
- package/tests/schemaDiffer.ts +2852 -0
- package/tests/singlestore-generated.test.ts +1290 -0
- package/tests/singlestore-schemas.test.ts +155 -0
- package/tests/singlestore.test.ts +978 -0
- package/tests/sqlite-checks.test.ts +308 -0
- package/tests/sqlite-columns.test.ts +1049 -0
- package/tests/sqlite-generated.test.ts +1726 -0
- package/tests/sqlite-tables.test.ts +637 -0
- package/tests/sqlite-views.test.ts +218 -0
- package/tests/statements-combiner/libsql-statements-combiner.test.ts +1812 -0
- package/tests/statements-combiner/singlestore-statements-combiner.test.ts +882 -0
- package/tests/statements-combiner/sqlite-statements-combiner.test.ts +1211 -0
- package/tests/test/sqlite.test.ts +39 -0
- package/tests/testsinglestore.ts +29 -0
- package/tests/validations.test.ts +869 -0
- package/tests/wrap-param.test.ts +16 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.cli-types.json +9 -0
- package/tsconfig.json +28 -0
- package/vitest.config.ts +34 -0
|
@@ -0,0 +1,61 @@
|
|
|
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 singlestoreCredentials = 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 SingleStoreCredentials = TypeOf<typeof singlestoreCredentials>;
|
|
33
|
+
|
|
34
|
+
export const printCliConnectionIssues = (options: any) => {
|
|
35
|
+
const { uri, host, database } = options || {};
|
|
36
|
+
|
|
37
|
+
if (!uri && (!host || !database)) {
|
|
38
|
+
console.log(outputs.singlestore.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 SingleStore 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 SingleStore 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
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { softAssertUnreachable } from 'src/global';
|
|
2
|
+
import { literal, object, string, TypeOf, undefined, union } from 'zod';
|
|
3
|
+
import { error } from '../views';
|
|
4
|
+
import { sqliteDriver, wrapParam } from './common';
|
|
5
|
+
|
|
6
|
+
export const sqliteCredentials = union([
|
|
7
|
+
object({
|
|
8
|
+
driver: literal('turso'),
|
|
9
|
+
url: string().min(1),
|
|
10
|
+
authToken: string().min(1).optional(),
|
|
11
|
+
}),
|
|
12
|
+
object({
|
|
13
|
+
driver: literal('d1-http'),
|
|
14
|
+
accountId: string().min(1),
|
|
15
|
+
databaseId: string().min(1),
|
|
16
|
+
token: string().min(1),
|
|
17
|
+
}),
|
|
18
|
+
object({
|
|
19
|
+
driver: undefined(),
|
|
20
|
+
url: string().min(1),
|
|
21
|
+
}).transform<{ url: string }>((o) => {
|
|
22
|
+
delete o.driver;
|
|
23
|
+
return o;
|
|
24
|
+
}),
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
export type SqliteCredentials =
|
|
28
|
+
| {
|
|
29
|
+
driver: 'd1-http';
|
|
30
|
+
accountId: string;
|
|
31
|
+
databaseId: string;
|
|
32
|
+
token: string;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
url: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const _: SqliteCredentials = {} as TypeOf<typeof sqliteCredentials>;
|
|
39
|
+
|
|
40
|
+
export const printConfigConnectionIssues = (
|
|
41
|
+
options: Record<string, unknown>,
|
|
42
|
+
command: 'generate' | 'migrate' | 'push' | 'pull' | 'studio',
|
|
43
|
+
) => {
|
|
44
|
+
const parsedDriver = sqliteDriver.safeParse(options.driver);
|
|
45
|
+
const driver = parsedDriver.success ? parsedDriver.data : ('' as never);
|
|
46
|
+
|
|
47
|
+
if (driver === 'expo') {
|
|
48
|
+
if (command === 'migrate') {
|
|
49
|
+
console.log(
|
|
50
|
+
error(
|
|
51
|
+
`You can't use 'migrate' command with Expo SQLite, please follow migration instructions in our docs - https://orm.drizzle.team/docs/get-started-sqlite#expo-sqlite`,
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
} else if (command === 'studio') {
|
|
55
|
+
console.log(
|
|
56
|
+
error(
|
|
57
|
+
`You can't use 'studio' command with Expo SQLite, please use Expo Plugin https://www.npmjs.com/package/expo-drizzle-studio-plugin`,
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
} else if (command === 'pull') {
|
|
61
|
+
console.log(error("You can't use 'pull' command with Expo SQLite"));
|
|
62
|
+
} else if (command === 'push') {
|
|
63
|
+
console.log(error("You can't use 'push' command with Expo SQLite"));
|
|
64
|
+
} else {
|
|
65
|
+
console.log(error('Unexpected error with expo driver 🤔'));
|
|
66
|
+
}
|
|
67
|
+
process.exit(1);
|
|
68
|
+
} else if (driver === 'd1-http') {
|
|
69
|
+
let text = `Please provide required params for D1 HTTP driver:\n`;
|
|
70
|
+
console.log(error(text));
|
|
71
|
+
console.log(wrapParam('accountId', options.accountId));
|
|
72
|
+
console.log(wrapParam('databaseId', options.databaseId));
|
|
73
|
+
console.log(wrapParam('token', options.token, false, 'secret'));
|
|
74
|
+
process.exit(1);
|
|
75
|
+
} else if (driver === 'durable-sqlite') {
|
|
76
|
+
if (command === 'migrate') {
|
|
77
|
+
console.log(
|
|
78
|
+
error(
|
|
79
|
+
`You can't use 'migrate' command with SQLite Durable Objects`,
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
} else if (command === 'studio') {
|
|
83
|
+
console.log(
|
|
84
|
+
error(
|
|
85
|
+
`You can't use 'migrate' command with SQLite Durable Objects`,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
} else if (command === 'pull') {
|
|
89
|
+
console.log(error("You can't use 'pull' command with SQLite Durable Objects"));
|
|
90
|
+
} else if (command === 'push') {
|
|
91
|
+
console.log(error("You can't use 'push' command with SQLite Durable Objects"));
|
|
92
|
+
} else {
|
|
93
|
+
console.log(error('Unexpected error with SQLite Durable Object driver 🤔'));
|
|
94
|
+
}
|
|
95
|
+
process.exit(1);
|
|
96
|
+
} else {
|
|
97
|
+
softAssertUnreachable(driver);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let text = `Please provide required params:\n`;
|
|
101
|
+
console.log(error(text));
|
|
102
|
+
console.log(wrapParam('url', options.url));
|
|
103
|
+
process.exit(1);
|
|
104
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { coerce, intersection, object, string, TypeOf, union } from 'zod';
|
|
2
|
+
import { dialect } from '../../schemaValidator';
|
|
3
|
+
import { mysqlCredentials } from './mysql';
|
|
4
|
+
import { postgresCredentials } from './postgres';
|
|
5
|
+
import { sqliteCredentials } from './sqlite';
|
|
6
|
+
|
|
7
|
+
export const credentials = intersection(
|
|
8
|
+
postgresCredentials,
|
|
9
|
+
mysqlCredentials,
|
|
10
|
+
sqliteCredentials,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export type Credentials = TypeOf<typeof credentials>;
|
|
14
|
+
|
|
15
|
+
export const studioCliParams = object({
|
|
16
|
+
port: coerce.number().optional().default(4983),
|
|
17
|
+
host: string().optional().default('127.0.0.1'),
|
|
18
|
+
config: string().optional(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const studioConfig = object({
|
|
22
|
+
dialect,
|
|
23
|
+
schema: union([string(), string().array()]).optional(),
|
|
24
|
+
});
|