@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/schema.ts
DELETED
|
@@ -1,794 +0,0 @@
|
|
|
1
|
-
import { boolean, command, number, string } from '@drizzle-team/brocli';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import 'dotenv/config';
|
|
4
|
-
import { mkdirSync } from 'fs';
|
|
5
|
-
import { renderWithTask } from 'hanji';
|
|
6
|
-
import { dialects } from 'src/schemaValidator';
|
|
7
|
-
import '../@types/utils';
|
|
8
|
-
import { assertUnreachable } from '../global';
|
|
9
|
-
import { type Setup } from '../serializer/studio';
|
|
10
|
-
import { assertV1OutFolder } from '../utils';
|
|
11
|
-
import { certs } from '../utils/certs';
|
|
12
|
-
import { checkHandler } from './commands/check';
|
|
13
|
-
import { dropMigration } from './commands/drop';
|
|
14
|
-
import { upMysqlHandler } from './commands/mysqlUp';
|
|
15
|
-
import { upPgHandler } from './commands/pgUp';
|
|
16
|
-
import { upSinglestoreHandler } from './commands/singlestoreUp';
|
|
17
|
-
import { upSqliteHandler } from './commands/sqliteUp';
|
|
18
|
-
import {
|
|
19
|
-
prepareCheckParams,
|
|
20
|
-
prepareDropParams,
|
|
21
|
-
prepareExportConfig,
|
|
22
|
-
prepareGenerateConfig,
|
|
23
|
-
prepareMigrateConfig,
|
|
24
|
-
preparePullConfig,
|
|
25
|
-
preparePushConfig,
|
|
26
|
-
prepareStudioConfig,
|
|
27
|
-
} from './commands/utils';
|
|
28
|
-
import { assertOrmCoreVersion, assertPackages, assertStudioNodeVersion, ormVersionGt } from './utils';
|
|
29
|
-
import { assertCollisions, drivers, prefixes } from './validations/common';
|
|
30
|
-
import { withStyle } from './validations/outputs';
|
|
31
|
-
import { grey, MigrateProgress } from './views';
|
|
32
|
-
|
|
33
|
-
const optionDialect = string('dialect')
|
|
34
|
-
.enum(...dialects)
|
|
35
|
-
.desc(
|
|
36
|
-
`Database dialect: 'postgresql', 'mysql', 'sqlite', 'turso' or 'singlestore'`,
|
|
37
|
-
);
|
|
38
|
-
const optionOut = string().desc("Output folder, 'drizzle' by default");
|
|
39
|
-
const optionConfig = string().desc('Path to drizzle config file');
|
|
40
|
-
const optionBreakpoints = boolean().desc(
|
|
41
|
-
`Prepare SQL statements with breakpoints`,
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const optionDriver = string()
|
|
45
|
-
.enum(...drivers)
|
|
46
|
-
.desc('Database driver');
|
|
47
|
-
|
|
48
|
-
const optionCasing = string().enum('camelCase', 'snake_case').desc('Casing for serialization');
|
|
49
|
-
|
|
50
|
-
export const generate = command({
|
|
51
|
-
name: 'generate',
|
|
52
|
-
options: {
|
|
53
|
-
config: optionConfig,
|
|
54
|
-
dialect: optionDialect,
|
|
55
|
-
driver: optionDriver,
|
|
56
|
-
casing: optionCasing,
|
|
57
|
-
schema: string().desc('Path to a schema file or folder'),
|
|
58
|
-
out: optionOut,
|
|
59
|
-
name: string().desc('Migration file name'),
|
|
60
|
-
breakpoints: optionBreakpoints,
|
|
61
|
-
custom: boolean()
|
|
62
|
-
.desc('Prepare empty migration file for custom SQL')
|
|
63
|
-
.default(false),
|
|
64
|
-
prefix: string()
|
|
65
|
-
.enum(...prefixes)
|
|
66
|
-
.default('index'),
|
|
67
|
-
},
|
|
68
|
-
transform: async (opts) => {
|
|
69
|
-
const from = assertCollisions(
|
|
70
|
-
'generate',
|
|
71
|
-
opts,
|
|
72
|
-
['prefix', 'name', 'custom'],
|
|
73
|
-
['driver', 'breakpoints', 'schema', 'out', 'dialect', 'casing'],
|
|
74
|
-
);
|
|
75
|
-
return prepareGenerateConfig(opts, from);
|
|
76
|
-
},
|
|
77
|
-
handler: async (opts) => {
|
|
78
|
-
await assertOrmCoreVersion();
|
|
79
|
-
await assertPackages('drizzle-orm');
|
|
80
|
-
|
|
81
|
-
// const parsed = cliConfigGenerate.parse(opts);
|
|
82
|
-
|
|
83
|
-
const {
|
|
84
|
-
prepareAndMigratePg,
|
|
85
|
-
prepareAndMigrateMysql,
|
|
86
|
-
prepareAndMigrateSqlite,
|
|
87
|
-
prepareAndMigrateLibSQL,
|
|
88
|
-
prepareAndMigrateSingleStore,
|
|
89
|
-
} = await import('./commands/migrate');
|
|
90
|
-
|
|
91
|
-
const dialect = opts.dialect;
|
|
92
|
-
if (dialect === 'postgresql') {
|
|
93
|
-
await prepareAndMigratePg(opts);
|
|
94
|
-
} else if (dialect === 'mysql') {
|
|
95
|
-
await prepareAndMigrateMysql(opts);
|
|
96
|
-
} else if (dialect === 'sqlite') {
|
|
97
|
-
await prepareAndMigrateSqlite(opts);
|
|
98
|
-
} else if (dialect === 'turso') {
|
|
99
|
-
await prepareAndMigrateLibSQL(opts);
|
|
100
|
-
} else if (dialect === 'singlestore') {
|
|
101
|
-
await prepareAndMigrateSingleStore(opts);
|
|
102
|
-
} else {
|
|
103
|
-
assertUnreachable(dialect);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
export const migrate = command({
|
|
109
|
-
name: 'migrate',
|
|
110
|
-
options: {
|
|
111
|
-
config: optionConfig,
|
|
112
|
-
},
|
|
113
|
-
transform: async (opts) => {
|
|
114
|
-
return await prepareMigrateConfig(opts.config);
|
|
115
|
-
},
|
|
116
|
-
handler: async (opts) => {
|
|
117
|
-
await assertOrmCoreVersion();
|
|
118
|
-
await assertPackages('drizzle-orm');
|
|
119
|
-
|
|
120
|
-
const { dialect, schema, table, out, credentials } = opts;
|
|
121
|
-
try {
|
|
122
|
-
if (dialect === 'postgresql') {
|
|
123
|
-
if ('driver' in credentials) {
|
|
124
|
-
const { driver } = credentials;
|
|
125
|
-
if (driver === 'aws-data-api') {
|
|
126
|
-
if (!(await ormVersionGt('0.30.10'))) {
|
|
127
|
-
console.log(
|
|
128
|
-
"To use 'aws-data-api' driver - please update drizzle-orm to the latest version",
|
|
129
|
-
);
|
|
130
|
-
process.exit(1);
|
|
131
|
-
}
|
|
132
|
-
} else if (driver === 'pglite') {
|
|
133
|
-
if (!(await ormVersionGt('0.30.6'))) {
|
|
134
|
-
console.log(
|
|
135
|
-
"To use 'pglite' driver - please update drizzle-orm to the latest version",
|
|
136
|
-
);
|
|
137
|
-
process.exit(1);
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
assertUnreachable(driver);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const { preparePostgresDB } = await import('./connections');
|
|
144
|
-
const { migrate } = await preparePostgresDB(credentials);
|
|
145
|
-
await renderWithTask(
|
|
146
|
-
new MigrateProgress(),
|
|
147
|
-
migrate({
|
|
148
|
-
migrationsFolder: out,
|
|
149
|
-
migrationsTable: table,
|
|
150
|
-
migrationsSchema: schema,
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
153
|
-
} else if (dialect === 'mysql') {
|
|
154
|
-
const { connectToMySQL } = await import('./connections');
|
|
155
|
-
const { migrate } = await connectToMySQL(credentials);
|
|
156
|
-
await renderWithTask(
|
|
157
|
-
new MigrateProgress(),
|
|
158
|
-
migrate({
|
|
159
|
-
migrationsFolder: out,
|
|
160
|
-
migrationsTable: table,
|
|
161
|
-
migrationsSchema: schema,
|
|
162
|
-
}),
|
|
163
|
-
);
|
|
164
|
-
} else if (dialect === 'singlestore') {
|
|
165
|
-
const { connectToSingleStore } = await import('./connections');
|
|
166
|
-
const { migrate } = await connectToSingleStore(credentials);
|
|
167
|
-
await renderWithTask(
|
|
168
|
-
new MigrateProgress(),
|
|
169
|
-
migrate({
|
|
170
|
-
migrationsFolder: out,
|
|
171
|
-
migrationsTable: table,
|
|
172
|
-
migrationsSchema: schema,
|
|
173
|
-
}),
|
|
174
|
-
);
|
|
175
|
-
} else if (dialect === 'sqlite') {
|
|
176
|
-
const { connectToSQLite } = await import('./connections');
|
|
177
|
-
const { migrate } = await connectToSQLite(credentials);
|
|
178
|
-
await renderWithTask(
|
|
179
|
-
new MigrateProgress(),
|
|
180
|
-
migrate({
|
|
181
|
-
migrationsFolder: opts.out,
|
|
182
|
-
migrationsTable: table,
|
|
183
|
-
migrationsSchema: schema,
|
|
184
|
-
}),
|
|
185
|
-
);
|
|
186
|
-
} else if (dialect === 'turso') {
|
|
187
|
-
const { connectToLibSQL } = await import('./connections');
|
|
188
|
-
const { migrate } = await connectToLibSQL(credentials);
|
|
189
|
-
await renderWithTask(
|
|
190
|
-
new MigrateProgress(),
|
|
191
|
-
migrate({
|
|
192
|
-
migrationsFolder: opts.out,
|
|
193
|
-
migrationsTable: table,
|
|
194
|
-
migrationsSchema: schema,
|
|
195
|
-
}),
|
|
196
|
-
);
|
|
197
|
-
} else {
|
|
198
|
-
assertUnreachable(dialect);
|
|
199
|
-
}
|
|
200
|
-
} catch (e) {
|
|
201
|
-
console.error(e);
|
|
202
|
-
process.exit(1);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
process.exit(0);
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
const optionsFilters = {
|
|
210
|
-
tablesFilter: string().desc('Table name filters'),
|
|
211
|
-
schemaFilters: string().desc('Schema name filters'),
|
|
212
|
-
extensionsFilters: string().desc(
|
|
213
|
-
'`Database extensions internal database filters',
|
|
214
|
-
),
|
|
215
|
-
} as const;
|
|
216
|
-
|
|
217
|
-
const optionsDatabaseCredentials = {
|
|
218
|
-
url: string().desc('Database connection URL'),
|
|
219
|
-
host: string().desc('Database host'),
|
|
220
|
-
port: string().desc('Database port'),
|
|
221
|
-
user: string().desc('Database user'),
|
|
222
|
-
password: string().desc('Database password'),
|
|
223
|
-
database: string().desc('Database name'),
|
|
224
|
-
ssl: string().desc('ssl mode'),
|
|
225
|
-
// Turso
|
|
226
|
-
authToken: string('auth-token').desc('Database auth token [Turso]'),
|
|
227
|
-
// specific cases
|
|
228
|
-
driver: optionDriver,
|
|
229
|
-
} as const;
|
|
230
|
-
|
|
231
|
-
export const push = command({
|
|
232
|
-
name: 'push',
|
|
233
|
-
options: {
|
|
234
|
-
config: optionConfig,
|
|
235
|
-
dialect: optionDialect,
|
|
236
|
-
casing: optionCasing,
|
|
237
|
-
schema: string().desc('Path to a schema file or folder'),
|
|
238
|
-
...optionsFilters,
|
|
239
|
-
...optionsDatabaseCredentials,
|
|
240
|
-
verbose: boolean()
|
|
241
|
-
.desc('Print all statements for each push')
|
|
242
|
-
.default(false),
|
|
243
|
-
strict: boolean().desc('Always ask for confirmation').default(false),
|
|
244
|
-
force: boolean()
|
|
245
|
-
.desc(
|
|
246
|
-
'Auto-approve all data loss statements. Note: Data loss statements may truncate your tables and data',
|
|
247
|
-
)
|
|
248
|
-
.default(false),
|
|
249
|
-
},
|
|
250
|
-
transform: async (opts) => {
|
|
251
|
-
const from = assertCollisions(
|
|
252
|
-
'push',
|
|
253
|
-
opts,
|
|
254
|
-
['force', 'verbose', 'strict'],
|
|
255
|
-
[
|
|
256
|
-
'schema',
|
|
257
|
-
'dialect',
|
|
258
|
-
'driver',
|
|
259
|
-
'url',
|
|
260
|
-
'host',
|
|
261
|
-
'port',
|
|
262
|
-
'user',
|
|
263
|
-
'password',
|
|
264
|
-
'database',
|
|
265
|
-
'ssl',
|
|
266
|
-
'authToken',
|
|
267
|
-
'schemaFilters',
|
|
268
|
-
'extensionsFilters',
|
|
269
|
-
'tablesFilter',
|
|
270
|
-
'casing',
|
|
271
|
-
],
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
return preparePushConfig(opts, from);
|
|
275
|
-
},
|
|
276
|
-
handler: async (config) => {
|
|
277
|
-
await assertPackages('drizzle-orm');
|
|
278
|
-
await assertOrmCoreVersion();
|
|
279
|
-
|
|
280
|
-
const {
|
|
281
|
-
dialect,
|
|
282
|
-
schemaPath,
|
|
283
|
-
strict,
|
|
284
|
-
verbose,
|
|
285
|
-
credentials,
|
|
286
|
-
tablesFilter,
|
|
287
|
-
schemasFilter,
|
|
288
|
-
force,
|
|
289
|
-
casing,
|
|
290
|
-
entities,
|
|
291
|
-
} = config;
|
|
292
|
-
|
|
293
|
-
try {
|
|
294
|
-
if (dialect === 'mysql') {
|
|
295
|
-
const { mysqlPush } = await import('./commands/push');
|
|
296
|
-
await mysqlPush(
|
|
297
|
-
schemaPath,
|
|
298
|
-
credentials,
|
|
299
|
-
tablesFilter,
|
|
300
|
-
strict,
|
|
301
|
-
verbose,
|
|
302
|
-
force,
|
|
303
|
-
casing,
|
|
304
|
-
);
|
|
305
|
-
} else if (dialect === 'postgresql') {
|
|
306
|
-
if ('driver' in credentials) {
|
|
307
|
-
const { driver } = credentials;
|
|
308
|
-
if (driver === 'aws-data-api') {
|
|
309
|
-
if (!(await ormVersionGt('0.30.10'))) {
|
|
310
|
-
console.log(
|
|
311
|
-
"To use 'aws-data-api' driver - please update drizzle-orm to the latest version",
|
|
312
|
-
);
|
|
313
|
-
process.exit(1);
|
|
314
|
-
}
|
|
315
|
-
} else if (driver === 'pglite') {
|
|
316
|
-
if (!(await ormVersionGt('0.30.6'))) {
|
|
317
|
-
console.log(
|
|
318
|
-
"To use 'pglite' driver - please update drizzle-orm to the latest version",
|
|
319
|
-
);
|
|
320
|
-
process.exit(1);
|
|
321
|
-
}
|
|
322
|
-
} else {
|
|
323
|
-
assertUnreachable(driver);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const { pgPush } = await import('./commands/push');
|
|
328
|
-
await pgPush(
|
|
329
|
-
schemaPath,
|
|
330
|
-
verbose,
|
|
331
|
-
strict,
|
|
332
|
-
credentials,
|
|
333
|
-
tablesFilter,
|
|
334
|
-
schemasFilter,
|
|
335
|
-
entities,
|
|
336
|
-
force,
|
|
337
|
-
casing,
|
|
338
|
-
);
|
|
339
|
-
} else if (dialect === 'sqlite') {
|
|
340
|
-
const { sqlitePush } = await import('./commands/push');
|
|
341
|
-
await sqlitePush(
|
|
342
|
-
schemaPath,
|
|
343
|
-
verbose,
|
|
344
|
-
strict,
|
|
345
|
-
credentials,
|
|
346
|
-
tablesFilter,
|
|
347
|
-
force,
|
|
348
|
-
casing,
|
|
349
|
-
);
|
|
350
|
-
} else if (dialect === 'turso') {
|
|
351
|
-
const { libSQLPush } = await import('./commands/push');
|
|
352
|
-
await libSQLPush(
|
|
353
|
-
schemaPath,
|
|
354
|
-
verbose,
|
|
355
|
-
strict,
|
|
356
|
-
credentials,
|
|
357
|
-
tablesFilter,
|
|
358
|
-
force,
|
|
359
|
-
casing,
|
|
360
|
-
);
|
|
361
|
-
} else if (dialect === 'singlestore') {
|
|
362
|
-
const { singlestorePush } = await import('./commands/push');
|
|
363
|
-
await singlestorePush(
|
|
364
|
-
schemaPath,
|
|
365
|
-
credentials,
|
|
366
|
-
tablesFilter,
|
|
367
|
-
strict,
|
|
368
|
-
verbose,
|
|
369
|
-
force,
|
|
370
|
-
casing,
|
|
371
|
-
);
|
|
372
|
-
} else {
|
|
373
|
-
assertUnreachable(dialect);
|
|
374
|
-
}
|
|
375
|
-
} catch (e) {
|
|
376
|
-
console.error(e);
|
|
377
|
-
}
|
|
378
|
-
process.exit(0);
|
|
379
|
-
},
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
export const check = command({
|
|
383
|
-
name: 'check',
|
|
384
|
-
options: {
|
|
385
|
-
config: optionConfig,
|
|
386
|
-
dialect: optionDialect,
|
|
387
|
-
out: optionOut,
|
|
388
|
-
},
|
|
389
|
-
transform: async (opts) => {
|
|
390
|
-
const from = assertCollisions('check', opts, [], ['dialect', 'out']);
|
|
391
|
-
return prepareCheckParams(opts, from);
|
|
392
|
-
},
|
|
393
|
-
handler: async (config) => {
|
|
394
|
-
await assertOrmCoreVersion();
|
|
395
|
-
|
|
396
|
-
const { out, dialect } = config;
|
|
397
|
-
checkHandler(out, dialect);
|
|
398
|
-
console.log("Everything's fine 🐶🔥");
|
|
399
|
-
},
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
export const up = command({
|
|
403
|
-
name: 'up',
|
|
404
|
-
options: {
|
|
405
|
-
config: optionConfig,
|
|
406
|
-
dialect: optionDialect,
|
|
407
|
-
out: optionOut,
|
|
408
|
-
},
|
|
409
|
-
transform: async (opts) => {
|
|
410
|
-
const from = assertCollisions('check', opts, [], ['dialect', 'out']);
|
|
411
|
-
return prepareCheckParams(opts, from);
|
|
412
|
-
},
|
|
413
|
-
handler: async (config) => {
|
|
414
|
-
await assertOrmCoreVersion();
|
|
415
|
-
|
|
416
|
-
const { out, dialect } = config;
|
|
417
|
-
await assertPackages('drizzle-orm');
|
|
418
|
-
|
|
419
|
-
if (dialect === 'postgresql') {
|
|
420
|
-
upPgHandler(out);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
if (dialect === 'mysql') {
|
|
424
|
-
upMysqlHandler(out);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (dialect === 'sqlite' || dialect === 'turso') {
|
|
428
|
-
upSqliteHandler(out);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
if (dialect === 'singlestore') {
|
|
432
|
-
upSinglestoreHandler(out);
|
|
433
|
-
}
|
|
434
|
-
},
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
export const pull = command({
|
|
438
|
-
name: 'introspect',
|
|
439
|
-
aliases: ['pull'],
|
|
440
|
-
options: {
|
|
441
|
-
config: optionConfig,
|
|
442
|
-
dialect: optionDialect,
|
|
443
|
-
out: optionOut,
|
|
444
|
-
breakpoints: optionBreakpoints,
|
|
445
|
-
casing: string('introspect-casing').enum('camel', 'preserve'),
|
|
446
|
-
...optionsFilters,
|
|
447
|
-
...optionsDatabaseCredentials,
|
|
448
|
-
},
|
|
449
|
-
transform: async (opts) => {
|
|
450
|
-
const from = assertCollisions(
|
|
451
|
-
'introspect',
|
|
452
|
-
opts,
|
|
453
|
-
[],
|
|
454
|
-
[
|
|
455
|
-
'dialect',
|
|
456
|
-
'driver',
|
|
457
|
-
'out',
|
|
458
|
-
'url',
|
|
459
|
-
'host',
|
|
460
|
-
'port',
|
|
461
|
-
'user',
|
|
462
|
-
'password',
|
|
463
|
-
'database',
|
|
464
|
-
'ssl',
|
|
465
|
-
'authToken',
|
|
466
|
-
'casing',
|
|
467
|
-
'breakpoints',
|
|
468
|
-
'tablesFilter',
|
|
469
|
-
'schemaFilters',
|
|
470
|
-
'extensionsFilters',
|
|
471
|
-
],
|
|
472
|
-
);
|
|
473
|
-
return preparePullConfig(opts, from);
|
|
474
|
-
},
|
|
475
|
-
handler: async (config) => {
|
|
476
|
-
await assertPackages('drizzle-orm');
|
|
477
|
-
await assertOrmCoreVersion();
|
|
478
|
-
|
|
479
|
-
const {
|
|
480
|
-
dialect,
|
|
481
|
-
credentials,
|
|
482
|
-
out,
|
|
483
|
-
casing,
|
|
484
|
-
breakpoints,
|
|
485
|
-
tablesFilter,
|
|
486
|
-
schemasFilter,
|
|
487
|
-
prefix,
|
|
488
|
-
entities,
|
|
489
|
-
} = config;
|
|
490
|
-
mkdirSync(out, { recursive: true });
|
|
491
|
-
|
|
492
|
-
console.log(
|
|
493
|
-
grey(
|
|
494
|
-
`Pulling from [${
|
|
495
|
-
schemasFilter
|
|
496
|
-
.map((it) => `'${it}'`)
|
|
497
|
-
.join(', ')
|
|
498
|
-
}] list of schemas`,
|
|
499
|
-
),
|
|
500
|
-
);
|
|
501
|
-
console.log();
|
|
502
|
-
|
|
503
|
-
try {
|
|
504
|
-
if (dialect === 'postgresql') {
|
|
505
|
-
if ('driver' in credentials) {
|
|
506
|
-
const { driver } = credentials;
|
|
507
|
-
if (driver === 'aws-data-api') {
|
|
508
|
-
if (!(await ormVersionGt('0.30.10'))) {
|
|
509
|
-
console.log(
|
|
510
|
-
"To use 'aws-data-api' driver - please update drizzle-orm to the latest version",
|
|
511
|
-
);
|
|
512
|
-
process.exit(1);
|
|
513
|
-
}
|
|
514
|
-
} else if (driver === 'pglite') {
|
|
515
|
-
if (!(await ormVersionGt('0.30.6'))) {
|
|
516
|
-
console.log(
|
|
517
|
-
"To use 'pglite' driver - please update drizzle-orm to the latest version",
|
|
518
|
-
);
|
|
519
|
-
process.exit(1);
|
|
520
|
-
}
|
|
521
|
-
} else {
|
|
522
|
-
assertUnreachable(driver);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
const { introspectPostgres } = await import('./commands/introspect');
|
|
527
|
-
await introspectPostgres(
|
|
528
|
-
casing,
|
|
529
|
-
out,
|
|
530
|
-
breakpoints,
|
|
531
|
-
credentials,
|
|
532
|
-
tablesFilter,
|
|
533
|
-
schemasFilter,
|
|
534
|
-
prefix,
|
|
535
|
-
entities,
|
|
536
|
-
);
|
|
537
|
-
} else if (dialect === 'mysql') {
|
|
538
|
-
const { introspectMysql } = await import('./commands/introspect');
|
|
539
|
-
await introspectMysql(
|
|
540
|
-
casing,
|
|
541
|
-
out,
|
|
542
|
-
breakpoints,
|
|
543
|
-
credentials,
|
|
544
|
-
tablesFilter,
|
|
545
|
-
prefix,
|
|
546
|
-
);
|
|
547
|
-
} else if (dialect === 'sqlite') {
|
|
548
|
-
const { introspectSqlite } = await import('./commands/introspect');
|
|
549
|
-
await introspectSqlite(
|
|
550
|
-
casing,
|
|
551
|
-
out,
|
|
552
|
-
breakpoints,
|
|
553
|
-
credentials,
|
|
554
|
-
tablesFilter,
|
|
555
|
-
prefix,
|
|
556
|
-
);
|
|
557
|
-
} else if (dialect === 'turso') {
|
|
558
|
-
const { introspectLibSQL } = await import('./commands/introspect');
|
|
559
|
-
await introspectLibSQL(
|
|
560
|
-
casing,
|
|
561
|
-
out,
|
|
562
|
-
breakpoints,
|
|
563
|
-
credentials,
|
|
564
|
-
tablesFilter,
|
|
565
|
-
prefix,
|
|
566
|
-
);
|
|
567
|
-
} else if (dialect === 'singlestore') {
|
|
568
|
-
const { introspectSingleStore } = await import('./commands/introspect');
|
|
569
|
-
await introspectSingleStore(
|
|
570
|
-
casing,
|
|
571
|
-
out,
|
|
572
|
-
breakpoints,
|
|
573
|
-
credentials,
|
|
574
|
-
tablesFilter,
|
|
575
|
-
prefix,
|
|
576
|
-
);
|
|
577
|
-
} else {
|
|
578
|
-
assertUnreachable(dialect);
|
|
579
|
-
}
|
|
580
|
-
} catch (e) {
|
|
581
|
-
console.error(e);
|
|
582
|
-
}
|
|
583
|
-
process.exit(0);
|
|
584
|
-
},
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
export const drop = command({
|
|
588
|
-
name: 'drop',
|
|
589
|
-
options: {
|
|
590
|
-
config: optionConfig,
|
|
591
|
-
out: optionOut,
|
|
592
|
-
driver: optionDriver,
|
|
593
|
-
},
|
|
594
|
-
transform: async (opts) => {
|
|
595
|
-
const from = assertCollisions('check', opts, [], ['driver', 'out']);
|
|
596
|
-
return prepareDropParams(opts, from);
|
|
597
|
-
},
|
|
598
|
-
handler: async (config) => {
|
|
599
|
-
await assertOrmCoreVersion();
|
|
600
|
-
|
|
601
|
-
assertV1OutFolder(config.out);
|
|
602
|
-
await dropMigration(config);
|
|
603
|
-
},
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
export const studio = command({
|
|
607
|
-
name: 'studio',
|
|
608
|
-
options: {
|
|
609
|
-
config: optionConfig,
|
|
610
|
-
port: number().desc('Custom port for drizzle studio [default=4983]'),
|
|
611
|
-
host: string().desc('Custom host for drizzle studio [default=0.0.0.0]'),
|
|
612
|
-
verbose: boolean()
|
|
613
|
-
.default(false)
|
|
614
|
-
.desc('Print all stataments that are executed by Studio'),
|
|
615
|
-
},
|
|
616
|
-
handler: async (opts) => {
|
|
617
|
-
await assertOrmCoreVersion();
|
|
618
|
-
await assertPackages('drizzle-orm');
|
|
619
|
-
|
|
620
|
-
assertStudioNodeVersion();
|
|
621
|
-
|
|
622
|
-
const {
|
|
623
|
-
dialect,
|
|
624
|
-
schema: schemaPath,
|
|
625
|
-
port,
|
|
626
|
-
host,
|
|
627
|
-
credentials,
|
|
628
|
-
} = await prepareStudioConfig(opts);
|
|
629
|
-
|
|
630
|
-
const {
|
|
631
|
-
drizzleForPostgres,
|
|
632
|
-
preparePgSchema,
|
|
633
|
-
prepareMySqlSchema,
|
|
634
|
-
drizzleForMySQL,
|
|
635
|
-
prepareSQLiteSchema,
|
|
636
|
-
drizzleForSQLite,
|
|
637
|
-
prepareSingleStoreSchema,
|
|
638
|
-
drizzleForSingleStore,
|
|
639
|
-
drizzleForLibSQL,
|
|
640
|
-
} = await import('../serializer/studio');
|
|
641
|
-
|
|
642
|
-
let setup: Setup;
|
|
643
|
-
try {
|
|
644
|
-
if (dialect === 'postgresql') {
|
|
645
|
-
if ('driver' in credentials) {
|
|
646
|
-
const { driver } = credentials;
|
|
647
|
-
if (driver === 'aws-data-api') {
|
|
648
|
-
if (!(await ormVersionGt('0.30.10'))) {
|
|
649
|
-
console.log(
|
|
650
|
-
"To use 'aws-data-api' driver - please update drizzle-orm to the latest version",
|
|
651
|
-
);
|
|
652
|
-
process.exit(1);
|
|
653
|
-
}
|
|
654
|
-
} else if (driver === 'pglite') {
|
|
655
|
-
if (!(await ormVersionGt('0.30.6'))) {
|
|
656
|
-
console.log(
|
|
657
|
-
"To use 'pglite' driver - please update drizzle-orm to the latest version",
|
|
658
|
-
);
|
|
659
|
-
process.exit(1);
|
|
660
|
-
}
|
|
661
|
-
} else {
|
|
662
|
-
assertUnreachable(driver);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
const { schema, relations, files } = schemaPath
|
|
667
|
-
? await preparePgSchema(schemaPath)
|
|
668
|
-
: { schema: {}, relations: {}, files: [] };
|
|
669
|
-
setup = await drizzleForPostgres(credentials, schema, relations, files);
|
|
670
|
-
} else if (dialect === 'mysql') {
|
|
671
|
-
const { schema, relations, files } = schemaPath
|
|
672
|
-
? await prepareMySqlSchema(schemaPath)
|
|
673
|
-
: { schema: {}, relations: {}, files: [] };
|
|
674
|
-
setup = await drizzleForMySQL(credentials, schema, relations, files);
|
|
675
|
-
} else if (dialect === 'sqlite') {
|
|
676
|
-
const { schema, relations, files } = schemaPath
|
|
677
|
-
? await prepareSQLiteSchema(schemaPath)
|
|
678
|
-
: { schema: {}, relations: {}, files: [] };
|
|
679
|
-
setup = await drizzleForSQLite(credentials, schema, relations, files);
|
|
680
|
-
} else if (dialect === 'turso') {
|
|
681
|
-
const { schema, relations, files } = schemaPath
|
|
682
|
-
? await prepareSQLiteSchema(schemaPath)
|
|
683
|
-
: { schema: {}, relations: {}, files: [] };
|
|
684
|
-
setup = await drizzleForLibSQL(credentials, schema, relations, files);
|
|
685
|
-
} else if (dialect === 'singlestore') {
|
|
686
|
-
const { schema, relations, files } = schemaPath
|
|
687
|
-
? await prepareSingleStoreSchema(schemaPath)
|
|
688
|
-
: { schema: {}, relations: {}, files: [] };
|
|
689
|
-
setup = await drizzleForSingleStore(
|
|
690
|
-
credentials,
|
|
691
|
-
schema,
|
|
692
|
-
relations,
|
|
693
|
-
files,
|
|
694
|
-
);
|
|
695
|
-
} else {
|
|
696
|
-
assertUnreachable(dialect);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
const { prepareServer } = await import('../serializer/studio');
|
|
700
|
-
|
|
701
|
-
const server = await prepareServer(setup);
|
|
702
|
-
|
|
703
|
-
console.log();
|
|
704
|
-
console.log(
|
|
705
|
-
withStyle.fullWarning(
|
|
706
|
-
'Drizzle Studio is currently in Beta. If you find anything that is not working as expected or should be improved, feel free to create an issue on GitHub: https://github.com/drizzle-team/drizzle-kit-mirror/issues/new or write to us on Discord: https://discord.gg/WcRKz2FFxN',
|
|
707
|
-
),
|
|
708
|
-
);
|
|
709
|
-
|
|
710
|
-
const { key, cert } = (await certs()) || {};
|
|
711
|
-
server.start({
|
|
712
|
-
host,
|
|
713
|
-
port,
|
|
714
|
-
key,
|
|
715
|
-
cert,
|
|
716
|
-
cb: (err, address) => {
|
|
717
|
-
if (err) {
|
|
718
|
-
console.error(err);
|
|
719
|
-
} else {
|
|
720
|
-
const queryParams: { port?: number; host?: string } = {};
|
|
721
|
-
if (port !== 4983) {
|
|
722
|
-
queryParams.port = port;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
if (host !== '127.0.0.1') {
|
|
726
|
-
queryParams.host = host;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
const queryString = Object.keys(queryParams)
|
|
730
|
-
.map((key: keyof { port?: number; host?: string }) => {
|
|
731
|
-
return `${key}=${queryParams[key]}`;
|
|
732
|
-
})
|
|
733
|
-
.join('&');
|
|
734
|
-
|
|
735
|
-
console.log(
|
|
736
|
-
`\nDrizzle Studio is up and running on ${
|
|
737
|
-
chalk.blue(
|
|
738
|
-
`https://local.drizzle.studio${queryString ? `?${queryString}` : ''}`,
|
|
739
|
-
)
|
|
740
|
-
}`,
|
|
741
|
-
);
|
|
742
|
-
}
|
|
743
|
-
},
|
|
744
|
-
});
|
|
745
|
-
} catch (e) {
|
|
746
|
-
console.error(e);
|
|
747
|
-
process.exit(0);
|
|
748
|
-
}
|
|
749
|
-
},
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
export const exportRaw = command({
|
|
753
|
-
name: 'export',
|
|
754
|
-
desc: 'Generate diff between current state and empty state in specified formats: sql',
|
|
755
|
-
options: {
|
|
756
|
-
sql: boolean('sql').default(true).desc('Generate as sql'),
|
|
757
|
-
config: optionConfig,
|
|
758
|
-
dialect: optionDialect,
|
|
759
|
-
schema: string().desc('Path to a schema file or folder'),
|
|
760
|
-
},
|
|
761
|
-
transform: async (opts) => {
|
|
762
|
-
const from = assertCollisions('export', opts, ['sql'], ['dialect', 'schema']);
|
|
763
|
-
return prepareExportConfig(opts, from);
|
|
764
|
-
},
|
|
765
|
-
handler: async (opts) => {
|
|
766
|
-
await assertOrmCoreVersion();
|
|
767
|
-
await assertPackages('drizzle-orm');
|
|
768
|
-
|
|
769
|
-
const {
|
|
770
|
-
prepareAndExportPg,
|
|
771
|
-
prepareAndExportMysql,
|
|
772
|
-
prepareAndExportSqlite,
|
|
773
|
-
prepareAndExportLibSQL,
|
|
774
|
-
prepareAndExportSinglestore,
|
|
775
|
-
} = await import(
|
|
776
|
-
'./commands/migrate'
|
|
777
|
-
);
|
|
778
|
-
|
|
779
|
-
const dialect = opts.dialect;
|
|
780
|
-
if (dialect === 'postgresql') {
|
|
781
|
-
await prepareAndExportPg(opts);
|
|
782
|
-
} else if (dialect === 'mysql') {
|
|
783
|
-
await prepareAndExportMysql(opts);
|
|
784
|
-
} else if (dialect === 'sqlite') {
|
|
785
|
-
await prepareAndExportSqlite(opts);
|
|
786
|
-
} else if (dialect === 'turso') {
|
|
787
|
-
await prepareAndExportLibSQL(opts);
|
|
788
|
-
} else if (dialect === 'singlestore') {
|
|
789
|
-
await prepareAndExportSinglestore(opts);
|
|
790
|
-
} else {
|
|
791
|
-
assertUnreachable(dialect);
|
|
792
|
-
}
|
|
793
|
-
},
|
|
794
|
-
});
|