drizzle-kit 0.20.7 → 0.20.8-883376b
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/bin.cjs +799 -785
- package/cli/commands/migrate.d.ts +11 -1
- package/cli/commands/utils.d.ts +9 -0
- package/cli/validations/mysql.d.ts +6 -6
- package/cli/validations/pg.d.ts +12 -12
- package/index.d.mts +2 -0
- package/index.d.ts +2 -0
- package/package.json +3 -2
- package/serializer/pgSerializer.d.ts +0 -2
- package/serializer/schemaToDrizzle.d.ts +7 -0
- package/serializer/sqliteSerializer.d.ts +0 -2
- package/serializer/studioUtils.d.ts +4 -4
- package/utils-studio.d.mts +2 -2
- package/utils-studio.d.ts +2 -2
- package/utils-studio.js +959 -957
- package/utils-studio.mjs +624 -622
- package/utils.js +252 -215
package/utils.js
CHANGED
@@ -11140,7 +11140,7 @@ var require_node2 = __commonJS({
|
|
11140
11140
|
});
|
11141
11141
|
|
11142
11142
|
// src/cli/commands/utils.ts
|
11143
|
-
var import_hanji2, assertES5, safeRegister, configCommonSchema, introspectCasing, configIntrospectSchema, configIntrospectCliSchema, configGenerateSchema, configPushSchema, mysqlConnectionSchema, mySqlCliConfigSchema, mySqlIntrospectConfigSchema;
|
11143
|
+
var import_hanji2, assertES5, safeRegister, driver, configCommonSchema, introspectCasing, configIntrospectSchema, configIntrospectCliSchema, configGenerateSchema, configPushSchema, mysqlConnectionSchema, mySqlCliConfigSchema, mySqlIntrospectConfigSchema;
|
11144
11144
|
var init_utils = __esm({
|
11145
11145
|
"src/cli/commands/utils.ts"() {
|
11146
11146
|
init_serializer();
|
@@ -11189,10 +11189,20 @@ var init_utils = __esm({
|
|
11189
11189
|
await assertES5(res.unregister);
|
11190
11190
|
return res;
|
11191
11191
|
};
|
11192
|
+
driver = unionType([
|
11193
|
+
literalType("better-sqlite"),
|
11194
|
+
literalType("turso"),
|
11195
|
+
literalType("libsql"),
|
11196
|
+
literalType("d1"),
|
11197
|
+
literalType("expo"),
|
11198
|
+
literalType("pg"),
|
11199
|
+
literalType("mysql2")
|
11200
|
+
]);
|
11192
11201
|
configCommonSchema = objectType({
|
11193
11202
|
schema: unionType([stringType(), stringType().array()]),
|
11194
11203
|
out: stringType().optional(),
|
11195
11204
|
breakpoints: booleanType().default(true),
|
11205
|
+
driver: driver.optional(),
|
11196
11206
|
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
11197
11207
|
schemaFilter: unionType([stringType(), stringType().array()]).default(["public"])
|
11198
11208
|
});
|
@@ -11721,9 +11731,9 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
11721
11731
|
}
|
11722
11732
|
try {
|
11723
11733
|
const fks = await db.execute(
|
11724
|
-
`SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,
|
11734
|
+
`SELECT INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_SCHEMA,INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME, INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_COLUMN_NAME,INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.UPDATE_RULE, INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.DELETE_RULE
|
11725
11735
|
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
11726
|
-
LEFT JOIN
|
11736
|
+
LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS on INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS.CONSTRAINT_NAME = INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME
|
11727
11737
|
WHERE INFORMATION_SCHEMA.KEY_COLUMN_USAGE.TABLE_SCHEMA = ? AND INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME != 'PRIMARY' and INFORMATION_SCHEMA.KEY_COLUMN_USAGE.REFERENCED_TABLE_NAME is not null;
|
11728
11738
|
`,
|
11729
11739
|
[inputSchema]
|
@@ -11888,10 +11898,9 @@ var pgSerializer_exports = {};
|
|
11888
11898
|
__export(pgSerializer_exports, {
|
11889
11899
|
fromDatabase: () => fromDatabase2,
|
11890
11900
|
generatePgSnapshot: () => generatePgSnapshot,
|
11891
|
-
indexName: () => indexName2
|
11892
|
-
toDrizzle: () => toDrizzle
|
11901
|
+
indexName: () => indexName2
|
11893
11902
|
});
|
11894
|
-
var import_pg_core2, import_pg_core3, import_drizzle_orm5, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn
|
11903
|
+
var import_pg_core2, import_pg_core3, import_drizzle_orm5, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
|
11895
11904
|
var init_pgSerializer = __esm({
|
11896
11905
|
"src/serializer/pgSerializer.ts"() {
|
11897
11906
|
import_pg_core2 = require("drizzle-orm/pg-core");
|
@@ -12521,108 +12530,6 @@ ${withStyle.errorWarning(
|
|
12521
12530
|
}
|
12522
12531
|
}
|
12523
12532
|
};
|
12524
|
-
toDrizzle = (schema4, schemaName) => {
|
12525
|
-
const tables = {};
|
12526
|
-
Object.values(schema4.tables).forEach((t) => {
|
12527
|
-
const columns = {};
|
12528
|
-
Object.values(t.columns).forEach((c) => {
|
12529
|
-
const columnName = c.name;
|
12530
|
-
const type = c.type;
|
12531
|
-
let columnBuilder;
|
12532
|
-
if (type === "bigint") {
|
12533
|
-
columnBuilder = new import_pg_core2.PgBigInt53Builder(columnName);
|
12534
|
-
} else if (type === "bigserial") {
|
12535
|
-
columnBuilder = new import_pg_core2.PgBigSerial53Builder(columnName);
|
12536
|
-
} else if (type === "boolean") {
|
12537
|
-
columnBuilder = new import_pg_core2.PgBooleanBuilder(columnName);
|
12538
|
-
} else if (type === "cidr") {
|
12539
|
-
columnBuilder = new import_pg_core2.PgCidrBuilder(columnName);
|
12540
|
-
} else if (type === "date") {
|
12541
|
-
columnBuilder = new import_pg_core2.PgDateBuilder(columnName);
|
12542
|
-
} else if (type === "double precision") {
|
12543
|
-
columnBuilder = new import_pg_core2.PgDoublePrecisionBuilder(columnName);
|
12544
|
-
} else if (type === "inet") {
|
12545
|
-
columnBuilder = new import_pg_core2.PgInetBuilder(columnName);
|
12546
|
-
} else if (type === "integer") {
|
12547
|
-
columnBuilder = new import_pg_core2.PgIntegerBuilder(columnName);
|
12548
|
-
} else if (type === "interval" || type.startsWith("interval ")) {
|
12549
|
-
columnBuilder = new import_pg_core2.PgIntervalBuilder(columnName, {});
|
12550
|
-
} else if (type === "json") {
|
12551
|
-
columnBuilder = new import_pg_core2.PgJsonBuilder(columnName);
|
12552
|
-
} else if (type === "jsonb") {
|
12553
|
-
columnBuilder = new import_pg_core2.PgJsonbBuilder(columnName);
|
12554
|
-
} else if (type === "macaddr") {
|
12555
|
-
columnBuilder = new import_pg_core2.PgMacaddrBuilder(columnName);
|
12556
|
-
} else if (type === "macaddr8") {
|
12557
|
-
columnBuilder = new import_pg_core2.PgMacaddr8Builder(columnName);
|
12558
|
-
} else if (type === "numeric" || type.startsWith("numeric(")) {
|
12559
|
-
columnBuilder = new import_pg_core2.PgNumericBuilder(columnName);
|
12560
|
-
} else if (type === "real") {
|
12561
|
-
columnBuilder = new import_pg_core2.PgRealBuilder(columnName);
|
12562
|
-
} else if (type === "serial") {
|
12563
|
-
columnBuilder = new import_pg_core2.PgSerialBuilder(columnName);
|
12564
|
-
} else if (type === "smallint") {
|
12565
|
-
columnBuilder = new import_pg_core2.PgSmallIntBuilder(columnName);
|
12566
|
-
} else if (type === "smallserial") {
|
12567
|
-
columnBuilder = new import_pg_core2.PgSmallSerialBuilder(columnName);
|
12568
|
-
} else if (type === "text") {
|
12569
|
-
columnBuilder = new import_pg_core2.PgTextBuilder(columnName, {});
|
12570
|
-
} else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
|
12571
|
-
columnBuilder = new import_pg_core2.PgTimeBuilder(columnName, false, void 0);
|
12572
|
-
} else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
|
12573
|
-
columnBuilder = new import_pg_core2.PgTimestampBuilder(columnName, false, void 0);
|
12574
|
-
} else if (type === "uuid") {
|
12575
|
-
columnBuilder = new import_pg_core2.PgUUIDBuilder(columnName);
|
12576
|
-
} else if (type === "varchar" || type.startsWith("varchar(")) {
|
12577
|
-
columnBuilder = new import_pg_core2.PgVarcharBuilder(columnName, {});
|
12578
|
-
} else if (type === "char" || type.startsWith("char(")) {
|
12579
|
-
columnBuilder = new import_pg_core2.PgCharBuilder(columnName, {});
|
12580
|
-
} else {
|
12581
|
-
columnBuilder = (0, import_pg_core2.customType)({
|
12582
|
-
dataType() {
|
12583
|
-
return type;
|
12584
|
-
}
|
12585
|
-
})(columnName);
|
12586
|
-
}
|
12587
|
-
if (c.notNull) {
|
12588
|
-
columnBuilder = columnBuilder.notNull();
|
12589
|
-
}
|
12590
|
-
if (c.default) {
|
12591
|
-
columnBuilder = columnBuilder.default(c.default);
|
12592
|
-
}
|
12593
|
-
if (c.primaryKey) {
|
12594
|
-
columnBuilder = columnBuilder.primaryKey();
|
12595
|
-
}
|
12596
|
-
columns[columnName] = columnBuilder;
|
12597
|
-
});
|
12598
|
-
if (schemaName === "public") {
|
12599
|
-
tables[t.name] = (0, import_pg_core2.pgTable)(t.name, columns, (cb) => {
|
12600
|
-
const res = {};
|
12601
|
-
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
12602
|
-
const gh = cpk.columns.map((c) => cb[c]);
|
12603
|
-
res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
|
12604
|
-
gh,
|
12605
|
-
cpk.name
|
12606
|
-
);
|
12607
|
-
});
|
12608
|
-
return res;
|
12609
|
-
});
|
12610
|
-
} else {
|
12611
|
-
tables[t.name] = (0, import_pg_core2.pgSchema)(schemaName).table(t.name, columns, (cb) => {
|
12612
|
-
const res = {};
|
12613
|
-
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
12614
|
-
const gh = cpk.columns.map((c) => cb[c]);
|
12615
|
-
res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
|
12616
|
-
gh,
|
12617
|
-
cpk.name
|
12618
|
-
);
|
12619
|
-
});
|
12620
|
-
return res;
|
12621
|
-
});
|
12622
|
-
}
|
12623
|
-
});
|
12624
|
-
return tables;
|
12625
|
-
};
|
12626
12533
|
}
|
12627
12534
|
});
|
12628
12535
|
|
@@ -12661,8 +12568,7 @@ var init_sqliteImports = __esm({
|
|
12661
12568
|
var sqliteSerializer_exports = {};
|
12662
12569
|
__export(sqliteSerializer_exports, {
|
12663
12570
|
fromDatabase: () => fromDatabase3,
|
12664
|
-
generateSqliteSnapshot: () => generateSqliteSnapshot
|
12665
|
-
toDrizzle: () => toDrizzle2
|
12571
|
+
generateSqliteSnapshot: () => generateSqliteSnapshot
|
12666
12572
|
});
|
12667
12573
|
function mapSqlToSqliteType(sqlType) {
|
12668
12574
|
if ([
|
@@ -12699,7 +12605,7 @@ function mapSqlToSqliteType(sqlType) {
|
|
12699
12605
|
return "numeric";
|
12700
12606
|
}
|
12701
12607
|
}
|
12702
|
-
var import_drizzle_orm7, import_sqlite_core2, dialect5, generateSqliteSnapshot, fromDatabase3
|
12608
|
+
var import_drizzle_orm7, import_sqlite_core2, dialect5, generateSqliteSnapshot, fromDatabase3;
|
12703
12609
|
var init_sqliteSerializer = __esm({
|
12704
12610
|
"src/serializer/sqliteSerializer.ts"() {
|
12705
12611
|
import_drizzle_orm7 = require("drizzle-orm");
|
@@ -13067,50 +12973,6 @@ WHERE
|
|
13067
12973
|
}
|
13068
12974
|
};
|
13069
12975
|
};
|
13070
|
-
toDrizzle2 = (schema4) => {
|
13071
|
-
const tables = {};
|
13072
|
-
Object.values(schema4.tables).forEach((t) => {
|
13073
|
-
const columns = {};
|
13074
|
-
Object.values(t.columns).forEach((c) => {
|
13075
|
-
const columnName = c.name;
|
13076
|
-
const type = c.type;
|
13077
|
-
let columnBuilder;
|
13078
|
-
if (type === "integer") {
|
13079
|
-
columnBuilder = new import_sqlite_core2.SQLiteIntegerBuilder(columnName);
|
13080
|
-
} else if (type === "text") {
|
13081
|
-
columnBuilder = new import_sqlite_core2.SQLiteTextBuilder(columnName, {});
|
13082
|
-
} else if (type === "blob") {
|
13083
|
-
columnBuilder = new import_sqlite_core2.SQLiteBlobBufferBuilder(columnName);
|
13084
|
-
} else if (type === "real") {
|
13085
|
-
columnBuilder = new import_sqlite_core2.SQLiteRealBuilder(columnName);
|
13086
|
-
} else {
|
13087
|
-
columnBuilder = new import_sqlite_core2.SQLiteNumericBuilder(columnName);
|
13088
|
-
}
|
13089
|
-
if (c.notNull) {
|
13090
|
-
columnBuilder = columnBuilder.notNull();
|
13091
|
-
}
|
13092
|
-
if (c.default) {
|
13093
|
-
columnBuilder = columnBuilder.default(c.default);
|
13094
|
-
}
|
13095
|
-
if (c.primaryKey) {
|
13096
|
-
columnBuilder = columnBuilder.primaryKey();
|
13097
|
-
}
|
13098
|
-
columns[columnName] = columnBuilder;
|
13099
|
-
});
|
13100
|
-
tables[t.name] = (0, import_sqlite_core2.sqliteTable)(t.name, columns, (cb) => {
|
13101
|
-
const res = {};
|
13102
|
-
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
13103
|
-
const gh = cpk.columns.map((c) => cb[c]);
|
13104
|
-
res[cpk.name] = new import_sqlite_core2.PrimaryKeyBuilder(
|
13105
|
-
gh,
|
13106
|
-
cpk.name
|
13107
|
-
);
|
13108
|
-
});
|
13109
|
-
return res;
|
13110
|
-
});
|
13111
|
-
});
|
13112
|
-
return tables;
|
13113
|
-
};
|
13114
12976
|
}
|
13115
12977
|
});
|
13116
12978
|
|
@@ -14622,6 +14484,7 @@ var init_words = __esm({
|
|
14622
14484
|
var migrate_exports = {};
|
14623
14485
|
__export(migrate_exports, {
|
14624
14486
|
BREAKPOINT: () => BREAKPOINT,
|
14487
|
+
embeddedMigrations: () => embeddedMigrations,
|
14625
14488
|
prepareAndMigrateMySql: () => prepareAndMigrateMySql,
|
14626
14489
|
prepareAndMigratePg: () => prepareAndMigratePg,
|
14627
14490
|
prepareAndMigrateSqlite: () => prepareAndMigrateSqlite,
|
@@ -14632,7 +14495,7 @@ __export(migrate_exports, {
|
|
14632
14495
|
prepareSnapshotFolderName: () => prepareSnapshotFolderName,
|
14633
14496
|
writeResult: () => writeResult
|
14634
14497
|
});
|
14635
|
-
var import_fs3, import_path2, import_hanji3, prepareAndMigratePg, prepareMySQLPush, prepareSQLitePush, preparePgPush, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, BREAKPOINT, writeResult, prepareSnapshotFolderName, two;
|
14498
|
+
var import_fs3, import_path2, import_hanji3, prepareAndMigratePg, prepareMySQLPush, prepareSQLitePush, preparePgPush, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
|
14636
14499
|
var init_migrate = __esm({
|
14637
14500
|
"src/cli/commands/migrate.ts"() {
|
14638
14501
|
import_fs3 = __toESM(require("fs"));
|
@@ -14661,19 +14524,14 @@ var init_migrate = __esm({
|
|
14661
14524
|
const validatedPrev = pgSchema.parse(prev);
|
14662
14525
|
const validatedCur = pgSchema.parse(cur);
|
14663
14526
|
if (config.custom) {
|
14664
|
-
writeResult(
|
14665
|
-
custom,
|
14666
|
-
[],
|
14527
|
+
writeResult({
|
14528
|
+
cur: custom,
|
14529
|
+
sqlStatements: [],
|
14667
14530
|
journal,
|
14668
|
-
{
|
14669
|
-
columns: {},
|
14670
|
-
schemas: {},
|
14671
|
-
tables: {}
|
14672
|
-
},
|
14673
14531
|
outFolder,
|
14674
|
-
config.breakpoints,
|
14675
|
-
"custom"
|
14676
|
-
);
|
14532
|
+
breakpoints: config.breakpoints,
|
14533
|
+
type: "custom"
|
14534
|
+
});
|
14677
14535
|
return;
|
14678
14536
|
}
|
14679
14537
|
const squashedPrev = squashPgScheme(validatedPrev);
|
@@ -14685,14 +14543,13 @@ var init_migrate = __esm({
|
|
14685
14543
|
validatedPrev,
|
14686
14544
|
validatedCur
|
14687
14545
|
);
|
14688
|
-
writeResult(
|
14546
|
+
writeResult({
|
14689
14547
|
cur,
|
14690
14548
|
sqlStatements,
|
14691
14549
|
journal,
|
14692
|
-
_meta,
|
14693
14550
|
outFolder,
|
14694
|
-
config.breakpoints
|
14695
|
-
);
|
14551
|
+
breakpoints: config.breakpoints
|
14552
|
+
});
|
14696
14553
|
} catch (e) {
|
14697
14554
|
console.error(e);
|
14698
14555
|
}
|
@@ -14786,19 +14643,14 @@ var init_migrate = __esm({
|
|
14786
14643
|
const validatedPrev = mysqlSchema.parse(prev);
|
14787
14644
|
const validatedCur = mysqlSchema.parse(cur);
|
14788
14645
|
if (config.custom) {
|
14789
|
-
writeResult(
|
14790
|
-
custom,
|
14791
|
-
[],
|
14646
|
+
writeResult({
|
14647
|
+
cur: custom,
|
14648
|
+
sqlStatements: [],
|
14792
14649
|
journal,
|
14793
|
-
{
|
14794
|
-
columns: {},
|
14795
|
-
schemas: {},
|
14796
|
-
tables: {}
|
14797
|
-
},
|
14798
14650
|
outFolder,
|
14799
|
-
config.breakpoints,
|
14800
|
-
"custom"
|
14801
|
-
);
|
14651
|
+
breakpoints: config.breakpoints,
|
14652
|
+
type: "custom"
|
14653
|
+
});
|
14802
14654
|
return;
|
14803
14655
|
}
|
14804
14656
|
const squashedPrev = squashMysqlScheme(validatedPrev);
|
@@ -14810,14 +14662,14 @@ var init_migrate = __esm({
|
|
14810
14662
|
validatedPrev,
|
14811
14663
|
validatedCur
|
14812
14664
|
);
|
14813
|
-
writeResult(
|
14665
|
+
writeResult({
|
14814
14666
|
cur,
|
14815
14667
|
sqlStatements,
|
14816
14668
|
journal,
|
14817
14669
|
_meta,
|
14818
14670
|
outFolder,
|
14819
|
-
config.breakpoints
|
14820
|
-
);
|
14671
|
+
breakpoints: config.breakpoints
|
14672
|
+
});
|
14821
14673
|
} catch (e) {
|
14822
14674
|
console.error(e);
|
14823
14675
|
}
|
@@ -14835,19 +14687,15 @@ var init_migrate = __esm({
|
|
14835
14687
|
const validatedPrev = sqliteSchema.parse(prev);
|
14836
14688
|
const validatedCur = sqliteSchema.parse(cur);
|
14837
14689
|
if (config.custom) {
|
14838
|
-
writeResult(
|
14839
|
-
custom,
|
14840
|
-
[],
|
14690
|
+
writeResult({
|
14691
|
+
cur: custom,
|
14692
|
+
sqlStatements: [],
|
14841
14693
|
journal,
|
14842
|
-
{
|
14843
|
-
columns: {},
|
14844
|
-
schemas: {},
|
14845
|
-
tables: {}
|
14846
|
-
},
|
14847
14694
|
outFolder,
|
14848
|
-
config.breakpoints,
|
14849
|
-
|
14850
|
-
|
14695
|
+
breakpoints: config.breakpoints,
|
14696
|
+
bundle: config.bundle,
|
14697
|
+
type: "custom"
|
14698
|
+
});
|
14851
14699
|
return;
|
14852
14700
|
}
|
14853
14701
|
const squashedPrev = squashSqliteScheme(validatedPrev);
|
@@ -14857,14 +14705,15 @@ var init_migrate = __esm({
|
|
14857
14705
|
squashedCur,
|
14858
14706
|
"sqlite"
|
14859
14707
|
);
|
14860
|
-
writeResult(
|
14708
|
+
writeResult({
|
14861
14709
|
cur,
|
14862
14710
|
sqlStatements,
|
14863
14711
|
journal,
|
14864
14712
|
_meta,
|
14865
14713
|
outFolder,
|
14866
|
-
config.breakpoints
|
14867
|
-
|
14714
|
+
breakpoints: config.breakpoints,
|
14715
|
+
bundle: config.bundle
|
14716
|
+
});
|
14868
14717
|
} catch (e) {
|
14869
14718
|
console.error(e);
|
14870
14719
|
}
|
@@ -15052,7 +14901,20 @@ var init_migrate = __esm({
|
|
15052
14901
|
return result;
|
15053
14902
|
};
|
15054
14903
|
BREAKPOINT = "--> statement-breakpoint\n";
|
15055
|
-
writeResult = (
|
14904
|
+
writeResult = ({
|
14905
|
+
cur,
|
14906
|
+
sqlStatements,
|
14907
|
+
journal,
|
14908
|
+
_meta = {
|
14909
|
+
columns: {},
|
14910
|
+
schemas: {},
|
14911
|
+
tables: {}
|
14912
|
+
},
|
14913
|
+
outFolder,
|
14914
|
+
breakpoints,
|
14915
|
+
bundle = false,
|
14916
|
+
type = "none"
|
14917
|
+
}) => {
|
15056
14918
|
if (type === "none") {
|
15057
14919
|
console.log(schema(cur));
|
15058
14920
|
if (sqlStatements.length === 0) {
|
@@ -15093,6 +14955,10 @@ ${sql2}
|
|
15093
14955
|
});
|
15094
14956
|
import_fs3.default.writeFileSync(metaJournal, JSON.stringify(journal, null, 2));
|
15095
14957
|
import_fs3.default.writeFileSync(`${outFolder}/${tag}.sql`, sql2);
|
14958
|
+
if (bundle) {
|
14959
|
+
const js = embeddedMigrations(journal);
|
14960
|
+
import_fs3.default.writeFileSync(`${outFolder}/migrations.js`, js);
|
14961
|
+
}
|
15096
14962
|
(0, import_hanji3.render)(
|
15097
14963
|
`[${source_default.green(
|
15098
14964
|
"\u2713"
|
@@ -15101,6 +14967,23 @@ ${sql2}
|
|
15101
14967
|
)} \u{1F680}`
|
15102
14968
|
);
|
15103
14969
|
};
|
14970
|
+
embeddedMigrations = (journal) => {
|
14971
|
+
let content = "// This file is required for Expo/React Native SQLite migrations - https://orm.drizzle.team/quick-sqlite/expo\n\n";
|
14972
|
+
content += "import journal from './meta/_journal.json';\n";
|
14973
|
+
journal.entries.forEach((entry) => {
|
14974
|
+
content += `import m${entry.idx.toString().padStart(4, "0")} from './${entry.tag}.sql';
|
14975
|
+
`;
|
14976
|
+
});
|
14977
|
+
content += `
|
14978
|
+
export default {
|
14979
|
+
journal,
|
14980
|
+
migrations: {
|
14981
|
+
${journal.entries.map((it) => `m${it.idx.toString().padStart(4, "0")}`).join(",\n")}
|
14982
|
+
}
|
14983
|
+
}
|
14984
|
+
`;
|
14985
|
+
return content;
|
14986
|
+
};
|
15104
14987
|
prepareSnapshotFolderName = () => {
|
15105
14988
|
const now = /* @__PURE__ */ new Date();
|
15106
14989
|
return `${now.getFullYear()}${two(now.getUTCMonth() + 1)}${two(
|
@@ -24877,6 +24760,161 @@ var init_sqliteIntrospect = __esm({
|
|
24877
24760
|
}
|
24878
24761
|
});
|
24879
24762
|
|
24763
|
+
// src/serializer/schemaToDrizzle.ts
|
24764
|
+
var import_pg_core4, import_sqlite_core3, pgSchemaToDrizzle, sqliteSchemaToDrizzle;
|
24765
|
+
var init_schemaToDrizzle = __esm({
|
24766
|
+
"src/serializer/schemaToDrizzle.ts"() {
|
24767
|
+
import_pg_core4 = require("drizzle-orm/pg-core");
|
24768
|
+
import_sqlite_core3 = require("drizzle-orm/sqlite-core");
|
24769
|
+
pgSchemaToDrizzle = (schema4, schemaName) => {
|
24770
|
+
const tables = {};
|
24771
|
+
Object.values(schema4.tables).forEach((t) => {
|
24772
|
+
const columns = {};
|
24773
|
+
Object.values(t.columns).forEach((c) => {
|
24774
|
+
const columnName = c.name;
|
24775
|
+
const type = c.type;
|
24776
|
+
let columnBuilder;
|
24777
|
+
if (type === "bigint") {
|
24778
|
+
columnBuilder = new import_pg_core4.PgBigInt53Builder(columnName);
|
24779
|
+
} else if (type === "bigserial") {
|
24780
|
+
columnBuilder = new import_pg_core4.PgBigSerial53Builder(columnName);
|
24781
|
+
} else if (type === "boolean") {
|
24782
|
+
columnBuilder = new import_pg_core4.PgBooleanBuilder(columnName);
|
24783
|
+
} else if (type === "cidr") {
|
24784
|
+
columnBuilder = new import_pg_core4.PgCidrBuilder(columnName);
|
24785
|
+
} else if (type === "date") {
|
24786
|
+
columnBuilder = new import_pg_core4.PgDateBuilder(columnName);
|
24787
|
+
} else if (type === "double precision") {
|
24788
|
+
columnBuilder = new import_pg_core4.PgDoublePrecisionBuilder(columnName);
|
24789
|
+
} else if (type === "inet") {
|
24790
|
+
columnBuilder = new import_pg_core4.PgInetBuilder(columnName);
|
24791
|
+
} else if (type === "integer") {
|
24792
|
+
columnBuilder = new import_pg_core4.PgIntegerBuilder(columnName);
|
24793
|
+
} else if (type === "interval" || type.startsWith("interval ")) {
|
24794
|
+
columnBuilder = new import_pg_core4.PgIntervalBuilder(columnName, {});
|
24795
|
+
} else if (type === "json") {
|
24796
|
+
columnBuilder = new import_pg_core4.PgJsonBuilder(columnName);
|
24797
|
+
} else if (type === "jsonb") {
|
24798
|
+
columnBuilder = new import_pg_core4.PgJsonbBuilder(columnName);
|
24799
|
+
} else if (type === "macaddr") {
|
24800
|
+
columnBuilder = new import_pg_core4.PgMacaddrBuilder(columnName);
|
24801
|
+
} else if (type === "macaddr8") {
|
24802
|
+
columnBuilder = new import_pg_core4.PgMacaddr8Builder(columnName);
|
24803
|
+
} else if (type === "numeric" || type.startsWith("numeric(")) {
|
24804
|
+
columnBuilder = new import_pg_core4.PgNumericBuilder(columnName);
|
24805
|
+
} else if (type === "real") {
|
24806
|
+
columnBuilder = new import_pg_core4.PgRealBuilder(columnName);
|
24807
|
+
} else if (type === "serial") {
|
24808
|
+
columnBuilder = new import_pg_core4.PgSerialBuilder(columnName);
|
24809
|
+
} else if (type === "smallint") {
|
24810
|
+
columnBuilder = new import_pg_core4.PgSmallIntBuilder(columnName);
|
24811
|
+
} else if (type === "smallserial") {
|
24812
|
+
columnBuilder = new import_pg_core4.PgSmallSerialBuilder(columnName);
|
24813
|
+
} else if (type === "text") {
|
24814
|
+
columnBuilder = new import_pg_core4.PgTextBuilder(columnName, {});
|
24815
|
+
} else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
|
24816
|
+
columnBuilder = new import_pg_core4.PgTimeBuilder(columnName, false, void 0);
|
24817
|
+
} else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
|
24818
|
+
columnBuilder = new import_pg_core4.PgTimestampBuilder(columnName, false, void 0);
|
24819
|
+
} else if (type === "uuid") {
|
24820
|
+
columnBuilder = new import_pg_core4.PgUUIDBuilder(columnName);
|
24821
|
+
} else if (type === "varchar" || type.startsWith("varchar(")) {
|
24822
|
+
columnBuilder = new import_pg_core4.PgVarcharBuilder(columnName, {});
|
24823
|
+
} else if (type === "char" || type.startsWith("char(")) {
|
24824
|
+
columnBuilder = new import_pg_core4.PgCharBuilder(columnName, {});
|
24825
|
+
} else {
|
24826
|
+
columnBuilder = (0, import_pg_core4.customType)({
|
24827
|
+
dataType() {
|
24828
|
+
return type;
|
24829
|
+
}
|
24830
|
+
})(columnName);
|
24831
|
+
}
|
24832
|
+
if (c.notNull) {
|
24833
|
+
columnBuilder = columnBuilder.notNull();
|
24834
|
+
}
|
24835
|
+
if (c.default) {
|
24836
|
+
columnBuilder = columnBuilder.default(c.default);
|
24837
|
+
}
|
24838
|
+
if (c.primaryKey) {
|
24839
|
+
columnBuilder = columnBuilder.primaryKey();
|
24840
|
+
}
|
24841
|
+
columns[columnName] = columnBuilder;
|
24842
|
+
});
|
24843
|
+
if (schemaName === "public") {
|
24844
|
+
tables[t.name] = (0, import_pg_core4.pgTable)(t.name, columns, (cb) => {
|
24845
|
+
const res = {};
|
24846
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
24847
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
24848
|
+
res[cpk.name] = new import_pg_core4.PrimaryKeyBuilder(
|
24849
|
+
gh,
|
24850
|
+
cpk.name
|
24851
|
+
);
|
24852
|
+
});
|
24853
|
+
return res;
|
24854
|
+
});
|
24855
|
+
} else {
|
24856
|
+
tables[t.name] = (0, import_pg_core4.pgSchema)(schemaName).table(t.name, columns, (cb) => {
|
24857
|
+
const res = {};
|
24858
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
24859
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
24860
|
+
res[cpk.name] = new import_pg_core4.PrimaryKeyBuilder(
|
24861
|
+
gh,
|
24862
|
+
cpk.name
|
24863
|
+
);
|
24864
|
+
});
|
24865
|
+
return res;
|
24866
|
+
});
|
24867
|
+
}
|
24868
|
+
});
|
24869
|
+
return tables;
|
24870
|
+
};
|
24871
|
+
sqliteSchemaToDrizzle = (schema4) => {
|
24872
|
+
const tables = {};
|
24873
|
+
Object.values(schema4.tables).forEach((t) => {
|
24874
|
+
const columns = {};
|
24875
|
+
Object.values(t.columns).forEach((c) => {
|
24876
|
+
const columnName = c.name;
|
24877
|
+
const type = c.type;
|
24878
|
+
let columnBuilder;
|
24879
|
+
if (type === "integer") {
|
24880
|
+
columnBuilder = new import_sqlite_core3.SQLiteIntegerBuilder(columnName);
|
24881
|
+
} else if (type === "text") {
|
24882
|
+
columnBuilder = new import_sqlite_core3.SQLiteTextBuilder(columnName, {});
|
24883
|
+
} else if (type === "blob") {
|
24884
|
+
columnBuilder = new import_sqlite_core3.SQLiteBlobBufferBuilder(columnName);
|
24885
|
+
} else if (type === "real") {
|
24886
|
+
columnBuilder = new import_sqlite_core3.SQLiteRealBuilder(columnName);
|
24887
|
+
} else {
|
24888
|
+
columnBuilder = new import_sqlite_core3.SQLiteNumericBuilder(columnName);
|
24889
|
+
}
|
24890
|
+
if (c.notNull) {
|
24891
|
+
columnBuilder = columnBuilder.notNull();
|
24892
|
+
}
|
24893
|
+
if (c.default) {
|
24894
|
+
columnBuilder = columnBuilder.default(c.default);
|
24895
|
+
}
|
24896
|
+
if (c.primaryKey) {
|
24897
|
+
columnBuilder = columnBuilder.primaryKey();
|
24898
|
+
}
|
24899
|
+
columns[columnName] = columnBuilder;
|
24900
|
+
});
|
24901
|
+
tables[t.name] = (0, import_sqlite_core3.sqliteTable)(t.name, columns, (cb) => {
|
24902
|
+
const res = {};
|
24903
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
24904
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
24905
|
+
res[cpk.name] = new import_sqlite_core3.PrimaryKeyBuilder(
|
24906
|
+
gh,
|
24907
|
+
cpk.name
|
24908
|
+
);
|
24909
|
+
});
|
24910
|
+
return res;
|
24911
|
+
});
|
24912
|
+
});
|
24913
|
+
return tables;
|
24914
|
+
};
|
24915
|
+
}
|
24916
|
+
});
|
24917
|
+
|
24880
24918
|
// node_modules/.pnpm/semver@7.5.4/node_modules/semver/internal/constants.js
|
24881
24919
|
var require_constants = __commonJS({
|
24882
24920
|
"node_modules/.pnpm/semver@7.5.4/node_modules/semver/internal/constants.js"(exports, module2) {
|
@@ -43220,15 +43258,15 @@ var require_promise = __commonJS({
|
|
43220
43258
|
});
|
43221
43259
|
|
43222
43260
|
// src/orm-extenstions/d1-driver/session.ts
|
43223
|
-
var import_drizzle_orm10, import_drizzle_orm11, import_drizzle_orm12,
|
43261
|
+
var import_drizzle_orm10, import_drizzle_orm11, import_drizzle_orm12, import_sqlite_core4, import_drizzle_orm13, _a, SQLiteWranglerD1Session, _a2, PreparedQuery;
|
43224
43262
|
var init_session = __esm({
|
43225
43263
|
"src/orm-extenstions/d1-driver/session.ts"() {
|
43226
43264
|
import_drizzle_orm10 = require("drizzle-orm");
|
43227
43265
|
import_drizzle_orm11 = require("drizzle-orm");
|
43228
43266
|
import_drizzle_orm12 = require("drizzle-orm");
|
43229
|
-
|
43267
|
+
import_sqlite_core4 = require("drizzle-orm/sqlite-core");
|
43230
43268
|
import_drizzle_orm13 = require("drizzle-orm");
|
43231
|
-
SQLiteWranglerD1Session = class extends
|
43269
|
+
SQLiteWranglerD1Session = class extends import_sqlite_core4.SQLiteSession {
|
43232
43270
|
constructor(client, configPath, dbName, dialect6, schema4, options = {}) {
|
43233
43271
|
super(dialect6);
|
43234
43272
|
this.client = client;
|
@@ -43257,7 +43295,7 @@ var init_session = __esm({
|
|
43257
43295
|
};
|
43258
43296
|
_a = import_drizzle_orm10.entityKind;
|
43259
43297
|
SQLiteWranglerD1Session[_a] = "SQLiteD1Session";
|
43260
|
-
PreparedQuery = class extends
|
43298
|
+
PreparedQuery = class extends import_sqlite_core4.SQLitePreparedQuery {
|
43261
43299
|
constructor(stmt, configPath, dbName, queryString, params, logger, fields, executeMethod, customResultMapper) {
|
43262
43300
|
super("async", executeMethod, {
|
43263
43301
|
sql: queryString,
|
@@ -43382,20 +43420,20 @@ function drizzle(client, configPath, dbName, config = {}) {
|
|
43382
43420
|
const session = new SQLiteWranglerD1Session(client, configPath, dbName, dialect6, schema4, {
|
43383
43421
|
logger
|
43384
43422
|
});
|
43385
|
-
return new
|
43423
|
+
return new import_sqlite_core5.BaseSQLiteDatabase(
|
43386
43424
|
"async",
|
43387
43425
|
dialect6,
|
43388
43426
|
session,
|
43389
43427
|
schema4
|
43390
43428
|
);
|
43391
43429
|
}
|
43392
|
-
var import_drizzle_orm14,
|
43430
|
+
var import_drizzle_orm14, import_sqlite_core5, WranglerDialect;
|
43393
43431
|
var init_driver = __esm({
|
43394
43432
|
"src/orm-extenstions/d1-driver/driver.ts"() {
|
43395
43433
|
import_drizzle_orm14 = require("drizzle-orm");
|
43396
|
-
|
43434
|
+
import_sqlite_core5 = require("drizzle-orm/sqlite-core");
|
43397
43435
|
init_session();
|
43398
|
-
WranglerDialect = class extends
|
43436
|
+
WranglerDialect = class extends import_sqlite_core5.SQLiteAsyncDialect {
|
43399
43437
|
sqlToQuery(sql2) {
|
43400
43438
|
return sql2.toQuery({
|
43401
43439
|
escapeName: this.escapeName,
|
@@ -58711,13 +58749,13 @@ var init_wrangler_client = __esm({
|
|
58711
58749
|
});
|
58712
58750
|
|
58713
58751
|
// src/serializer/studioUtils.ts
|
58714
|
-
var import_drizzle_orm15, import_mysql_core4,
|
58752
|
+
var import_drizzle_orm15, import_mysql_core4, import_pg_core5, import_sqlite_core6, drizzleDb;
|
58715
58753
|
var init_studioUtils = __esm({
|
58716
58754
|
"src/serializer/studioUtils.ts"() {
|
58717
58755
|
import_drizzle_orm15 = require("drizzle-orm");
|
58718
58756
|
import_mysql_core4 = require("drizzle-orm/mysql-core");
|
58719
|
-
|
58720
|
-
|
58757
|
+
import_pg_core5 = require("drizzle-orm/pg-core");
|
58758
|
+
import_sqlite_core6 = require("drizzle-orm/sqlite-core");
|
58721
58759
|
init_utils();
|
58722
58760
|
init_utils3();
|
58723
58761
|
init_global();
|
@@ -58826,8 +58864,7 @@ var init_utils5 = __esm({
|
|
58826
58864
|
init_pgIntrospect();
|
58827
58865
|
init_pgPushUtils();
|
58828
58866
|
init_sqliteIntrospect();
|
58829
|
-
|
58830
|
-
init_pgSerializer();
|
58867
|
+
init_schemaToDrizzle();
|
58831
58868
|
init_studioUtils();
|
58832
58869
|
init_pgConnect();
|
58833
58870
|
assertV1OutFolder = (out, dialect6) => {
|
@@ -59146,7 +59183,7 @@ var init_utils5 = __esm({
|
|
59146
59183
|
preparedConnection.client,
|
59147
59184
|
[]
|
59148
59185
|
);
|
59149
|
-
const models =
|
59186
|
+
const models = sqliteSchemaToDrizzle(schema4);
|
59150
59187
|
const drizzleDbInstance = await drizzleDb(
|
59151
59188
|
connection,
|
59152
59189
|
{ sqliteSchema: models },
|
@@ -59171,7 +59208,7 @@ var init_utils5 = __esm({
|
|
59171
59208
|
[],
|
59172
59209
|
[schemaName]
|
59173
59210
|
);
|
59174
|
-
const models =
|
59211
|
+
const models = pgSchemaToDrizzle(schema4, schemaName);
|
59175
59212
|
response[schemaName] = await drizzleDb(
|
59176
59213
|
// @ts-ignore I don't know how to fix it yet. But will find a way
|
59177
59214
|
connection,
|