drizzle-kit 0.20.0-029419a → 0.20.0-13160ca
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/cli/commands/pgIntrospect.d.ts +1 -0
- package/cli/commands/sqliteIntrospect.d.ts +3 -3
- package/cli/utils.d.ts +11 -0
- package/cli/views.d.ts +2 -2
- package/drivers/index.d.ts +3 -3
- package/index.cjs +219 -154
- package/package.json +2 -2
- package/serializer/index.d.ts +4 -4
- package/serializer/pgSerializer.d.ts +4 -4
- package/serializer/sqliteSerializer.d.ts +2 -2
- package/serializer/studioUtils.d.ts +5 -1
- package/sqlite-introspect.d.ts +2 -2
- package/utils-studio.d.ts +3 -0
- package/utils-studio.js +377 -18
- package/utils.d.ts +2 -22
- package/utils.js +2391 -1637
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-kit",
|
|
3
|
-
"version": "0.20.0-
|
|
3
|
+
"version": "0.20.0-13160ca",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Drizzle Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
]
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@drizzle-team/studio": "^0.0.
|
|
57
|
+
"@drizzle-team/studio": "^0.0.17",
|
|
58
58
|
"@esbuild-kit/esm-loader": "^2.5.5",
|
|
59
59
|
"camelcase": "^7.0.1",
|
|
60
60
|
"chalk": "^5.2.0",
|
package/serializer/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PgSchemaInternal } from "./pgSchema";
|
|
2
|
-
import { SQLiteSchemaInternal } from "./sqliteSchema";
|
|
3
|
-
import { MySqlSchemaInternal } from "./mysqlSchema";
|
|
4
|
-
import { SQL } from "drizzle-orm";
|
|
1
|
+
import type { PgSchemaInternal } from "./pgSchema";
|
|
2
|
+
import type { SQLiteSchemaInternal } from "./sqliteSchema";
|
|
3
|
+
import type { MySqlSchemaInternal } from "./mysqlSchema";
|
|
4
|
+
import type { SQL } from "drizzle-orm";
|
|
5
5
|
export declare const sqlToStr: (sql: SQL) => string;
|
|
6
6
|
export declare const serializeMySql: (path: string | string[]) => Promise<MySqlSchemaInternal>;
|
|
7
7
|
export declare const serializePg: (path: string | string[], schemaFilter?: string[]) => Promise<PgSchemaInternal>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AnyPgTable, PgEnum, PgSchema } from "drizzle-orm/pg-core";
|
|
2
2
|
import { Relations } from "drizzle-orm";
|
|
3
|
-
import { IntrospectStage, IntrospectStatus } from "
|
|
4
|
-
import { PgSchemaInternal } from "
|
|
5
|
-
import type { DrizzleDbClient } from "
|
|
3
|
+
import type { IntrospectStage, IntrospectStatus } from "../cli/views";
|
|
4
|
+
import type { PgSchemaInternal } from "../serializer/pgSchema";
|
|
5
|
+
import type { DrizzleDbClient } from "../drivers";
|
|
6
6
|
export declare const indexName: (tableName: string, columns: string[]) => string;
|
|
7
7
|
export declare const generatePgSnapshot: (tables: AnyPgTable[], enums: PgEnum<any>[], schemas: PgSchema[], schemaFilter?: string[]) => PgSchemaInternal;
|
|
8
8
|
export declare const fromDatabase: (db: DrizzleDbClient, tablesFilter: ((table: string) => boolean) | undefined, schemaFilters: string[], progressCallback?: ((stage: IntrospectStage, count: number, status: IntrospectStatus) => void) | undefined) => Promise<PgSchemaInternal>;
|
|
9
|
-
export declare const toDrizzle: (schema: PgSchemaInternal) => Record<string, AnyPgTable | Relations>;
|
|
9
|
+
export declare const toDrizzle: (schema: PgSchemaInternal, schemaName: string) => Record<string, AnyPgTable | Relations>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SQLiteSchemaInternal } from "
|
|
1
|
+
import type { SQLiteSchemaInternal } from "../serializer/sqliteSchema";
|
|
2
2
|
import { Relations } from "drizzle-orm";
|
|
3
3
|
import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
4
|
-
import { IntrospectStage, IntrospectStatus } from "src/cli/views";
|
|
4
|
+
import type { IntrospectStage, IntrospectStatus } from "src/cli/views";
|
|
5
5
|
import type { DrizzleDbClient } from "src/drivers";
|
|
6
6
|
export declare const generateSqliteSnapshot: (tables: AnySQLiteTable[], enums: any[]) => SQLiteSchemaInternal;
|
|
7
7
|
export declare const fromDatabase: (db: DrizzleDbClient, tablesFilter?: (table: string) => boolean, progressCallback?: ((stage: IntrospectStage, count: number, status: IntrospectStatus) => void) | undefined) => Promise<SQLiteSchemaInternal>;
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
+
import type { Setup } from "@drizzle-team/studio";
|
|
1
2
|
import { Relations } from "drizzle-orm";
|
|
2
3
|
import { AnyMySqlTable } from "drizzle-orm/mysql-core";
|
|
3
4
|
import { AnyPgTable } from "drizzle-orm/pg-core";
|
|
4
5
|
import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
|
6
|
+
import type { Pool } from "pg";
|
|
7
|
+
import { PgConnectionConfig } from "src/cli/validations/pg";
|
|
5
8
|
import { StudioConfigConnections } from "src/cli/validations/studio";
|
|
6
9
|
export declare const prepareModels: (path: string | string[]) => Promise<{
|
|
7
10
|
pgSchema: Record<string, AnyPgTable<{}> | Relations<string, Record<string, import("drizzle-orm").Relation<string>>>>;
|
|
8
11
|
mysqlSchema: Record<string, AnyMySqlTable<{}> | Relations<string, Record<string, import("drizzle-orm").Relation<string>>>>;
|
|
9
12
|
sqliteSchema: Record<string, Relations<string, Record<string, import("drizzle-orm").Relation<string>>> | AnySQLiteTable<{}>>;
|
|
10
13
|
}>;
|
|
14
|
+
export declare const drizzleForPostgres: (connectionConfig: PgConnectionConfig, pgSchema: Record<string, AnyPgTable | Relations>, verbose: boolean) => Promise<Setup>;
|
|
11
15
|
export declare const drizzleDb: (drizzleConfig: StudioConfigConnections, models: {
|
|
12
16
|
pgSchema?: Record<string, AnyPgTable | Relations>;
|
|
13
17
|
mysqlSchema?: Record<string, AnyMySqlTable | Relations>;
|
|
14
18
|
sqliteSchema?: Record<string, AnySQLiteTable | Relations>;
|
|
15
|
-
}, logger: boolean) => Promise<{
|
|
19
|
+
}, logger: boolean, pgClient?: Pool) => Promise<{
|
|
16
20
|
db: import("drizzle-orm/node-postgres").NodePgDatabase<Record<string, never>>;
|
|
17
21
|
type: "pg";
|
|
18
22
|
schema: Record<string, AnyPgTable<{}> | Relations<string, Record<string, import("drizzle-orm").Relation<string>>>> | undefined;
|
package/sqlite-introspect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./@types/utils";
|
|
2
|
-
import { ConfigIntrospectCasing } from "./cli/commands/utils";
|
|
3
|
-
import { SQLiteSchema } from "./serializer/sqliteSchema";
|
|
2
|
+
import type { ConfigIntrospectCasing } from "./cli/commands/utils";
|
|
3
|
+
import type { SQLiteSchema } from "./serializer/sqliteSchema";
|
|
4
4
|
export declare const indexName: (tableName: string, columns: string[]) => string;
|
|
5
5
|
export declare const schemaToTypeScript: (schema: SQLiteSchema, casing: ConfigIntrospectCasing["casing"]) => string;
|
package/utils-studio.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { toDrizzle as drizzleSchemaPg } from "./serializer/pgSerializer";
|
|
2
|
+
export { toDrizzle as drizzleSchemaSQLite } from "./serializer/sqliteSerializer";
|
|
3
|
+
export { sqlitePushIntrospect } from "./cli/commands/sqliteIntrospect";
|
|
2
4
|
export { pgPushIntrospect } from "./cli/commands/pgIntrospect";
|
|
5
|
+
export { DrizzleORMPgClient } from "./drivers";
|
package/utils-studio.js
CHANGED
|
@@ -560,13 +560,12 @@ var init_outputs = __esm({
|
|
|
560
560
|
});
|
|
561
561
|
|
|
562
562
|
// src/serializer/pgSerializer.ts
|
|
563
|
-
var import_pg_core, import_pg_core2, import_drizzle_orm,
|
|
563
|
+
var import_pg_core, import_pg_core2, import_drizzle_orm, dialect, trimChar, fromDatabase, columnToDefault, defaultForColumn, toDrizzle;
|
|
564
564
|
var init_pgSerializer = __esm({
|
|
565
565
|
"src/serializer/pgSerializer.ts"() {
|
|
566
566
|
import_pg_core = require("drizzle-orm/pg-core");
|
|
567
567
|
import_pg_core2 = require("drizzle-orm/pg-core");
|
|
568
568
|
import_drizzle_orm = require("drizzle-orm");
|
|
569
|
-
import_drizzle_orm2 = require("drizzle-orm");
|
|
570
569
|
init_serializer();
|
|
571
570
|
init_source();
|
|
572
571
|
init_outputs();
|
|
@@ -968,7 +967,7 @@ var init_pgSerializer = __esm({
|
|
|
968
967
|
}
|
|
969
968
|
}
|
|
970
969
|
};
|
|
971
|
-
toDrizzle = (schema) => {
|
|
970
|
+
toDrizzle = (schema, schemaName) => {
|
|
972
971
|
const tables = {};
|
|
973
972
|
Object.values(schema.tables).forEach((t) => {
|
|
974
973
|
const columns = {};
|
|
@@ -1042,11 +1041,311 @@ var init_pgSerializer = __esm({
|
|
|
1042
1041
|
}
|
|
1043
1042
|
columns[columnName] = columnBuilder;
|
|
1044
1043
|
});
|
|
1045
|
-
|
|
1044
|
+
if (schemaName === "public") {
|
|
1045
|
+
tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
|
|
1046
|
+
const res = {};
|
|
1047
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
|
1048
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
|
1049
|
+
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
|
1050
|
+
gh,
|
|
1051
|
+
cpk.name
|
|
1052
|
+
);
|
|
1053
|
+
});
|
|
1054
|
+
return res;
|
|
1055
|
+
});
|
|
1056
|
+
} else {
|
|
1057
|
+
tables[t.name] = (0, import_pg_core.pgSchema)(schemaName).table(t.name, columns, (cb) => {
|
|
1058
|
+
const res = {};
|
|
1059
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
|
1060
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
|
1061
|
+
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
|
1062
|
+
gh,
|
|
1063
|
+
cpk.name
|
|
1064
|
+
);
|
|
1065
|
+
});
|
|
1066
|
+
return res;
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
return tables;
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
// src/serializer/sqliteSerializer.ts
|
|
1076
|
+
function mapSqlToSqliteType(sqlType) {
|
|
1077
|
+
if ([
|
|
1078
|
+
"int",
|
|
1079
|
+
"integer",
|
|
1080
|
+
"integer auto_increment",
|
|
1081
|
+
"tinyint",
|
|
1082
|
+
"smallint",
|
|
1083
|
+
"mediumint",
|
|
1084
|
+
"bigint",
|
|
1085
|
+
"unsigned big int",
|
|
1086
|
+
"int2",
|
|
1087
|
+
"int8"
|
|
1088
|
+
].includes(sqlType.toLowerCase())) {
|
|
1089
|
+
return "integer";
|
|
1090
|
+
} else if ([
|
|
1091
|
+
"character",
|
|
1092
|
+
"varchar",
|
|
1093
|
+
"vatying character",
|
|
1094
|
+
"nchar",
|
|
1095
|
+
"native character",
|
|
1096
|
+
"nvarchar",
|
|
1097
|
+
"text",
|
|
1098
|
+
"clob"
|
|
1099
|
+
].some((it) => it.startsWith(sqlType.toLowerCase()))) {
|
|
1100
|
+
return "text";
|
|
1101
|
+
} else if (sqlType.toLowerCase() === "blob") {
|
|
1102
|
+
return "blob";
|
|
1103
|
+
} else if (["real", "double", "double precision", "float"].includes(
|
|
1104
|
+
sqlType.toLowerCase()
|
|
1105
|
+
)) {
|
|
1106
|
+
return "real";
|
|
1107
|
+
} else {
|
|
1108
|
+
return "numeric";
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
var import_drizzle_orm2, import_sqlite_core, dialect2, fromDatabase2, toDrizzle2;
|
|
1112
|
+
var init_sqliteSerializer = __esm({
|
|
1113
|
+
"src/serializer/sqliteSerializer.ts"() {
|
|
1114
|
+
import_drizzle_orm2 = require("drizzle-orm");
|
|
1115
|
+
import_sqlite_core = require("drizzle-orm/sqlite-core");
|
|
1116
|
+
init_serializer();
|
|
1117
|
+
init_outputs();
|
|
1118
|
+
init_source();
|
|
1119
|
+
dialect2 = new import_sqlite_core.SQLiteSyncDialect();
|
|
1120
|
+
fromDatabase2 = async (db, tablesFilter = (table) => true, progressCallback) => {
|
|
1121
|
+
const result = {};
|
|
1122
|
+
const columns = await db.query(
|
|
1123
|
+
`SELECT
|
|
1124
|
+
m.name as "tableName", p.name as "columnName", p.type as "columnType", p."notnull" as "notNull", p.dflt_value as "defaultValue", p.pk as pk
|
|
1125
|
+
FROM sqlite_master AS m JOIN pragma_table_info(m.name) AS p
|
|
1126
|
+
WHERE m.type = 'table' and m.tbl_name != 'sqlite_sequence' and m.tbl_name != 'sqlite_stat1' and m.tbl_name != '_litestream_seq' and m.tbl_name != '_litestream_lock' and m.tbl_name != 'libsql_wasm_func_table';
|
|
1127
|
+
`
|
|
1128
|
+
);
|
|
1129
|
+
const tablesWithSeq = [];
|
|
1130
|
+
const seq = await db.query(
|
|
1131
|
+
`SELECT * FROM sqlite_master WHERE name != 'sqlite_sequence' and name != 'sqlite_stat1' and name != '_litestream_seq' and name != '_litestream_lock' and sql GLOB '*[ *' || CHAR(9) || CHAR(10) || CHAR(13) || ']AUTOINCREMENT[^'']*';`
|
|
1132
|
+
);
|
|
1133
|
+
for (const s of seq) {
|
|
1134
|
+
tablesWithSeq.push(s.name);
|
|
1135
|
+
}
|
|
1136
|
+
let columnsCount = 0;
|
|
1137
|
+
let tablesCount = /* @__PURE__ */ new Set();
|
|
1138
|
+
let indexesCount = 0;
|
|
1139
|
+
let foreignKeysCount = 0;
|
|
1140
|
+
const tableToPk = {};
|
|
1141
|
+
for (const column of columns) {
|
|
1142
|
+
if (!tablesFilter(column.tableName))
|
|
1143
|
+
continue;
|
|
1144
|
+
columnsCount += 1;
|
|
1145
|
+
if (progressCallback) {
|
|
1146
|
+
progressCallback("columns", columnsCount, "fetching");
|
|
1147
|
+
}
|
|
1148
|
+
const tableName = column.tableName;
|
|
1149
|
+
tablesCount.add(tableName);
|
|
1150
|
+
if (progressCallback) {
|
|
1151
|
+
progressCallback("tables", tablesCount.size, "fetching");
|
|
1152
|
+
}
|
|
1153
|
+
const columnName = column.columnName;
|
|
1154
|
+
const isNotNull = column.notNull === 1;
|
|
1155
|
+
const columnType = column.columnType;
|
|
1156
|
+
const isPrimary = column.pk !== 0;
|
|
1157
|
+
const columnDefault = column.defaultValue;
|
|
1158
|
+
const isAutoincrement = isPrimary && tablesWithSeq.includes(tableName);
|
|
1159
|
+
if (isPrimary) {
|
|
1160
|
+
if (typeof tableToPk[tableName] === "undefined") {
|
|
1161
|
+
tableToPk[tableName] = [columnName];
|
|
1162
|
+
} else {
|
|
1163
|
+
tableToPk[tableName].push(columnName);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
const table = result[tableName];
|
|
1167
|
+
const newColumn = {
|
|
1168
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
|
|
1169
|
+
columnDefault
|
|
1170
|
+
) ? `(${columnDefault})` : columnDefault === "false" ? false : columnDefault === "true" ? true : columnDefault.startsWith("'") && columnDefault.endsWith("'") ? columnDefault : (
|
|
1171
|
+
// ? columnDefault.substring(1, columnDefault.length - 1)
|
|
1172
|
+
`(${columnDefault})`
|
|
1173
|
+
),
|
|
1174
|
+
autoincrement: isAutoincrement,
|
|
1175
|
+
name: columnName,
|
|
1176
|
+
type: mapSqlToSqliteType(columnType),
|
|
1177
|
+
primaryKey: false,
|
|
1178
|
+
notNull: isNotNull
|
|
1179
|
+
};
|
|
1180
|
+
if (!table) {
|
|
1181
|
+
result[tableName] = {
|
|
1182
|
+
name: tableName,
|
|
1183
|
+
columns: {
|
|
1184
|
+
[columnName]: newColumn
|
|
1185
|
+
},
|
|
1186
|
+
compositePrimaryKeys: {},
|
|
1187
|
+
indexes: {},
|
|
1188
|
+
foreignKeys: {},
|
|
1189
|
+
uniqueConstraints: {}
|
|
1190
|
+
};
|
|
1191
|
+
} else {
|
|
1192
|
+
result[tableName].columns[columnName] = newColumn;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
for (const [key, value] of Object.entries(tableToPk)) {
|
|
1196
|
+
if (value.length > 1) {
|
|
1197
|
+
value.sort();
|
|
1198
|
+
result[key].compositePrimaryKeys = {
|
|
1199
|
+
[`${key}_${value.join("_")}_pk`]: {
|
|
1200
|
+
columns: value,
|
|
1201
|
+
name: `${key}_${value.join("_")}_pk`
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
} else if (value.length === 1) {
|
|
1205
|
+
result[key].columns[value[0]].primaryKey = true;
|
|
1206
|
+
} else {
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
if (progressCallback) {
|
|
1210
|
+
progressCallback("columns", columnsCount, "done");
|
|
1211
|
+
progressCallback("tables", tablesCount.size, "done");
|
|
1212
|
+
}
|
|
1213
|
+
try {
|
|
1214
|
+
const fks = await db.query(
|
|
1215
|
+
`SELECT m.name as "tableFrom", f.id as "id", f."table" as "tableTo", f."from", f."to", f."on_update" as "onUpdate", f."on_delete" as "onDelete", f.seq as "seq"
|
|
1216
|
+
FROM sqlite_master m, pragma_foreign_key_list(m.name) as f;`
|
|
1217
|
+
);
|
|
1218
|
+
const fkByTableName = {};
|
|
1219
|
+
for (const fkRow of fks) {
|
|
1220
|
+
foreignKeysCount += 1;
|
|
1221
|
+
if (progressCallback) {
|
|
1222
|
+
progressCallback("fks", foreignKeysCount, "fetching");
|
|
1223
|
+
}
|
|
1224
|
+
const tableName = fkRow.tableFrom;
|
|
1225
|
+
const columnName = fkRow.from;
|
|
1226
|
+
const refTableName = fkRow.tableTo;
|
|
1227
|
+
const refColumnName = fkRow.to;
|
|
1228
|
+
const updateRule = fkRow.onUpdate;
|
|
1229
|
+
const deleteRule = fkRow.onDelete;
|
|
1230
|
+
const sequence = fkRow.seq;
|
|
1231
|
+
const id = fkRow.id;
|
|
1232
|
+
const tableInResult = result[tableName];
|
|
1233
|
+
if (typeof tableInResult === "undefined")
|
|
1234
|
+
continue;
|
|
1235
|
+
if (typeof fkByTableName[`${tableName}_${id}`] !== "undefined") {
|
|
1236
|
+
fkByTableName[`${tableName}_${id}`].columnsFrom.push(columnName);
|
|
1237
|
+
fkByTableName[`${tableName}_${id}`].columnsTo.push(refColumnName);
|
|
1238
|
+
} else {
|
|
1239
|
+
fkByTableName[`${tableName}_${id}`] = {
|
|
1240
|
+
name: "",
|
|
1241
|
+
tableFrom: tableName,
|
|
1242
|
+
tableTo: refTableName,
|
|
1243
|
+
columnsFrom: [columnName],
|
|
1244
|
+
columnsTo: [refColumnName],
|
|
1245
|
+
onDelete: deleteRule == null ? void 0 : deleteRule.toLowerCase(),
|
|
1246
|
+
onUpdate: updateRule == null ? void 0 : updateRule.toLowerCase()
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
const columnsFrom = fkByTableName[`${tableName}_${id}`].columnsFrom;
|
|
1250
|
+
const columnsTo = fkByTableName[`${tableName}_${id}`].columnsTo;
|
|
1251
|
+
fkByTableName[`${tableName}_${id}`].name = `${tableName}_${columnsFrom.join(
|
|
1252
|
+
"_"
|
|
1253
|
+
)}_${refTableName}_${columnsTo.join("_")}_fk`;
|
|
1254
|
+
}
|
|
1255
|
+
for (const idx of Object.keys(fkByTableName)) {
|
|
1256
|
+
const value = fkByTableName[idx];
|
|
1257
|
+
result[value.tableFrom].foreignKeys[value.name] = value;
|
|
1258
|
+
}
|
|
1259
|
+
} catch (e) {
|
|
1260
|
+
}
|
|
1261
|
+
if (progressCallback) {
|
|
1262
|
+
progressCallback("fks", foreignKeysCount, "done");
|
|
1263
|
+
}
|
|
1264
|
+
const idxs = await db.query(
|
|
1265
|
+
`SELECT
|
|
1266
|
+
m.tbl_name as tableName,
|
|
1267
|
+
il.name as indexName,
|
|
1268
|
+
ii.name as columnName,
|
|
1269
|
+
il.[unique] as isUnique,
|
|
1270
|
+
il.seq as seq
|
|
1271
|
+
FROM sqlite_master AS m,
|
|
1272
|
+
pragma_index_list(m.name) AS il,
|
|
1273
|
+
pragma_index_info(il.name) AS ii
|
|
1274
|
+
WHERE
|
|
1275
|
+
m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
|
|
1276
|
+
);
|
|
1277
|
+
for (const idxRow of idxs) {
|
|
1278
|
+
const tableName = idxRow.tableName;
|
|
1279
|
+
const constraintName = idxRow.indexName;
|
|
1280
|
+
const columnName = idxRow.columnName;
|
|
1281
|
+
const isUnique = idxRow.isUnique === 1;
|
|
1282
|
+
const tableInResult = result[tableName];
|
|
1283
|
+
if (typeof tableInResult === "undefined")
|
|
1284
|
+
continue;
|
|
1285
|
+
indexesCount += 1;
|
|
1286
|
+
if (progressCallback) {
|
|
1287
|
+
progressCallback("indexes", indexesCount, "fetching");
|
|
1288
|
+
}
|
|
1289
|
+
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
|
1290
|
+
tableInResult.indexes[constraintName].columns.push(columnName);
|
|
1291
|
+
} else {
|
|
1292
|
+
tableInResult.indexes[constraintName] = {
|
|
1293
|
+
name: constraintName,
|
|
1294
|
+
columns: [columnName],
|
|
1295
|
+
isUnique
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (progressCallback) {
|
|
1300
|
+
progressCallback("indexes", indexesCount, "done");
|
|
1301
|
+
progressCallback("enums", 0, "done");
|
|
1302
|
+
}
|
|
1303
|
+
return {
|
|
1304
|
+
version: "5",
|
|
1305
|
+
dialect: "sqlite",
|
|
1306
|
+
tables: result,
|
|
1307
|
+
enums: {},
|
|
1308
|
+
_meta: {
|
|
1309
|
+
tables: {},
|
|
1310
|
+
columns: {}
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
};
|
|
1314
|
+
toDrizzle2 = (schema) => {
|
|
1315
|
+
const tables = {};
|
|
1316
|
+
Object.values(schema.tables).forEach((t) => {
|
|
1317
|
+
const columns = {};
|
|
1318
|
+
Object.values(t.columns).forEach((c) => {
|
|
1319
|
+
const columnName = c.name;
|
|
1320
|
+
const type = c.type;
|
|
1321
|
+
let columnBuilder;
|
|
1322
|
+
if (type === "integer") {
|
|
1323
|
+
columnBuilder = new import_sqlite_core.SQLiteIntegerBuilder(columnName);
|
|
1324
|
+
} else if (type === "text") {
|
|
1325
|
+
columnBuilder = new import_sqlite_core.SQLiteTextBuilder(columnName, {});
|
|
1326
|
+
} else if (type === "blob") {
|
|
1327
|
+
columnBuilder = new import_sqlite_core.SQLiteBlobBufferBuilder(columnName);
|
|
1328
|
+
} else if (type === "real") {
|
|
1329
|
+
columnBuilder = new import_sqlite_core.SQLiteRealBuilder(columnName);
|
|
1330
|
+
} else {
|
|
1331
|
+
columnBuilder = new import_sqlite_core.SQLiteNumericBuilder(columnName);
|
|
1332
|
+
}
|
|
1333
|
+
if (c.notNull) {
|
|
1334
|
+
columnBuilder = columnBuilder.notNull();
|
|
1335
|
+
}
|
|
1336
|
+
if (c.default) {
|
|
1337
|
+
columnBuilder = columnBuilder.default(c.default);
|
|
1338
|
+
}
|
|
1339
|
+
if (c.primaryKey) {
|
|
1340
|
+
columnBuilder = columnBuilder.primaryKey();
|
|
1341
|
+
}
|
|
1342
|
+
columns[columnName] = columnBuilder;
|
|
1343
|
+
});
|
|
1344
|
+
tables[t.name] = (0, import_sqlite_core.sqliteTable)(t.name, columns, (cb) => {
|
|
1046
1345
|
const res = {};
|
|
1047
1346
|
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
|
1048
1347
|
const gh = cpk.columns.map((c) => cb[c]);
|
|
1049
|
-
res[cpk.name] = new
|
|
1348
|
+
res[cpk.name] = new import_sqlite_core.PrimaryKeyBuilder(
|
|
1050
1349
|
gh,
|
|
1051
1350
|
cpk.name
|
|
1052
1351
|
);
|
|
@@ -1571,7 +1870,7 @@ var require_hanji = __commonJS({
|
|
|
1571
1870
|
return;
|
|
1572
1871
|
}
|
|
1573
1872
|
exports.render = render2;
|
|
1574
|
-
function
|
|
1873
|
+
function renderWithTask3(view, task) {
|
|
1575
1874
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1576
1875
|
const terminal = new TaskTerminal(view, process.stdout);
|
|
1577
1876
|
terminal.requestLayout();
|
|
@@ -1580,7 +1879,7 @@ var require_hanji = __commonJS({
|
|
|
1580
1879
|
return result;
|
|
1581
1880
|
});
|
|
1582
1881
|
}
|
|
1583
|
-
exports.renderWithTask =
|
|
1882
|
+
exports.renderWithTask = renderWithTask3;
|
|
1584
1883
|
var terminateHandler;
|
|
1585
1884
|
function onTerminate(callback) {
|
|
1586
1885
|
terminateHandler = callback;
|
|
@@ -1809,19 +2108,50 @@ var require_brace_expansion = __commonJS({
|
|
|
1809
2108
|
}
|
|
1810
2109
|
});
|
|
1811
2110
|
|
|
2111
|
+
// src/drivers/index.ts
|
|
2112
|
+
var import_drizzle_orm3, DrizzleDbClient, DrizzleORMPgClient;
|
|
2113
|
+
var init_drivers = __esm({
|
|
2114
|
+
"src/drivers/index.ts"() {
|
|
2115
|
+
import_drizzle_orm3 = require("drizzle-orm");
|
|
2116
|
+
DrizzleDbClient = class {
|
|
2117
|
+
constructor(db) {
|
|
2118
|
+
this.db = db;
|
|
2119
|
+
}
|
|
2120
|
+
};
|
|
2121
|
+
DrizzleORMPgClient = class extends DrizzleDbClient {
|
|
2122
|
+
async query(query, values) {
|
|
2123
|
+
const res = await this.db.execute(import_drizzle_orm3.sql.raw(query));
|
|
2124
|
+
return res.rows;
|
|
2125
|
+
}
|
|
2126
|
+
async run(query) {
|
|
2127
|
+
const res = await this.db.execute(import_drizzle_orm3.sql.raw(query));
|
|
2128
|
+
return res.rows;
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
2132
|
+
});
|
|
2133
|
+
|
|
1812
2134
|
// src/utils-studio.ts
|
|
1813
2135
|
var utils_studio_exports = {};
|
|
1814
2136
|
__export(utils_studio_exports, {
|
|
2137
|
+
DrizzleORMPgClient: () => DrizzleORMPgClient,
|
|
1815
2138
|
drizzleSchemaPg: () => toDrizzle,
|
|
1816
|
-
|
|
2139
|
+
drizzleSchemaSQLite: () => toDrizzle2,
|
|
2140
|
+
pgPushIntrospect: () => pgPushIntrospect,
|
|
2141
|
+
sqlitePushIntrospect: () => sqlitePushIntrospect
|
|
1817
2142
|
});
|
|
1818
2143
|
module.exports = __toCommonJS(utils_studio_exports);
|
|
1819
2144
|
init_pgSerializer();
|
|
2145
|
+
init_sqliteSerializer();
|
|
1820
2146
|
|
|
1821
|
-
// src/cli/commands/
|
|
1822
|
-
var import_hanji2 = __toESM(require_hanji());
|
|
2147
|
+
// src/cli/commands/sqliteIntrospect.ts
|
|
1823
2148
|
init_views();
|
|
1824
|
-
|
|
2149
|
+
|
|
2150
|
+
// src/global.ts
|
|
2151
|
+
var originUUID = "00000000-0000-0000-0000-000000000000";
|
|
2152
|
+
|
|
2153
|
+
// src/cli/commands/sqliteIntrospect.ts
|
|
2154
|
+
init_sqliteSerializer();
|
|
1825
2155
|
|
|
1826
2156
|
// node_modules/.pnpm/camelcase@7.0.1/node_modules/camelcase/index.js
|
|
1827
2157
|
var UPPERCASE = /[\p{Lu}]/u;
|
|
@@ -1928,12 +2258,6 @@ Array.prototype.random = function() {
|
|
|
1928
2258
|
return this[~~(Math.random() * this.length)];
|
|
1929
2259
|
};
|
|
1930
2260
|
|
|
1931
|
-
// src/introspect.ts
|
|
1932
|
-
init_pgSerializer();
|
|
1933
|
-
|
|
1934
|
-
// src/global.ts
|
|
1935
|
-
var originUUID = "00000000-0000-0000-0000-000000000000";
|
|
1936
|
-
|
|
1937
2261
|
// node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/index.js
|
|
1938
2262
|
var import_brace_expansion = __toESM(require_brace_expansion(), 1);
|
|
1939
2263
|
|
|
@@ -2980,6 +3304,35 @@ minimatch.Minimatch = Minimatch;
|
|
|
2980
3304
|
minimatch.escape = escape;
|
|
2981
3305
|
minimatch.unescape = unescape;
|
|
2982
3306
|
|
|
3307
|
+
// src/cli/commands/sqliteIntrospect.ts
|
|
3308
|
+
var import_hanji2 = __toESM(require_hanji());
|
|
3309
|
+
var sqlitePushIntrospect = async (client, filters) => {
|
|
3310
|
+
const matchers = filters.map((it) => {
|
|
3311
|
+
return new Minimatch(it);
|
|
3312
|
+
});
|
|
3313
|
+
const filter2 = (tableName) => {
|
|
3314
|
+
if (matchers.length === 0)
|
|
3315
|
+
return true;
|
|
3316
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
3317
|
+
const matcher = matchers[i];
|
|
3318
|
+
if (matcher.match(tableName))
|
|
3319
|
+
return true;
|
|
3320
|
+
}
|
|
3321
|
+
return false;
|
|
3322
|
+
};
|
|
3323
|
+
const res = await fromDatabase2(client, filter2);
|
|
3324
|
+
const schema = { id: originUUID, prevId: "", ...res };
|
|
3325
|
+
return { schema };
|
|
3326
|
+
};
|
|
3327
|
+
|
|
3328
|
+
// src/cli/commands/pgIntrospect.ts
|
|
3329
|
+
var import_hanji3 = __toESM(require_hanji());
|
|
3330
|
+
init_views();
|
|
3331
|
+
init_pgSerializer();
|
|
3332
|
+
|
|
3333
|
+
// src/introspect.ts
|
|
3334
|
+
init_pgSerializer();
|
|
3335
|
+
|
|
2983
3336
|
// src/cli/commands/pgIntrospect.ts
|
|
2984
3337
|
var pgPushIntrospect = async (connection, filters, schemaFilters) => {
|
|
2985
3338
|
const { client } = connection;
|
|
@@ -3001,8 +3354,14 @@ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
|
|
|
3001
3354
|
const { internal, ...schemaWithoutInternals } = schema;
|
|
3002
3355
|
return { schema: schemaWithoutInternals };
|
|
3003
3356
|
};
|
|
3357
|
+
|
|
3358
|
+
// src/utils-studio.ts
|
|
3359
|
+
init_drivers();
|
|
3004
3360
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3005
3361
|
0 && (module.exports = {
|
|
3362
|
+
DrizzleORMPgClient,
|
|
3006
3363
|
drizzleSchemaPg,
|
|
3007
|
-
|
|
3364
|
+
drizzleSchemaSQLite,
|
|
3365
|
+
pgPushIntrospect,
|
|
3366
|
+
sqlitePushIntrospect
|
|
3008
3367
|
});
|
package/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dialect } from "./schemaValidator";
|
|
2
2
|
import { NamedWithSchema } from "./cli/commands/migrate";
|
|
3
|
-
import {
|
|
3
|
+
import { PgDatabase } from "drizzle-orm/pg-core";
|
|
4
4
|
import { PgSchema as PgSchemaKit } from "./serializer/pgSchema";
|
|
5
5
|
import { Config, DbConnection } from ".";
|
|
6
6
|
export declare const assertV1OutFolder: (out: string, dialect: Dialect | "{dialect}") => void;
|
|
@@ -209,24 +209,4 @@ export declare const pushSchema: (imports: Record<string, unknown>, db: PgDataba
|
|
|
209
209
|
statementsToExecute: string[];
|
|
210
210
|
apply: () => Promise<void>;
|
|
211
211
|
}>;
|
|
212
|
-
export declare const prepareFrom: (connection: DbConnection) => Promise<
|
|
213
|
-
db: import("drizzle-orm/node-postgres").NodePgDatabase<Record<string, never>>;
|
|
214
|
-
type: "pg";
|
|
215
|
-
schema: Record<string, AnyPgTable<{}> | import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>>> | undefined;
|
|
216
|
-
} | {
|
|
217
|
-
db: import("drizzle-orm/mysql2").MySql2Database<Record<string, never>>;
|
|
218
|
-
type: "mysql";
|
|
219
|
-
schema: Record<string, import("drizzle-orm/mysql-core").AnyMySqlTable<{}> | import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>>> | undefined;
|
|
220
|
-
} | {
|
|
221
|
-
db: import("./orm-extenstions/d1-driver/driver").DrizzleD1WranglerDatabase<Record<string, never>>;
|
|
222
|
-
type: "sqlite";
|
|
223
|
-
schema: Record<string, import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>> | import("drizzle-orm/sqlite-core").AnySQLiteTable<{}>> | undefined;
|
|
224
|
-
} | {
|
|
225
|
-
db: import("drizzle-orm/better-sqlite3").BetterSQLite3Database<Record<string, never>>;
|
|
226
|
-
type: "sqlite";
|
|
227
|
-
schema: Record<string, import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>> | import("drizzle-orm/sqlite-core").AnySQLiteTable<{}>> | undefined;
|
|
228
|
-
} | {
|
|
229
|
-
db: import("drizzle-orm/libsql").LibSQLDatabase<Record<string, never>>;
|
|
230
|
-
type: "sqlite";
|
|
231
|
-
schema: Record<string, import("drizzle-orm").Relations<string, Record<string, import("drizzle-orm").Relation<string>>> | import("drizzle-orm/sqlite-core").AnySQLiteTable<{}>> | undefined;
|
|
232
|
-
}>;
|
|
212
|
+
export declare const prepareFrom: (connection: DbConnection) => Promise<Record<string, any>>;
|