drizzle-kit 0.20.16 → 0.20.17-7776aba
Sign up to get free protection for your applications and to get access to all the features.
- package/bin.cjs +192 -35
- package/package.json +1 -1
package/bin.cjs
CHANGED
@@ -22453,23 +22453,23 @@ var require_isexe = __commonJS({
|
|
22453
22453
|
throw new TypeError("callback not provided");
|
22454
22454
|
}
|
22455
22455
|
return new Promise(function(resolve2, reject) {
|
22456
|
-
isexe(path5, options || {}, function(er,
|
22456
|
+
isexe(path5, options || {}, function(er, is9) {
|
22457
22457
|
if (er) {
|
22458
22458
|
reject(er);
|
22459
22459
|
} else {
|
22460
|
-
resolve2(
|
22460
|
+
resolve2(is9);
|
22461
22461
|
}
|
22462
22462
|
});
|
22463
22463
|
});
|
22464
22464
|
}
|
22465
|
-
core(path5, options || {}, function(er,
|
22465
|
+
core(path5, options || {}, function(er, is9) {
|
22466
22466
|
if (er) {
|
22467
22467
|
if (er.code === "EACCES" || options && options.ignoreErrors) {
|
22468
22468
|
er = null;
|
22469
|
-
|
22469
|
+
is9 = false;
|
22470
22470
|
}
|
22471
22471
|
}
|
22472
|
-
cb(er,
|
22472
|
+
cb(er, is9);
|
22473
22473
|
});
|
22474
22474
|
}
|
22475
22475
|
function sync2(path5, options) {
|
@@ -22532,8 +22532,8 @@ var require_lib = __commonJS({
|
|
22532
22532
|
const p2 = getPathPart(envPart, cmd);
|
22533
22533
|
for (const ext2 of pathExt) {
|
22534
22534
|
const withExt = p2 + ext2;
|
22535
|
-
const
|
22536
|
-
if (
|
22535
|
+
const is9 = await isexe(withExt, { pathExt: pathExtExe, ignoreErrors: true });
|
22536
|
+
if (is9) {
|
22537
22537
|
if (!opt.all) {
|
22538
22538
|
return withExt;
|
22539
22539
|
}
|
@@ -22556,8 +22556,8 @@ var require_lib = __commonJS({
|
|
22556
22556
|
const p2 = getPathPart(pathEnvPart, cmd);
|
22557
22557
|
for (const ext2 of pathExt) {
|
22558
22558
|
const withExt = p2 + ext2;
|
22559
|
-
const
|
22560
|
-
if (
|
22559
|
+
const is9 = isexe.sync(withExt, { pathExt: pathExtExe, ignoreErrors: true });
|
22560
|
+
if (is9) {
|
22561
22561
|
if (!opt.all) {
|
22562
22562
|
return withExt;
|
22563
22563
|
}
|
@@ -60336,9 +60336,12 @@ __export(studio_exports, {
|
|
60336
60336
|
drizzleForMySQL: () => drizzleForMySQL,
|
60337
60337
|
drizzleForPostgres: () => drizzleForPostgres,
|
60338
60338
|
drizzleForSQLite: () => drizzleForSQLite,
|
60339
|
+
prepareMySqlSchema: () => prepareMySqlSchema,
|
60340
|
+
preparePgSchema: () => preparePgSchema,
|
60341
|
+
prepareSQLiteSchema: () => prepareSQLiteSchema,
|
60339
60342
|
prepareServer: () => prepareServer
|
60340
60343
|
});
|
60341
|
-
var import_node_https, drizzleForPostgres, drizzleForMySQL, prepareParams, drizzleForSQLite, init, proxySchema, schema4, jsonStringify, prepareServer;
|
60344
|
+
var import_node_https, import_pg_core4, import_drizzle_orm8, import_mysql_core4, import_sqlite_core3, preparePgSchema, prepareMySqlSchema, prepareSQLiteSchema, getCustomDefaults, drizzleForPostgres, drizzleForMySQL, prepareParams, drizzleForSQLite, init, proxySchema, defaultsSchema, schema4, jsonStringify, prepareServer;
|
60342
60345
|
var init_studio = __esm({
|
60343
60346
|
"src/serializer/studio.ts"() {
|
60344
60347
|
init_dist();
|
@@ -60350,7 +60353,110 @@ var init_studio = __esm({
|
|
60350
60353
|
init_lib();
|
60351
60354
|
init_utils3();
|
60352
60355
|
init_global();
|
60353
|
-
|
60356
|
+
init_serializer();
|
60357
|
+
import_pg_core4 = require("drizzle-orm/pg-core");
|
60358
|
+
import_drizzle_orm8 = require("drizzle-orm");
|
60359
|
+
init_utils();
|
60360
|
+
import_mysql_core4 = require("drizzle-orm/mysql-core");
|
60361
|
+
import_sqlite_core3 = require("drizzle-orm/sqlite-core");
|
60362
|
+
preparePgSchema = async (path5) => {
|
60363
|
+
const imports = prepareFilenames(path5);
|
60364
|
+
const pgSchema3 = {};
|
60365
|
+
const relations4 = {};
|
60366
|
+
const { unregister } = await safeRegister();
|
60367
|
+
for (let i = 0; i < imports.length; i++) {
|
60368
|
+
const it = imports[i];
|
60369
|
+
const i0 = require(`${it}`);
|
60370
|
+
const i0values = Object.entries(i0);
|
60371
|
+
i0values.forEach(([k, t]) => {
|
60372
|
+
if ((0, import_drizzle_orm8.is)(t, import_pg_core4.PgTable)) {
|
60373
|
+
const schema5 = (0, import_pg_core4.getTableConfig)(t).schema || "public";
|
60374
|
+
pgSchema3[schema5] = pgSchema3[schema5] || {};
|
60375
|
+
pgSchema3[schema5][k] = t;
|
60376
|
+
}
|
60377
|
+
if ((0, import_drizzle_orm8.is)(t, import_drizzle_orm8.Relations)) {
|
60378
|
+
relations4[k] = t;
|
60379
|
+
}
|
60380
|
+
});
|
60381
|
+
}
|
60382
|
+
unregister();
|
60383
|
+
return { schema: pgSchema3, relations: relations4 };
|
60384
|
+
};
|
60385
|
+
prepareMySqlSchema = async (path5) => {
|
60386
|
+
const imports = prepareFilenames(path5);
|
60387
|
+
const mysqlSchema5 = {
|
60388
|
+
public: {}
|
60389
|
+
};
|
60390
|
+
const relations4 = {};
|
60391
|
+
const { unregister } = await safeRegister();
|
60392
|
+
for (let i = 0; i < imports.length; i++) {
|
60393
|
+
const it = imports[i];
|
60394
|
+
const i0 = require(`${it}`);
|
60395
|
+
const i0values = Object.entries(i0);
|
60396
|
+
i0values.forEach(([k, t]) => {
|
60397
|
+
if ((0, import_drizzle_orm8.is)(t, import_mysql_core4.MySqlTable)) {
|
60398
|
+
const schema5 = (0, import_mysql_core4.getTableConfig)(t).schema || "public";
|
60399
|
+
mysqlSchema5[schema5][k] = t;
|
60400
|
+
}
|
60401
|
+
if ((0, import_drizzle_orm8.is)(t, import_drizzle_orm8.Relations)) {
|
60402
|
+
relations4[k] = t;
|
60403
|
+
}
|
60404
|
+
});
|
60405
|
+
}
|
60406
|
+
unregister();
|
60407
|
+
return { schema: mysqlSchema5, relations: relations4 };
|
60408
|
+
};
|
60409
|
+
prepareSQLiteSchema = async (path5) => {
|
60410
|
+
const imports = prepareFilenames(path5);
|
60411
|
+
const sqliteSchema3 = {
|
60412
|
+
public: {}
|
60413
|
+
};
|
60414
|
+
const relations4 = {};
|
60415
|
+
const { unregister } = await safeRegister();
|
60416
|
+
for (let i = 0; i < imports.length; i++) {
|
60417
|
+
const it = imports[i];
|
60418
|
+
const i0 = require(`${it}`);
|
60419
|
+
const i0values = Object.entries(i0);
|
60420
|
+
i0values.forEach(([k, t]) => {
|
60421
|
+
if ((0, import_drizzle_orm8.is)(t, import_sqlite_core3.SQLiteTable)) {
|
60422
|
+
const schema5 = "public";
|
60423
|
+
sqliteSchema3[schema5][k] = t;
|
60424
|
+
}
|
60425
|
+
if ((0, import_drizzle_orm8.is)(t, import_drizzle_orm8.Relations)) {
|
60426
|
+
relations4[k] = t;
|
60427
|
+
}
|
60428
|
+
});
|
60429
|
+
}
|
60430
|
+
unregister();
|
60431
|
+
return { schema: sqliteSchema3, relations: relations4 };
|
60432
|
+
};
|
60433
|
+
getCustomDefaults = (schema5) => {
|
60434
|
+
const customDefaults = [];
|
60435
|
+
Object.entries(schema5).map(([schema6, tables]) => {
|
60436
|
+
Object.entries(tables).map(([, table4]) => {
|
60437
|
+
let tableConfig;
|
60438
|
+
if ((0, import_drizzle_orm8.is)(table4, import_pg_core4.PgTable)) {
|
60439
|
+
tableConfig = (0, import_pg_core4.getTableConfig)(table4);
|
60440
|
+
} else if ((0, import_drizzle_orm8.is)(table4, import_mysql_core4.MySqlTable)) {
|
60441
|
+
tableConfig = (0, import_mysql_core4.getTableConfig)(table4);
|
60442
|
+
} else {
|
60443
|
+
tableConfig = (0, import_sqlite_core3.getTableConfig)(table4);
|
60444
|
+
}
|
60445
|
+
tableConfig.columns.map((column7) => {
|
60446
|
+
if (column7.defaultFn) {
|
60447
|
+
customDefaults.push({
|
60448
|
+
schema: schema6,
|
60449
|
+
table: tableConfig.name,
|
60450
|
+
column: column7.name,
|
60451
|
+
func: column7.defaultFn
|
60452
|
+
});
|
60453
|
+
}
|
60454
|
+
});
|
60455
|
+
});
|
60456
|
+
});
|
60457
|
+
return customDefaults;
|
60458
|
+
};
|
60459
|
+
drizzleForPostgres = async (connectionConfig, pgSchema3, relations4) => {
|
60354
60460
|
assertPackages("pg");
|
60355
60461
|
const pg = await Promise.resolve().then(() => __toESM(require_lib3()));
|
60356
60462
|
const client = new pg.default.Pool(connectionConfig.dbCredentials);
|
@@ -60362,12 +60468,14 @@ var init_studio = __esm({
|
|
60362
60468
|
});
|
60363
60469
|
return result.rows;
|
60364
60470
|
};
|
60471
|
+
const customDefaults = getCustomDefaults(pgSchema3);
|
60365
60472
|
return {
|
60366
60473
|
dialect: "pg",
|
60367
|
-
proxy
|
60474
|
+
proxy,
|
60475
|
+
customDefaults
|
60368
60476
|
};
|
60369
60477
|
};
|
60370
|
-
drizzleForMySQL = async (config) => {
|
60478
|
+
drizzleForMySQL = async (config, mysqlSchema5, relations4) => {
|
60371
60479
|
assertPackages("mysql2");
|
60372
60480
|
const { createPool } = await Promise.resolve().then(() => __toESM(require_promise()));
|
60373
60481
|
const client = createPool({ ...config.dbCredentials, connectionLimit: 1 });
|
@@ -60379,9 +60487,11 @@ var init_studio = __esm({
|
|
60379
60487
|
});
|
60380
60488
|
return result[0];
|
60381
60489
|
};
|
60490
|
+
const customDefaults = getCustomDefaults(mysqlSchema5);
|
60382
60491
|
return {
|
60383
60492
|
dialect: "mysql",
|
60384
|
-
proxy
|
60493
|
+
proxy,
|
60494
|
+
customDefaults
|
60385
60495
|
};
|
60386
60496
|
};
|
60387
60497
|
prepareParams = (params) => {
|
@@ -60392,15 +60502,17 @@ var init_studio = __esm({
|
|
60392
60502
|
return param;
|
60393
60503
|
});
|
60394
60504
|
};
|
60395
|
-
drizzleForSQLite = async (config) => {
|
60505
|
+
drizzleForSQLite = async (config, sqliteSchema3, relations4) => {
|
60396
60506
|
const { driver: driver2, dbCredentials } = config;
|
60507
|
+
const customDefaults = getCustomDefaults(sqliteSchema3);
|
60397
60508
|
if (driver2 === "d1") {
|
60398
60509
|
const proxy = async (params) => {
|
60399
60510
|
throw new Error("Proxy is not implemented for D1");
|
60400
60511
|
};
|
60401
60512
|
return {
|
60402
60513
|
dialect: "sqlite",
|
60403
|
-
proxy
|
60514
|
+
proxy,
|
60515
|
+
customDefaults
|
60404
60516
|
};
|
60405
60517
|
}
|
60406
60518
|
if (driver2 === "better-sqlite") {
|
@@ -60416,7 +60528,8 @@ var init_studio = __esm({
|
|
60416
60528
|
};
|
60417
60529
|
return {
|
60418
60530
|
dialect: "sqlite",
|
60419
|
-
proxy
|
60531
|
+
proxy,
|
60532
|
+
customDefaults
|
60420
60533
|
};
|
60421
60534
|
}
|
60422
60535
|
if (driver2 === "libsql" || driver2 === "turso") {
|
@@ -60437,7 +60550,8 @@ var init_studio = __esm({
|
|
60437
60550
|
};
|
60438
60551
|
return {
|
60439
60552
|
dialect: "sqlite",
|
60440
|
-
proxy
|
60553
|
+
proxy,
|
60554
|
+
customDefaults
|
60441
60555
|
};
|
60442
60556
|
}
|
60443
60557
|
assertUnreachable(driver2);
|
@@ -60454,9 +60568,18 @@ var init_studio = __esm({
|
|
60454
60568
|
method: mod.union([mod.literal("values"), mod.literal("get"), mod.literal("all"), mod.literal("run"), mod.literal("execute")])
|
60455
60569
|
})
|
60456
60570
|
});
|
60571
|
+
defaultsSchema = mod.object({
|
60572
|
+
type: mod.literal("defaults"),
|
60573
|
+
data: mod.array(mod.object({
|
60574
|
+
schema: mod.string(),
|
60575
|
+
table: mod.string(),
|
60576
|
+
column: mod.string()
|
60577
|
+
})).min(1)
|
60578
|
+
});
|
60457
60579
|
schema4 = mod.union([
|
60458
60580
|
init,
|
60459
|
-
proxySchema
|
60581
|
+
proxySchema,
|
60582
|
+
defaultsSchema
|
60460
60583
|
]);
|
60461
60584
|
SuperJSON.registerCustom(
|
60462
60585
|
{
|
@@ -60479,7 +60602,7 @@ var init_studio = __esm({
|
|
60479
60602
|
return value;
|
60480
60603
|
});
|
60481
60604
|
};
|
60482
|
-
prepareServer = async ({ dialect: dialect6, proxy }, app) => {
|
60605
|
+
prepareServer = async ({ dialect: dialect6, proxy, customDefaults }, app) => {
|
60483
60606
|
app = app !== void 0 ? app : new Hono2();
|
60484
60607
|
app.use(cors());
|
60485
60608
|
app.onError((err2, ctx) => {
|
@@ -60493,7 +60616,12 @@ var init_studio = __esm({
|
|
60493
60616
|
const body = c.req.valid("json");
|
60494
60617
|
const { type } = body;
|
60495
60618
|
if (type === "init") {
|
60496
|
-
|
60619
|
+
const preparedDefaults = customDefaults.map((d) => ({
|
60620
|
+
schema: d.schema,
|
60621
|
+
table: d.table,
|
60622
|
+
column: d.column
|
60623
|
+
}));
|
60624
|
+
return c.json({ version: "5", dialect: dialect6, customDefaults: preparedDefaults });
|
60497
60625
|
}
|
60498
60626
|
if (type === "proxy") {
|
60499
60627
|
const { sql: sql2, params, mode, method } = body.data;
|
@@ -60505,6 +60633,23 @@ var init_studio = __esm({
|
|
60505
60633
|
});
|
60506
60634
|
return c.json(JSON.parse(jsonStringify(result)));
|
60507
60635
|
}
|
60636
|
+
if (type === "defaults") {
|
60637
|
+
const columns = body.data;
|
60638
|
+
const result = columns.map((column7) => {
|
60639
|
+
const found = customDefaults.find((d) => {
|
60640
|
+
return d.schema === column7.schema && d.table === column7.table && d.column === column7.column;
|
60641
|
+
});
|
60642
|
+
if (!found) {
|
60643
|
+
throw new Error(`Custom default not found for ${column7.schema}.${column7.table}.${column7.column}`);
|
60644
|
+
}
|
60645
|
+
const value = found.func();
|
60646
|
+
return {
|
60647
|
+
...column7,
|
60648
|
+
value
|
60649
|
+
};
|
60650
|
+
});
|
60651
|
+
return c.json(JSON.parse(jsonStringify(result)));
|
60652
|
+
}
|
60508
60653
|
throw new Error(`Unknown type: ${type}`);
|
60509
60654
|
});
|
60510
60655
|
return {
|
@@ -62371,10 +62516,10 @@ __export(drivers_exports, {
|
|
62371
62516
|
PgPostgres: () => PgPostgres,
|
62372
62517
|
TursoSqlite: () => TursoSqlite
|
62373
62518
|
});
|
62374
|
-
var
|
62519
|
+
var import_drizzle_orm9, DrizzleDbClient, DrizzleORMPgClient, DrizzleORMMySQLClient, DrizzleORMSQLiteClient, BetterSqlite, MySQL2Client, TursoSqlite, PgPostgres;
|
62375
62520
|
var init_drivers = __esm({
|
62376
62521
|
"src/drivers/index.ts"() {
|
62377
|
-
|
62522
|
+
import_drizzle_orm9 = require("drizzle-orm");
|
62378
62523
|
DrizzleDbClient = class {
|
62379
62524
|
constructor(db) {
|
62380
62525
|
this.db = db;
|
@@ -62382,30 +62527,30 @@ var init_drivers = __esm({
|
|
62382
62527
|
};
|
62383
62528
|
DrizzleORMPgClient = class extends DrizzleDbClient {
|
62384
62529
|
async query(query, values) {
|
62385
|
-
const res = await this.db.execute(
|
62530
|
+
const res = await this.db.execute(import_drizzle_orm9.sql.raw(query));
|
62386
62531
|
return res.rows;
|
62387
62532
|
}
|
62388
62533
|
async run(query) {
|
62389
|
-
const res = await this.db.execute(
|
62534
|
+
const res = await this.db.execute(import_drizzle_orm9.sql.raw(query));
|
62390
62535
|
return res.rows;
|
62391
62536
|
}
|
62392
62537
|
};
|
62393
62538
|
DrizzleORMMySQLClient = class extends DrizzleDbClient {
|
62394
62539
|
async query(query, values) {
|
62395
|
-
const res = await this.db.execute(
|
62540
|
+
const res = await this.db.execute(import_drizzle_orm9.sql.raw(query));
|
62396
62541
|
return res[0];
|
62397
62542
|
}
|
62398
62543
|
async run(query) {
|
62399
|
-
await this.db.execute(
|
62544
|
+
await this.db.execute(import_drizzle_orm9.sql.raw(query));
|
62400
62545
|
}
|
62401
62546
|
};
|
62402
62547
|
DrizzleORMSQLiteClient = class extends DrizzleDbClient {
|
62403
62548
|
async query(query, values) {
|
62404
|
-
const res = this.db.all(
|
62549
|
+
const res = this.db.all(import_drizzle_orm9.sql.raw(query));
|
62405
62550
|
return res;
|
62406
62551
|
}
|
62407
62552
|
async run(query) {
|
62408
|
-
this.db.run(
|
62553
|
+
this.db.run(import_drizzle_orm9.sql.raw(query));
|
62409
62554
|
}
|
62410
62555
|
};
|
62411
62556
|
BetterSqlite = class extends DrizzleDbClient {
|
@@ -62560,10 +62705,10 @@ var init_pgConnect = __esm({
|
|
62560
62705
|
});
|
62561
62706
|
|
62562
62707
|
// src/introspect-pg.ts
|
62563
|
-
var
|
62708
|
+
var import_drizzle_orm10, import_relations, pgImportsList, objToStatement22, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations2, withCasing, schemaToTypeScript2, isCyclic2, isSelf2, column5, dimensionsInArray, createTableColumns2, createTableIndexes2, createTablePKs2, createTableUniques2, createTableFKs2;
|
62564
62709
|
var init_introspect_pg = __esm({
|
62565
62710
|
"src/introspect-pg.ts"() {
|
62566
|
-
|
62711
|
+
import_drizzle_orm10 = require("drizzle-orm");
|
62567
62712
|
import_relations = require("drizzle-orm/relations");
|
62568
62713
|
init_utils4();
|
62569
62714
|
init_pgSerializer();
|
@@ -63745,7 +63890,7 @@ init_source();
|
|
63745
63890
|
// package.json
|
63746
63891
|
var package_default = {
|
63747
63892
|
name: "drizzle-kit",
|
63748
|
-
version: "0.20.
|
63893
|
+
version: "0.20.17",
|
63749
63894
|
repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
|
63750
63895
|
author: "Drizzle Team",
|
63751
63896
|
license: "MIT",
|
@@ -66550,22 +66695,34 @@ var studioCommand = new import_commander.Command("studio").option("--port <port>
|
|
66550
66695
|
const drizzleConfig = await validateStudio2(options);
|
66551
66696
|
const {
|
66552
66697
|
drizzleForPostgres: drizzleForPostgres2,
|
66698
|
+
preparePgSchema: preparePgSchema2,
|
66699
|
+
prepareMySqlSchema: prepareMySqlSchema2,
|
66553
66700
|
drizzleForMySQL: drizzleForMySQL2,
|
66701
|
+
prepareSQLiteSchema: prepareSQLiteSchema2,
|
66554
66702
|
drizzleForSQLite: drizzleForSQLite2
|
66555
66703
|
} = await Promise.resolve().then(() => (init_studio(), studio_exports));
|
66556
66704
|
const { driver: driver2, schema: schemaPath } = drizzleConfig;
|
66557
66705
|
let setup;
|
66558
66706
|
if (driver2 === "pg") {
|
66707
|
+
const { schema: schema5, relations: relations4 } = await preparePgSchema2(schemaPath);
|
66559
66708
|
setup = await drizzleForPostgres2(
|
66560
|
-
drizzleConfig
|
66709
|
+
drizzleConfig,
|
66710
|
+
schema5,
|
66711
|
+
relations4
|
66561
66712
|
);
|
66562
66713
|
} else if (driver2 === "mysql2") {
|
66714
|
+
const { schema: schema5, relations: relations4 } = await prepareMySqlSchema2(schemaPath);
|
66563
66715
|
setup = await drizzleForMySQL2(
|
66564
|
-
drizzleConfig
|
66716
|
+
drizzleConfig,
|
66717
|
+
schema5,
|
66718
|
+
relations4
|
66565
66719
|
);
|
66566
66720
|
} else if (driver2 === "better-sqlite" || driver2 === "d1" || driver2 === "libsql" || driver2 === "turso") {
|
66721
|
+
const { schema: schema5, relations: relations4 } = await prepareSQLiteSchema2(schemaPath);
|
66567
66722
|
setup = await drizzleForSQLite2(
|
66568
|
-
drizzleConfig
|
66723
|
+
drizzleConfig,
|
66724
|
+
schema5,
|
66725
|
+
relations4
|
66569
66726
|
);
|
66570
66727
|
} else {
|
66571
66728
|
assertUnreachable(driver2);
|