drizzle-kit 0.20.8 → 0.20.9-1dc10f5
Sign up to get free protection for your applications and to get access to all the features.
- package/bin.cjs +663 -693
- package/cli/commands/pgIntrospect.d.ts +2 -0
- package/package.json +4 -3
- package/schemaValidator.d.ts +7 -0
- package/serializer/pgSchema.d.ts +89 -0
- 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 +953 -944
- package/utils-studio.mjs +631 -622
- package/utils.d.ts +2 -0
- package/utils.js +209 -190
package/utils-studio.js
CHANGED
@@ -1098,1014 +1098,875 @@ var init_outputs = __esm({
|
|
1098
1098
|
}
|
1099
1099
|
});
|
1100
1100
|
|
1101
|
-
// src/serializer/
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1101
|
+
// src/serializer/sqliteSerializer.ts
|
1102
|
+
function mapSqlToSqliteType(sqlType) {
|
1103
|
+
if ([
|
1104
|
+
"int",
|
1105
|
+
"integer",
|
1106
|
+
"integer auto_increment",
|
1107
|
+
"tinyint",
|
1108
|
+
"smallint",
|
1109
|
+
"mediumint",
|
1110
|
+
"bigint",
|
1111
|
+
"unsigned big int",
|
1112
|
+
"int2",
|
1113
|
+
"int8"
|
1114
|
+
].includes(sqlType.toLowerCase())) {
|
1115
|
+
return "integer";
|
1116
|
+
} else if ([
|
1117
|
+
"character",
|
1118
|
+
"varchar",
|
1119
|
+
"vatying character",
|
1120
|
+
"nchar",
|
1121
|
+
"native character",
|
1122
|
+
"nvarchar",
|
1123
|
+
"text",
|
1124
|
+
"clob"
|
1125
|
+
].some((it) => it.startsWith(sqlType.toLowerCase()))) {
|
1126
|
+
return "text";
|
1127
|
+
} else if (sqlType.toLowerCase() === "blob") {
|
1128
|
+
return "blob";
|
1129
|
+
} else if (["real", "double", "double precision", "float"].includes(
|
1130
|
+
sqlType.toLowerCase()
|
1131
|
+
)) {
|
1132
|
+
return "real";
|
1133
|
+
} else {
|
1134
|
+
return "numeric";
|
1135
|
+
}
|
1136
|
+
}
|
1137
|
+
var import_drizzle_orm, import_sqlite_core2, dialect, fromDatabase;
|
1138
|
+
var init_sqliteSerializer = __esm({
|
1139
|
+
"src/serializer/sqliteSerializer.ts"() {
|
1107
1140
|
import_drizzle_orm = require("drizzle-orm");
|
1141
|
+
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
1108
1142
|
init_serializer();
|
1109
|
-
init_source();
|
1110
1143
|
init_outputs();
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
let end = str.length;
|
1115
|
-
while (start < end && str[start] === char)
|
1116
|
-
++start;
|
1117
|
-
while (end > start && str[end - 1] === char)
|
1118
|
-
--end;
|
1119
|
-
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
1120
|
-
};
|
1121
|
-
fromDatabase = async (db, tablesFilter = (table) => true, schemaFilters, progressCallback) => {
|
1144
|
+
init_source();
|
1145
|
+
dialect = new import_sqlite_core2.SQLiteSyncDialect();
|
1146
|
+
fromDatabase = async (db, tablesFilter = (table) => true, progressCallback) => {
|
1122
1147
|
const result = {};
|
1123
|
-
const
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1148
|
+
const columns = await db.query(
|
1149
|
+
`SELECT
|
1150
|
+
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
|
1151
|
+
FROM sqlite_master AS m JOIN pragma_table_info(m.name) AS p
|
1152
|
+
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';
|
1153
|
+
`
|
1127
1154
|
);
|
1128
|
-
const
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
and nspname not like 'pg_temp_%'
|
1136
|
-
order by table_schema;`);
|
1137
|
-
allSchemas.forEach((item) => {
|
1138
|
-
if (schemaFilters.includes(item.table_schema)) {
|
1139
|
-
schemas.add(item.table_schema);
|
1140
|
-
}
|
1141
|
-
});
|
1155
|
+
const tablesWithSeq = [];
|
1156
|
+
const seq = await db.query(
|
1157
|
+
`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[^'']*';`
|
1158
|
+
);
|
1159
|
+
for (const s of seq) {
|
1160
|
+
tablesWithSeq.push(s.name);
|
1161
|
+
}
|
1142
1162
|
let columnsCount = 0;
|
1163
|
+
let tablesCount = /* @__PURE__ */ new Set();
|
1143
1164
|
let indexesCount = 0;
|
1144
1165
|
let foreignKeysCount = 0;
|
1145
|
-
|
1146
|
-
const
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
rc.delete_rule, rc.update_rule
|
1208
|
-
FROM
|
1209
|
-
information_schema.table_constraints AS tc
|
1210
|
-
JOIN information_schema.key_column_usage AS kcu
|
1211
|
-
ON tc.constraint_name = kcu.constraint_name
|
1212
|
-
AND tc.table_schema = kcu.table_schema
|
1213
|
-
JOIN information_schema.constraint_column_usage AS ccu
|
1214
|
-
ON ccu.constraint_name = tc.constraint_name
|
1215
|
-
AND ccu.table_schema = tc.table_schema
|
1216
|
-
JOIN information_schema.referential_constraints AS rc
|
1217
|
-
ON ccu.constraint_name = rc.constraint_name
|
1218
|
-
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
|
1219
|
-
);
|
1220
|
-
foreignKeysCount += tableForeignKeys.length;
|
1221
|
-
if (progressCallback) {
|
1222
|
-
progressCallback("fks", foreignKeysCount, "fetching");
|
1223
|
-
}
|
1224
|
-
for (const fk of tableForeignKeys) {
|
1225
|
-
const columnFrom = fk.column_name;
|
1226
|
-
const tableTo = fk.foreign_table_name;
|
1227
|
-
const columnTo = fk.foreign_column_name;
|
1228
|
-
const foreignKeyName = fk.constraint_name;
|
1229
|
-
const onUpdate = fk.update_rule.toLowerCase();
|
1230
|
-
const onDelete = fk.delete_rule.toLowerCase();
|
1231
|
-
if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
|
1232
|
-
foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
|
1233
|
-
foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
|
1234
|
-
} else {
|
1235
|
-
foreignKeysToReturn[foreignKeyName] = {
|
1236
|
-
name: foreignKeyName,
|
1237
|
-
tableFrom: tableName,
|
1238
|
-
tableTo,
|
1239
|
-
columnsFrom: [columnFrom],
|
1240
|
-
columnsTo: [columnTo],
|
1241
|
-
onDelete,
|
1242
|
-
onUpdate
|
1243
|
-
};
|
1244
|
-
}
|
1245
|
-
foreignKeysToReturn[foreignKeyName].columnsFrom = [
|
1246
|
-
...new Set(foreignKeysToReturn[foreignKeyName].columnsFrom)
|
1247
|
-
];
|
1248
|
-
foreignKeysToReturn[foreignKeyName].columnsTo = [
|
1249
|
-
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
1250
|
-
];
|
1251
|
-
}
|
1252
|
-
const uniqueConstrainsRows = tableConstraints.filter(
|
1253
|
-
(mapRow) => mapRow.constraint_type === "UNIQUE"
|
1254
|
-
);
|
1255
|
-
for (const unqs of uniqueConstrainsRows) {
|
1256
|
-
const columnName = unqs.column_name;
|
1257
|
-
const constraintName = unqs.constraint_name;
|
1258
|
-
if (typeof uniqueConstrains[constraintName] !== "undefined") {
|
1259
|
-
uniqueConstrains[constraintName].columns.push(columnName);
|
1260
|
-
} else {
|
1261
|
-
uniqueConstrains[constraintName] = {
|
1262
|
-
columns: [columnName],
|
1263
|
-
nullsNotDistinct: false,
|
1264
|
-
name: constraintName
|
1265
|
-
};
|
1266
|
-
}
|
1166
|
+
const tableToPk = {};
|
1167
|
+
for (const column of columns) {
|
1168
|
+
if (!tablesFilter(column.tableName))
|
1169
|
+
continue;
|
1170
|
+
columnsCount += 1;
|
1171
|
+
if (progressCallback) {
|
1172
|
+
progressCallback("columns", columnsCount, "fetching");
|
1173
|
+
}
|
1174
|
+
const tableName = column.tableName;
|
1175
|
+
tablesCount.add(tableName);
|
1176
|
+
if (progressCallback) {
|
1177
|
+
progressCallback("tables", tablesCount.size, "fetching");
|
1178
|
+
}
|
1179
|
+
const columnName = column.columnName;
|
1180
|
+
const isNotNull = column.notNull === 1;
|
1181
|
+
const columnType = column.columnType;
|
1182
|
+
const isPrimary = column.pk !== 0;
|
1183
|
+
const columnDefault = column.defaultValue;
|
1184
|
+
const isAutoincrement = isPrimary && tablesWithSeq.includes(tableName);
|
1185
|
+
if (isPrimary) {
|
1186
|
+
if (typeof tableToPk[tableName] === "undefined") {
|
1187
|
+
tableToPk[tableName] = [columnName];
|
1188
|
+
} else {
|
1189
|
+
tableToPk[tableName].push(columnName);
|
1190
|
+
}
|
1191
|
+
}
|
1192
|
+
const table = result[tableName];
|
1193
|
+
const newColumn = {
|
1194
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
|
1195
|
+
columnDefault
|
1196
|
+
) ? `(${columnDefault})` : columnDefault === "false" ? false : columnDefault === "true" ? true : columnDefault.startsWith("'") && columnDefault.endsWith("'") ? columnDefault : (
|
1197
|
+
// ? columnDefault.substring(1, columnDefault.length - 1)
|
1198
|
+
`(${columnDefault})`
|
1199
|
+
),
|
1200
|
+
autoincrement: isAutoincrement,
|
1201
|
+
name: columnName,
|
1202
|
+
type: mapSqlToSqliteType(columnType),
|
1203
|
+
primaryKey: false,
|
1204
|
+
notNull: isNotNull
|
1205
|
+
};
|
1206
|
+
if (!table) {
|
1207
|
+
result[tableName] = {
|
1208
|
+
name: tableName,
|
1209
|
+
columns: {
|
1210
|
+
[columnName]: newColumn
|
1211
|
+
},
|
1212
|
+
compositePrimaryKeys: {},
|
1213
|
+
indexes: {},
|
1214
|
+
foreignKeys: {},
|
1215
|
+
uniqueConstraints: {}
|
1216
|
+
};
|
1217
|
+
} else {
|
1218
|
+
result[tableName].columns[columnName] = newColumn;
|
1219
|
+
}
|
1220
|
+
}
|
1221
|
+
for (const [key, value] of Object.entries(tableToPk)) {
|
1222
|
+
if (value.length > 1) {
|
1223
|
+
value.sort();
|
1224
|
+
result[key].compositePrimaryKeys = {
|
1225
|
+
[`${key}_${value.join("_")}_pk`]: {
|
1226
|
+
columns: value,
|
1227
|
+
name: `${key}_${value.join("_")}_pk`
|
1267
1228
|
}
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
|
1275
|
-
);
|
1276
|
-
const cprimaryKey = tableConstraints.filter(
|
1277
|
-
(mapRow) => mapRow.constraint_type === "PRIMARY KEY"
|
1278
|
-
);
|
1279
|
-
if (cprimaryKey.length > 1) {
|
1280
|
-
const tableCompositePkName = await db.query(
|
1281
|
-
`SELECT conname AS primary_key
|
1282
|
-
FROM pg_constraint join pg_class on (pg_class.oid = conrelid)
|
1283
|
-
WHERE contype = 'p'
|
1284
|
-
AND connamespace = $1::regnamespace
|
1285
|
-
AND pg_class.relname = $2;`,
|
1286
|
-
[tableSchema, tableName]
|
1287
|
-
);
|
1288
|
-
primaryKeys[tableCompositePkName[0].primary_key] = {
|
1289
|
-
name: tableCompositePkName[0].primary_key,
|
1290
|
-
columns: cprimaryKey.map((c) => c.column_name)
|
1291
|
-
};
|
1292
|
-
}
|
1293
|
-
const defaultValue = defaultForColumn(columnResponse);
|
1294
|
-
const isSerial = columnType === "serial";
|
1295
|
-
let columnTypeMapped = columnType;
|
1296
|
-
if (columnTypeMapped.startsWith("numeric(")) {
|
1297
|
-
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
1298
|
-
}
|
1299
|
-
if (columnAdditionalDT === "ARRAY") {
|
1300
|
-
if (typeof internals.tables[tableName] === "undefined") {
|
1301
|
-
internals.tables[tableName] = {
|
1302
|
-
columns: {
|
1303
|
-
[columnName]: {
|
1304
|
-
isArray: true,
|
1305
|
-
dimensions: columnDimensions,
|
1306
|
-
rawType: columnTypeMapped.substring(
|
1307
|
-
0,
|
1308
|
-
columnTypeMapped.length - 2
|
1309
|
-
)
|
1310
|
-
}
|
1311
|
-
}
|
1312
|
-
};
|
1313
|
-
} else {
|
1314
|
-
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
1315
|
-
internals.tables[tableName].columns[columnName] = {
|
1316
|
-
isArray: true,
|
1317
|
-
dimensions: columnDimensions,
|
1318
|
-
rawType: columnTypeMapped.substring(
|
1319
|
-
0,
|
1320
|
-
columnTypeMapped.length - 2
|
1321
|
-
)
|
1322
|
-
};
|
1323
|
-
}
|
1324
|
-
}
|
1325
|
-
}
|
1326
|
-
if (columnAdditionalDT === "ARRAY") {
|
1327
|
-
for (let i = 1; i < Number(columnDimensions); i++) {
|
1328
|
-
columnTypeMapped += "[]";
|
1329
|
-
}
|
1330
|
-
}
|
1331
|
-
columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
|
1332
|
-
columnTypeMapped = trimChar(columnTypeMapped, '"');
|
1333
|
-
columnToReturn[columnName] = {
|
1334
|
-
name: columnName,
|
1335
|
-
type: columnTypeMapped,
|
1336
|
-
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
1337
|
-
// default: isSerial ? undefined : defaultValue,
|
1338
|
-
notNull: columnResponse.is_nullable === "NO"
|
1339
|
-
};
|
1340
|
-
if (!isSerial && typeof defaultValue !== "undefined") {
|
1341
|
-
columnToReturn[columnName].default = defaultValue;
|
1342
|
-
}
|
1343
|
-
}
|
1344
|
-
const dbIndexes = await db.query(
|
1345
|
-
`SELECT t.relname as table_name, i.relname AS index_name, ix.indisunique AS is_unique, a.attname AS column_name
|
1346
|
-
FROM pg_class t
|
1347
|
-
JOIN pg_index ix ON t.oid = ix.indrelid
|
1348
|
-
JOIN pg_class i ON i.oid = ix.indexrelid
|
1349
|
-
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
|
1350
|
-
JOIN pg_namespace ns ON ns.oid = t.relnamespace
|
1351
|
-
WHERE ns.nspname = '${tableSchema}'
|
1352
|
-
AND t.relname = '${tableName}'
|
1353
|
-
and ix.indisprimary = false;`
|
1354
|
-
);
|
1355
|
-
const dbIndexFromConstraint = await db.query(
|
1356
|
-
`SELECT
|
1357
|
-
idx.indexrelname AS index_name,
|
1358
|
-
idx.relname AS table_name,
|
1359
|
-
schemaname,
|
1360
|
-
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
|
1361
|
-
FROM
|
1362
|
-
pg_stat_user_indexes idx
|
1363
|
-
LEFT JOIN
|
1364
|
-
pg_constraint con ON con.conindid = idx.indexrelid
|
1365
|
-
WHERE idx.relname = '${tableName}' and schemaname = '${tableSchema}'
|
1366
|
-
group by index_name, table_name,schemaname, generated_by_constraint;`
|
1367
|
-
);
|
1368
|
-
const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
|
1369
|
-
for (const dbIndex of dbIndexes) {
|
1370
|
-
const indexName2 = dbIndex.index_name;
|
1371
|
-
const indexColumnName = dbIndex.column_name;
|
1372
|
-
const indexIsUnique = dbIndex.is_unique;
|
1373
|
-
if (idxsInConsteraint.includes(indexName2))
|
1374
|
-
continue;
|
1375
|
-
if (typeof indexToReturn[indexName2] !== "undefined") {
|
1376
|
-
indexToReturn[indexName2].columns.push(indexColumnName);
|
1377
|
-
} else {
|
1378
|
-
indexToReturn[indexName2] = {
|
1379
|
-
name: indexName2,
|
1380
|
-
columns: [indexColumnName],
|
1381
|
-
isUnique: indexIsUnique
|
1382
|
-
};
|
1383
|
-
}
|
1384
|
-
}
|
1385
|
-
indexesCount += Object.keys(indexToReturn).length;
|
1386
|
-
if (progressCallback) {
|
1387
|
-
progressCallback("indexes", indexesCount, "fetching");
|
1388
|
-
}
|
1389
|
-
result[tableName] = {
|
1390
|
-
name: tableName,
|
1391
|
-
schema: tableSchema !== "public" ? tableSchema : "",
|
1392
|
-
columns: columnToReturn,
|
1393
|
-
indexes: indexToReturn,
|
1394
|
-
foreignKeys: foreignKeysToReturn,
|
1395
|
-
compositePrimaryKeys: primaryKeys,
|
1396
|
-
uniqueConstraints: uniqueConstrains
|
1397
|
-
};
|
1398
|
-
} catch (e) {
|
1399
|
-
rej(e);
|
1400
|
-
return;
|
1401
|
-
}
|
1402
|
-
res("");
|
1403
|
-
});
|
1404
|
-
});
|
1229
|
+
};
|
1230
|
+
} else if (value.length === 1) {
|
1231
|
+
result[key].columns[value[0]].primaryKey = true;
|
1232
|
+
} else {
|
1233
|
+
}
|
1234
|
+
}
|
1405
1235
|
if (progressCallback) {
|
1406
|
-
progressCallback("
|
1236
|
+
progressCallback("columns", columnsCount, "done");
|
1237
|
+
progressCallback("tables", tablesCount.size, "done");
|
1407
1238
|
}
|
1408
|
-
|
1239
|
+
try {
|
1240
|
+
const fks = await db.query(
|
1241
|
+
`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"
|
1242
|
+
FROM sqlite_master m, pragma_foreign_key_list(m.name) as f;`
|
1243
|
+
);
|
1244
|
+
const fkByTableName = {};
|
1245
|
+
for (const fkRow of fks) {
|
1246
|
+
foreignKeysCount += 1;
|
1247
|
+
if (progressCallback) {
|
1248
|
+
progressCallback("fks", foreignKeysCount, "fetching");
|
1249
|
+
}
|
1250
|
+
const tableName = fkRow.tableFrom;
|
1251
|
+
const columnName = fkRow.from;
|
1252
|
+
const refTableName = fkRow.tableTo;
|
1253
|
+
const refColumnName = fkRow.to;
|
1254
|
+
const updateRule = fkRow.onUpdate;
|
1255
|
+
const deleteRule = fkRow.onDelete;
|
1256
|
+
const sequence = fkRow.seq;
|
1257
|
+
const id = fkRow.id;
|
1258
|
+
const tableInResult = result[tableName];
|
1259
|
+
if (typeof tableInResult === "undefined")
|
1260
|
+
continue;
|
1261
|
+
if (typeof fkByTableName[`${tableName}_${id}`] !== "undefined") {
|
1262
|
+
fkByTableName[`${tableName}_${id}`].columnsFrom.push(columnName);
|
1263
|
+
fkByTableName[`${tableName}_${id}`].columnsTo.push(refColumnName);
|
1264
|
+
} else {
|
1265
|
+
fkByTableName[`${tableName}_${id}`] = {
|
1266
|
+
name: "",
|
1267
|
+
tableFrom: tableName,
|
1268
|
+
tableTo: refTableName,
|
1269
|
+
columnsFrom: [columnName],
|
1270
|
+
columnsTo: [refColumnName],
|
1271
|
+
onDelete: deleteRule == null ? void 0 : deleteRule.toLowerCase(),
|
1272
|
+
onUpdate: updateRule == null ? void 0 : updateRule.toLowerCase()
|
1273
|
+
};
|
1274
|
+
}
|
1275
|
+
const columnsFrom = fkByTableName[`${tableName}_${id}`].columnsFrom;
|
1276
|
+
const columnsTo = fkByTableName[`${tableName}_${id}`].columnsTo;
|
1277
|
+
fkByTableName[`${tableName}_${id}`].name = `${tableName}_${columnsFrom.join(
|
1278
|
+
"_"
|
1279
|
+
)}_${refTableName}_${columnsTo.join("_")}_fk`;
|
1280
|
+
}
|
1281
|
+
for (const idx of Object.keys(fkByTableName)) {
|
1282
|
+
const value = fkByTableName[idx];
|
1283
|
+
result[value.tableFrom].foreignKeys[value.name] = value;
|
1284
|
+
}
|
1285
|
+
} catch (e) {
|
1409
1286
|
}
|
1410
1287
|
if (progressCallback) {
|
1411
|
-
progressCallback("columns", columnsCount, "done");
|
1412
|
-
progressCallback("indexes", indexesCount, "done");
|
1413
1288
|
progressCallback("fks", foreignKeysCount, "done");
|
1414
1289
|
}
|
1415
|
-
const
|
1416
|
-
`
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1290
|
+
const idxs = await db.query(
|
1291
|
+
`SELECT
|
1292
|
+
m.tbl_name as tableName,
|
1293
|
+
il.name as indexName,
|
1294
|
+
ii.name as columnName,
|
1295
|
+
il.[unique] as isUnique,
|
1296
|
+
il.seq as seq
|
1297
|
+
FROM sqlite_master AS m,
|
1298
|
+
pragma_index_list(m.name) AS il,
|
1299
|
+
pragma_index_info(il.name) AS ii
|
1300
|
+
WHERE
|
1301
|
+
m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
|
1422
1302
|
);
|
1423
|
-
const
|
1424
|
-
|
1425
|
-
const
|
1426
|
-
const
|
1427
|
-
|
1428
|
-
|
1303
|
+
for (const idxRow of idxs) {
|
1304
|
+
const tableName = idxRow.tableName;
|
1305
|
+
const constraintName = idxRow.indexName;
|
1306
|
+
const columnName = idxRow.columnName;
|
1307
|
+
const isUnique = idxRow.isUnique === 1;
|
1308
|
+
const tableInResult = result[tableName];
|
1309
|
+
if (typeof tableInResult === "undefined")
|
1310
|
+
continue;
|
1311
|
+
indexesCount += 1;
|
1312
|
+
if (progressCallback) {
|
1313
|
+
progressCallback("indexes", indexesCount, "fetching");
|
1314
|
+
}
|
1315
|
+
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
1316
|
+
tableInResult.indexes[constraintName].columns.push(columnName);
|
1429
1317
|
} else {
|
1430
|
-
|
1431
|
-
name:
|
1432
|
-
|
1318
|
+
tableInResult.indexes[constraintName] = {
|
1319
|
+
name: constraintName,
|
1320
|
+
columns: [columnName],
|
1321
|
+
isUnique
|
1433
1322
|
};
|
1434
1323
|
}
|
1435
1324
|
}
|
1436
1325
|
if (progressCallback) {
|
1437
|
-
progressCallback("
|
1326
|
+
progressCallback("indexes", indexesCount, "done");
|
1327
|
+
progressCallback("enums", 0, "done");
|
1438
1328
|
}
|
1439
|
-
const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
|
1440
1329
|
return {
|
1441
1330
|
version: "5",
|
1442
|
-
dialect: "
|
1331
|
+
dialect: "sqlite",
|
1443
1332
|
tables: result,
|
1444
|
-
enums:
|
1445
|
-
schemas: schemasObject,
|
1333
|
+
enums: {},
|
1446
1334
|
_meta: {
|
1447
|
-
schemas: {},
|
1448
1335
|
tables: {},
|
1449
1336
|
columns: {}
|
1450
|
-
}
|
1451
|
-
internal: internals
|
1337
|
+
}
|
1452
1338
|
};
|
1453
1339
|
};
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1340
|
+
}
|
1341
|
+
});
|
1342
|
+
|
1343
|
+
// node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js
|
1344
|
+
var require_balanced_match = __commonJS({
|
1345
|
+
"node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js"(exports, module2) {
|
1346
|
+
"use strict";
|
1347
|
+
module2.exports = balanced;
|
1348
|
+
function balanced(a, b, str) {
|
1349
|
+
if (a instanceof RegExp)
|
1350
|
+
a = maybeMatch(a, str);
|
1351
|
+
if (b instanceof RegExp)
|
1352
|
+
b = maybeMatch(b, str);
|
1353
|
+
var r = range(a, b, str);
|
1354
|
+
return r && {
|
1355
|
+
start: r[0],
|
1356
|
+
end: r[1],
|
1357
|
+
pre: str.slice(0, r[0]),
|
1358
|
+
body: str.slice(r[0] + a.length, r[1]),
|
1359
|
+
post: str.slice(r[1] + b.length)
|
1360
|
+
};
|
1361
|
+
}
|
1362
|
+
function maybeMatch(reg, str) {
|
1363
|
+
var m = str.match(reg);
|
1364
|
+
return m ? m[0] : null;
|
1365
|
+
}
|
1366
|
+
balanced.range = range;
|
1367
|
+
function range(a, b, str) {
|
1368
|
+
var begs, beg, left, right, result;
|
1369
|
+
var ai = str.indexOf(a);
|
1370
|
+
var bi = str.indexOf(b, ai + 1);
|
1371
|
+
var i = ai;
|
1372
|
+
if (ai >= 0 && bi > 0) {
|
1373
|
+
if (a === b) {
|
1374
|
+
return [ai, bi];
|
1375
|
+
}
|
1376
|
+
begs = [];
|
1377
|
+
left = str.length;
|
1378
|
+
while (i >= 0 && !result) {
|
1379
|
+
if (i == ai) {
|
1380
|
+
begs.push(i);
|
1381
|
+
ai = str.indexOf(a, i + 1);
|
1382
|
+
} else if (begs.length == 1) {
|
1383
|
+
result = [begs.pop(), bi];
|
1384
|
+
} else {
|
1385
|
+
beg = begs.pop();
|
1386
|
+
if (beg < left) {
|
1387
|
+
left = beg;
|
1388
|
+
right = bi;
|
1389
|
+
}
|
1390
|
+
bi = str.indexOf(b, i + 1);
|
1391
|
+
}
|
1392
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
1393
|
+
}
|
1394
|
+
if (begs.length) {
|
1395
|
+
result = [left, right];
|
1396
|
+
}
|
1477
1397
|
}
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1398
|
+
return result;
|
1399
|
+
}
|
1400
|
+
}
|
1401
|
+
});
|
1402
|
+
|
1403
|
+
// node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js
|
1404
|
+
var require_brace_expansion = __commonJS({
|
1405
|
+
"node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js"(exports, module2) {
|
1406
|
+
var balanced = require_balanced_match();
|
1407
|
+
module2.exports = expandTop;
|
1408
|
+
var escSlash = "\0SLASH" + Math.random() + "\0";
|
1409
|
+
var escOpen = "\0OPEN" + Math.random() + "\0";
|
1410
|
+
var escClose = "\0CLOSE" + Math.random() + "\0";
|
1411
|
+
var escComma = "\0COMMA" + Math.random() + "\0";
|
1412
|
+
var escPeriod = "\0PERIOD" + Math.random() + "\0";
|
1413
|
+
function numeric(str) {
|
1414
|
+
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
|
1415
|
+
}
|
1416
|
+
function escapeBraces(str) {
|
1417
|
+
return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
|
1418
|
+
}
|
1419
|
+
function unescapeBraces(str) {
|
1420
|
+
return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
|
1421
|
+
}
|
1422
|
+
function parseCommaParts(str) {
|
1423
|
+
if (!str)
|
1424
|
+
return [""];
|
1425
|
+
var parts = [];
|
1426
|
+
var m = balanced("{", "}", str);
|
1427
|
+
if (!m)
|
1428
|
+
return str.split(",");
|
1429
|
+
var pre = m.pre;
|
1430
|
+
var body = m.body;
|
1431
|
+
var post = m.post;
|
1432
|
+
var p = pre.split(",");
|
1433
|
+
p[p.length - 1] += "{" + body + "}";
|
1434
|
+
var postParts = parseCommaParts(post);
|
1435
|
+
if (post.length) {
|
1436
|
+
p[p.length - 1] += postParts.shift();
|
1437
|
+
p.push.apply(p, postParts);
|
1483
1438
|
}
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1439
|
+
parts.push.apply(parts, p);
|
1440
|
+
return parts;
|
1441
|
+
}
|
1442
|
+
function expandTop(str) {
|
1443
|
+
if (!str)
|
1444
|
+
return [];
|
1445
|
+
if (str.substr(0, 2) === "{}") {
|
1446
|
+
str = "\\{\\}" + str.substr(2);
|
1447
|
+
}
|
1448
|
+
return expand2(escapeBraces(str), true).map(unescapeBraces);
|
1449
|
+
}
|
1450
|
+
function embrace(str) {
|
1451
|
+
return "{" + str + "}";
|
1452
|
+
}
|
1453
|
+
function isPadded(el) {
|
1454
|
+
return /^-?0\d/.test(el);
|
1455
|
+
}
|
1456
|
+
function lte(i, y) {
|
1457
|
+
return i <= y;
|
1458
|
+
}
|
1459
|
+
function gte(i, y) {
|
1460
|
+
return i >= y;
|
1461
|
+
}
|
1462
|
+
function expand2(str, isTop) {
|
1463
|
+
var expansions = [];
|
1464
|
+
var m = balanced("{", "}", str);
|
1465
|
+
if (!m)
|
1466
|
+
return [str];
|
1467
|
+
var pre = m.pre;
|
1468
|
+
var post = m.post.length ? expand2(m.post, false) : [""];
|
1469
|
+
if (/\$$/.test(m.pre)) {
|
1470
|
+
for (var k = 0; k < post.length; k++) {
|
1471
|
+
var expansion = pre + "{" + m.body + "}" + post[k];
|
1472
|
+
expansions.push(expansion);
|
1499
1473
|
}
|
1500
1474
|
} else {
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1475
|
+
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
1476
|
+
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
1477
|
+
var isSequence = isNumericSequence || isAlphaSequence;
|
1478
|
+
var isOptions = m.body.indexOf(",") >= 0;
|
1479
|
+
if (!isSequence && !isOptions) {
|
1480
|
+
if (m.post.match(/,.*\}/)) {
|
1481
|
+
str = m.pre + "{" + m.body + escClose + m.post;
|
1482
|
+
return expand2(str);
|
1483
|
+
}
|
1484
|
+
return [str];
|
1485
|
+
}
|
1486
|
+
var n;
|
1487
|
+
if (isSequence) {
|
1488
|
+
n = m.body.split(/\.\./);
|
1505
1489
|
} else {
|
1506
|
-
|
1490
|
+
n = parseCommaParts(m.body);
|
1491
|
+
if (n.length === 1) {
|
1492
|
+
n = expand2(n[0], false).map(embrace);
|
1493
|
+
if (n.length === 1) {
|
1494
|
+
return post.map(function(p) {
|
1495
|
+
return m.pre + n[0] + p;
|
1496
|
+
});
|
1497
|
+
}
|
1498
|
+
}
|
1507
1499
|
}
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
columnBuilder = new import_pg_core.PgBigInt53Builder(columnName);
|
1520
|
-
} else if (type === "bigserial") {
|
1521
|
-
columnBuilder = new import_pg_core.PgBigSerial53Builder(columnName);
|
1522
|
-
} else if (type === "boolean") {
|
1523
|
-
columnBuilder = new import_pg_core.PgBooleanBuilder(columnName);
|
1524
|
-
} else if (type === "cidr") {
|
1525
|
-
columnBuilder = new import_pg_core.PgCidrBuilder(columnName);
|
1526
|
-
} else if (type === "date") {
|
1527
|
-
columnBuilder = new import_pg_core.PgDateBuilder(columnName);
|
1528
|
-
} else if (type === "double precision") {
|
1529
|
-
columnBuilder = new import_pg_core.PgDoublePrecisionBuilder(columnName);
|
1530
|
-
} else if (type === "inet") {
|
1531
|
-
columnBuilder = new import_pg_core.PgInetBuilder(columnName);
|
1532
|
-
} else if (type === "integer") {
|
1533
|
-
columnBuilder = new import_pg_core.PgIntegerBuilder(columnName);
|
1534
|
-
} else if (type === "interval" || type.startsWith("interval ")) {
|
1535
|
-
columnBuilder = new import_pg_core.PgIntervalBuilder(columnName, {});
|
1536
|
-
} else if (type === "json") {
|
1537
|
-
columnBuilder = new import_pg_core.PgJsonBuilder(columnName);
|
1538
|
-
} else if (type === "jsonb") {
|
1539
|
-
columnBuilder = new import_pg_core.PgJsonbBuilder(columnName);
|
1540
|
-
} else if (type === "macaddr") {
|
1541
|
-
columnBuilder = new import_pg_core.PgMacaddrBuilder(columnName);
|
1542
|
-
} else if (type === "macaddr8") {
|
1543
|
-
columnBuilder = new import_pg_core.PgMacaddr8Builder(columnName);
|
1544
|
-
} else if (type === "numeric" || type.startsWith("numeric(")) {
|
1545
|
-
columnBuilder = new import_pg_core.PgNumericBuilder(columnName);
|
1546
|
-
} else if (type === "real") {
|
1547
|
-
columnBuilder = new import_pg_core.PgRealBuilder(columnName);
|
1548
|
-
} else if (type === "serial") {
|
1549
|
-
columnBuilder = new import_pg_core.PgSerialBuilder(columnName);
|
1550
|
-
} else if (type === "smallint") {
|
1551
|
-
columnBuilder = new import_pg_core.PgSmallIntBuilder(columnName);
|
1552
|
-
} else if (type === "smallserial") {
|
1553
|
-
columnBuilder = new import_pg_core.PgSmallSerialBuilder(columnName);
|
1554
|
-
} else if (type === "text") {
|
1555
|
-
columnBuilder = new import_pg_core.PgTextBuilder(columnName, {});
|
1556
|
-
} else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
|
1557
|
-
columnBuilder = new import_pg_core.PgTimeBuilder(columnName, false, void 0);
|
1558
|
-
} else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
|
1559
|
-
columnBuilder = new import_pg_core.PgTimestampBuilder(columnName, false, void 0);
|
1560
|
-
} else if (type === "uuid") {
|
1561
|
-
columnBuilder = new import_pg_core.PgUUIDBuilder(columnName);
|
1562
|
-
} else if (type === "varchar" || type.startsWith("varchar(")) {
|
1563
|
-
columnBuilder = new import_pg_core.PgVarcharBuilder(columnName, {});
|
1564
|
-
} else if (type === "char" || type.startsWith("char(")) {
|
1565
|
-
columnBuilder = new import_pg_core.PgCharBuilder(columnName, {});
|
1566
|
-
} else {
|
1567
|
-
columnBuilder = (0, import_pg_core.customType)({
|
1568
|
-
dataType() {
|
1569
|
-
return type;
|
1570
|
-
}
|
1571
|
-
})(columnName);
|
1500
|
+
var N;
|
1501
|
+
if (isSequence) {
|
1502
|
+
var x = numeric(n[0]);
|
1503
|
+
var y = numeric(n[1]);
|
1504
|
+
var width = Math.max(n[0].length, n[1].length);
|
1505
|
+
var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
|
1506
|
+
var test = lte;
|
1507
|
+
var reverse = y < x;
|
1508
|
+
if (reverse) {
|
1509
|
+
incr *= -1;
|
1510
|
+
test = gte;
|
1572
1511
|
}
|
1573
|
-
|
1574
|
-
|
1512
|
+
var pad = n.some(isPadded);
|
1513
|
+
N = [];
|
1514
|
+
for (var i = x; test(i, y); i += incr) {
|
1515
|
+
var c;
|
1516
|
+
if (isAlphaSequence) {
|
1517
|
+
c = String.fromCharCode(i);
|
1518
|
+
if (c === "\\")
|
1519
|
+
c = "";
|
1520
|
+
} else {
|
1521
|
+
c = String(i);
|
1522
|
+
if (pad) {
|
1523
|
+
var need = width - c.length;
|
1524
|
+
if (need > 0) {
|
1525
|
+
var z = new Array(need + 1).join("0");
|
1526
|
+
if (i < 0)
|
1527
|
+
c = "-" + z + c.slice(1);
|
1528
|
+
else
|
1529
|
+
c = z + c;
|
1530
|
+
}
|
1531
|
+
}
|
1532
|
+
}
|
1533
|
+
N.push(c);
|
1575
1534
|
}
|
1576
|
-
|
1577
|
-
|
1535
|
+
} else {
|
1536
|
+
N = [];
|
1537
|
+
for (var j = 0; j < n.length; j++) {
|
1538
|
+
N.push.apply(N, expand2(n[j], false));
|
1578
1539
|
}
|
1579
|
-
|
1580
|
-
|
1540
|
+
}
|
1541
|
+
for (var j = 0; j < N.length; j++) {
|
1542
|
+
for (var k = 0; k < post.length; k++) {
|
1543
|
+
var expansion = pre + N[j] + post[k];
|
1544
|
+
if (!isTop || isSequence || expansion)
|
1545
|
+
expansions.push(expansion);
|
1581
1546
|
}
|
1582
|
-
columns[columnName] = columnBuilder;
|
1583
|
-
});
|
1584
|
-
if (schemaName === "public") {
|
1585
|
-
tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
|
1586
|
-
const res = {};
|
1587
|
-
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
1588
|
-
const gh = cpk.columns.map((c) => cb[c]);
|
1589
|
-
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
1590
|
-
gh,
|
1591
|
-
cpk.name
|
1592
|
-
);
|
1593
|
-
});
|
1594
|
-
return res;
|
1595
|
-
});
|
1596
|
-
} else {
|
1597
|
-
tables[t.name] = (0, import_pg_core.pgSchema)(schemaName).table(t.name, columns, (cb) => {
|
1598
|
-
const res = {};
|
1599
|
-
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
1600
|
-
const gh = cpk.columns.map((c) => cb[c]);
|
1601
|
-
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
1602
|
-
gh,
|
1603
|
-
cpk.name
|
1604
|
-
);
|
1605
|
-
});
|
1606
|
-
return res;
|
1607
|
-
});
|
1608
1547
|
}
|
1609
|
-
}
|
1610
|
-
return
|
1611
|
-
}
|
1548
|
+
}
|
1549
|
+
return expansions;
|
1550
|
+
}
|
1612
1551
|
}
|
1613
1552
|
});
|
1614
1553
|
|
1615
|
-
// src/serializer/
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
"
|
1620
|
-
|
1621
|
-
"tinyint",
|
1622
|
-
"smallint",
|
1623
|
-
"mediumint",
|
1624
|
-
"bigint",
|
1625
|
-
"unsigned big int",
|
1626
|
-
"int2",
|
1627
|
-
"int8"
|
1628
|
-
].includes(sqlType.toLowerCase())) {
|
1629
|
-
return "integer";
|
1630
|
-
} else if ([
|
1631
|
-
"character",
|
1632
|
-
"varchar",
|
1633
|
-
"vatying character",
|
1634
|
-
"nchar",
|
1635
|
-
"native character",
|
1636
|
-
"nvarchar",
|
1637
|
-
"text",
|
1638
|
-
"clob"
|
1639
|
-
].some((it) => it.startsWith(sqlType.toLowerCase()))) {
|
1640
|
-
return "text";
|
1641
|
-
} else if (sqlType.toLowerCase() === "blob") {
|
1642
|
-
return "blob";
|
1643
|
-
} else if (["real", "double", "double precision", "float"].includes(
|
1644
|
-
sqlType.toLowerCase()
|
1645
|
-
)) {
|
1646
|
-
return "real";
|
1647
|
-
} else {
|
1648
|
-
return "numeric";
|
1649
|
-
}
|
1650
|
-
}
|
1651
|
-
var import_drizzle_orm2, import_sqlite_core, dialect2, fromDatabase2, toDrizzle2;
|
1652
|
-
var init_sqliteSerializer = __esm({
|
1653
|
-
"src/serializer/sqliteSerializer.ts"() {
|
1554
|
+
// src/serializer/pgSerializer.ts
|
1555
|
+
var import_pg_core2, import_pg_core3, import_drizzle_orm2, dialect2, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
|
1556
|
+
var init_pgSerializer = __esm({
|
1557
|
+
"src/serializer/pgSerializer.ts"() {
|
1558
|
+
import_pg_core2 = require("drizzle-orm/pg-core");
|
1559
|
+
import_pg_core3 = require("drizzle-orm/pg-core");
|
1654
1560
|
import_drizzle_orm2 = require("drizzle-orm");
|
1655
|
-
import_sqlite_core = require("drizzle-orm/sqlite-core");
|
1656
1561
|
init_serializer();
|
1657
|
-
init_outputs();
|
1658
1562
|
init_source();
|
1659
|
-
|
1660
|
-
|
1563
|
+
init_outputs();
|
1564
|
+
dialect2 = new import_pg_core2.PgDialect();
|
1565
|
+
trimChar = (str, char) => {
|
1566
|
+
let start = 0;
|
1567
|
+
let end = str.length;
|
1568
|
+
while (start < end && str[start] === char)
|
1569
|
+
++start;
|
1570
|
+
while (end > start && str[end - 1] === char)
|
1571
|
+
--end;
|
1572
|
+
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
1573
|
+
};
|
1574
|
+
fromDatabase2 = async (db, tablesFilter = (table) => true, schemaFilters, progressCallback) => {
|
1661
1575
|
const result = {};
|
1662
|
-
const
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
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';
|
1667
|
-
`
|
1668
|
-
);
|
1669
|
-
const tablesWithSeq = [];
|
1670
|
-
const seq = await db.query(
|
1671
|
-
`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[^'']*';`
|
1576
|
+
const internals = { tables: {} };
|
1577
|
+
const where = schemaFilters.map((t) => `table_schema = '${t}'`).join(" or ");
|
1578
|
+
const allTables = await db.query(
|
1579
|
+
`SELECT table_schema, table_name FROM information_schema.tables WHERE ${where};`
|
1672
1580
|
);
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1581
|
+
const schemas = new Set(allTables.map((it) => it.table_schema));
|
1582
|
+
schemas.delete("public");
|
1583
|
+
const allSchemas = await db.query(`select s.nspname as table_schema
|
1584
|
+
from pg_catalog.pg_namespace s
|
1585
|
+
join pg_catalog.pg_user u on u.usesysid = s.nspowner
|
1586
|
+
where nspname not in ('information_schema', 'pg_catalog', 'public')
|
1587
|
+
and nspname not like 'pg_toast%'
|
1588
|
+
and nspname not like 'pg_temp_%'
|
1589
|
+
order by table_schema;`);
|
1590
|
+
allSchemas.forEach((item) => {
|
1591
|
+
if (schemaFilters.includes(item.table_schema)) {
|
1592
|
+
schemas.add(item.table_schema);
|
1593
|
+
}
|
1594
|
+
});
|
1676
1595
|
let columnsCount = 0;
|
1677
|
-
let tablesCount = /* @__PURE__ */ new Set();
|
1678
1596
|
let indexesCount = 0;
|
1679
1597
|
let foreignKeysCount = 0;
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1598
|
+
let tableCount = 0;
|
1599
|
+
const all = allTables.map((row) => {
|
1600
|
+
return new Promise(async (res, rej) => {
|
1601
|
+
const tableName = row.table_name;
|
1602
|
+
if (!tablesFilter(tableName))
|
1603
|
+
return res("");
|
1604
|
+
tableCount += 1;
|
1605
|
+
const tableSchema = row.table_schema;
|
1606
|
+
try {
|
1607
|
+
const columnToReturn = {};
|
1608
|
+
const indexToReturn = {};
|
1609
|
+
const foreignKeysToReturn = {};
|
1610
|
+
const primaryKeys = {};
|
1611
|
+
const uniqueConstrains = {};
|
1612
|
+
const tableResponse = await db.query(
|
1613
|
+
`SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
|
1614
|
+
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
1615
|
+
AND EXISTS (
|
1616
|
+
SELECT FROM pg_attrdef ad
|
1617
|
+
WHERE ad.adrelid = a.attrelid
|
1618
|
+
AND ad.adnum = a.attnum
|
1619
|
+
AND pg_get_expr(ad.adbin, ad.adrelid)
|
1620
|
+
= 'nextval('''
|
1621
|
+
|| (pg_get_serial_sequence (a.attrelid::regclass::text
|
1622
|
+
, a.attname))::regclass
|
1623
|
+
|| '''::regclass)'
|
1624
|
+
)
|
1625
|
+
THEN CASE a.atttypid
|
1626
|
+
WHEN 'int'::regtype THEN 'serial'
|
1627
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
1628
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
1629
|
+
END
|
1630
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
1631
|
+
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, INFORMATION_SCHEMA.COLUMNS.column_name, INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt
|
1632
|
+
FROM pg_attribute a
|
1633
|
+
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
1634
|
+
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}'
|
1635
|
+
AND a.attnum > 0
|
1636
|
+
AND NOT a.attisdropped
|
1637
|
+
ORDER BY a.attnum;`
|
1638
|
+
);
|
1639
|
+
const tableConstraints = await db.query(
|
1640
|
+
`SELECT c.column_name, c.data_type, constraint_type, constraint_name, constraint_schema
|
1641
|
+
FROM information_schema.table_constraints tc
|
1642
|
+
JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
|
1643
|
+
JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema
|
1644
|
+
AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
|
1645
|
+
WHERE tc.table_name = '${tableName}' and constraint_schema = '${tableSchema}';`
|
1646
|
+
);
|
1647
|
+
columnsCount += tableResponse.length;
|
1648
|
+
if (progressCallback) {
|
1649
|
+
progressCallback("columns", columnsCount, "fetching");
|
1650
|
+
}
|
1651
|
+
const tableForeignKeys = await db.query(
|
1652
|
+
`SELECT
|
1653
|
+
tc.table_schema,
|
1654
|
+
tc.constraint_name,
|
1655
|
+
tc.table_name,
|
1656
|
+
kcu.column_name,
|
1657
|
+
(
|
1658
|
+
SELECT ccu.table_schema
|
1659
|
+
FROM information_schema.constraint_column_usage ccu
|
1660
|
+
WHERE ccu.constraint_name = tc.constraint_name
|
1661
|
+
LIMIT 1
|
1662
|
+
) AS foreign_table_schema,
|
1663
|
+
ccu.table_name AS foreign_table_name,
|
1664
|
+
ccu.column_name AS foreign_column_name,
|
1665
|
+
rc.delete_rule,
|
1666
|
+
rc.update_rule
|
1667
|
+
FROM
|
1668
|
+
information_schema.table_constraints AS tc
|
1669
|
+
JOIN information_schema.key_column_usage AS kcu
|
1670
|
+
ON tc.constraint_name = kcu.constraint_name
|
1671
|
+
AND tc.table_schema = kcu.table_schema
|
1672
|
+
JOIN information_schema.constraint_column_usage AS ccu
|
1673
|
+
ON ccu.constraint_name = tc.constraint_name
|
1674
|
+
JOIN information_schema.referential_constraints AS rc
|
1675
|
+
ON ccu.constraint_name = rc.constraint_name
|
1676
|
+
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
|
1677
|
+
);
|
1678
|
+
foreignKeysCount += tableForeignKeys.length;
|
1679
|
+
if (progressCallback) {
|
1680
|
+
progressCallback("fks", foreignKeysCount, "fetching");
|
1681
|
+
}
|
1682
|
+
for (const fk of tableForeignKeys) {
|
1683
|
+
const columnFrom = fk.column_name;
|
1684
|
+
const tableTo = fk.foreign_table_name;
|
1685
|
+
const columnTo = fk.foreign_column_name;
|
1686
|
+
const schemaTo = fk.foreign_table_schema;
|
1687
|
+
const foreignKeyName = fk.constraint_name;
|
1688
|
+
const onUpdate = fk.update_rule.toLowerCase();
|
1689
|
+
const onDelete = fk.delete_rule.toLowerCase();
|
1690
|
+
if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
|
1691
|
+
foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
|
1692
|
+
foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
|
1693
|
+
} else {
|
1694
|
+
foreignKeysToReturn[foreignKeyName] = {
|
1695
|
+
name: foreignKeyName,
|
1696
|
+
tableFrom: tableName,
|
1697
|
+
tableTo,
|
1698
|
+
schemaTo,
|
1699
|
+
columnsFrom: [columnFrom],
|
1700
|
+
columnsTo: [columnTo],
|
1701
|
+
onDelete,
|
1702
|
+
onUpdate
|
1703
|
+
};
|
1704
|
+
}
|
1705
|
+
foreignKeysToReturn[foreignKeyName].columnsFrom = [
|
1706
|
+
...new Set(foreignKeysToReturn[foreignKeyName].columnsFrom)
|
1707
|
+
];
|
1708
|
+
foreignKeysToReturn[foreignKeyName].columnsTo = [
|
1709
|
+
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
1710
|
+
];
|
1711
|
+
}
|
1712
|
+
const uniqueConstrainsRows = tableConstraints.filter(
|
1713
|
+
(mapRow) => mapRow.constraint_type === "UNIQUE"
|
1714
|
+
);
|
1715
|
+
for (const unqs of uniqueConstrainsRows) {
|
1716
|
+
const columnName = unqs.column_name;
|
1717
|
+
const constraintName = unqs.constraint_name;
|
1718
|
+
if (typeof uniqueConstrains[constraintName] !== "undefined") {
|
1719
|
+
uniqueConstrains[constraintName].columns.push(columnName);
|
1720
|
+
} else {
|
1721
|
+
uniqueConstrains[constraintName] = {
|
1722
|
+
columns: [columnName],
|
1723
|
+
nullsNotDistinct: false,
|
1724
|
+
name: constraintName
|
1725
|
+
};
|
1726
|
+
}
|
1727
|
+
}
|
1728
|
+
for (const columnResponse of tableResponse) {
|
1729
|
+
const columnName = columnResponse.attname;
|
1730
|
+
const columnAdditionalDT = columnResponse.additional_dt;
|
1731
|
+
const columnDimensions = columnResponse.array_dimensions;
|
1732
|
+
let columnType = columnResponse.data_type;
|
1733
|
+
const primaryKey = tableConstraints.filter(
|
1734
|
+
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
|
1735
|
+
);
|
1736
|
+
const cprimaryKey = tableConstraints.filter(
|
1737
|
+
(mapRow) => mapRow.constraint_type === "PRIMARY KEY"
|
1738
|
+
);
|
1739
|
+
if (cprimaryKey.length > 1) {
|
1740
|
+
const tableCompositePkName = await db.query(
|
1741
|
+
`SELECT conname AS primary_key
|
1742
|
+
FROM pg_constraint join pg_class on (pg_class.oid = conrelid)
|
1743
|
+
WHERE contype = 'p'
|
1744
|
+
AND connamespace = $1::regnamespace
|
1745
|
+
AND pg_class.relname = $2;`,
|
1746
|
+
[tableSchema, tableName]
|
1747
|
+
);
|
1748
|
+
primaryKeys[tableCompositePkName[0].primary_key] = {
|
1749
|
+
name: tableCompositePkName[0].primary_key,
|
1750
|
+
columns: cprimaryKey.map((c) => c.column_name)
|
1751
|
+
};
|
1752
|
+
}
|
1753
|
+
const defaultValue = defaultForColumn(columnResponse);
|
1754
|
+
const isSerial = columnType === "serial";
|
1755
|
+
let columnTypeMapped = columnType;
|
1756
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
1757
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
1758
|
+
}
|
1759
|
+
if (columnAdditionalDT === "ARRAY") {
|
1760
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
1761
|
+
internals.tables[tableName] = {
|
1762
|
+
columns: {
|
1763
|
+
[columnName]: {
|
1764
|
+
isArray: true,
|
1765
|
+
dimensions: columnDimensions,
|
1766
|
+
rawType: columnTypeMapped.substring(
|
1767
|
+
0,
|
1768
|
+
columnTypeMapped.length - 2
|
1769
|
+
)
|
1770
|
+
}
|
1771
|
+
}
|
1772
|
+
};
|
1773
|
+
} else {
|
1774
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
1775
|
+
internals.tables[tableName].columns[columnName] = {
|
1776
|
+
isArray: true,
|
1777
|
+
dimensions: columnDimensions,
|
1778
|
+
rawType: columnTypeMapped.substring(
|
1779
|
+
0,
|
1780
|
+
columnTypeMapped.length - 2
|
1781
|
+
)
|
1782
|
+
};
|
1783
|
+
}
|
1784
|
+
}
|
1785
|
+
}
|
1786
|
+
if (columnAdditionalDT === "ARRAY") {
|
1787
|
+
for (let i = 1; i < Number(columnDimensions); i++) {
|
1788
|
+
columnTypeMapped += "[]";
|
1789
|
+
}
|
1790
|
+
}
|
1791
|
+
columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
|
1792
|
+
columnTypeMapped = trimChar(columnTypeMapped, '"');
|
1793
|
+
columnToReturn[columnName] = {
|
1794
|
+
name: columnName,
|
1795
|
+
type: columnTypeMapped,
|
1796
|
+
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
1797
|
+
// default: isSerial ? undefined : defaultValue,
|
1798
|
+
notNull: columnResponse.is_nullable === "NO"
|
1799
|
+
};
|
1800
|
+
if (!isSerial && typeof defaultValue !== "undefined") {
|
1801
|
+
columnToReturn[columnName].default = defaultValue;
|
1802
|
+
}
|
1742
1803
|
}
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1804
|
+
const dbIndexes = await db.query(
|
1805
|
+
`SELECT t.relname as table_name, i.relname AS index_name, ix.indisunique AS is_unique, a.attname AS column_name
|
1806
|
+
FROM pg_class t
|
1807
|
+
JOIN pg_index ix ON t.oid = ix.indrelid
|
1808
|
+
JOIN pg_class i ON i.oid = ix.indexrelid
|
1809
|
+
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
|
1810
|
+
JOIN pg_namespace ns ON ns.oid = t.relnamespace
|
1811
|
+
WHERE ns.nspname = '${tableSchema}'
|
1812
|
+
AND t.relname = '${tableName}'
|
1813
|
+
and ix.indisprimary = false;`
|
1814
|
+
);
|
1815
|
+
const dbIndexFromConstraint = await db.query(
|
1816
|
+
`SELECT
|
1817
|
+
idx.indexrelname AS index_name,
|
1818
|
+
idx.relname AS table_name,
|
1819
|
+
schemaname,
|
1820
|
+
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
|
1821
|
+
FROM
|
1822
|
+
pg_stat_user_indexes idx
|
1823
|
+
LEFT JOIN
|
1824
|
+
pg_constraint con ON con.conindid = idx.indexrelid
|
1825
|
+
WHERE idx.relname = '${tableName}' and schemaname = '${tableSchema}'
|
1826
|
+
group by index_name, table_name,schemaname, generated_by_constraint;`
|
1827
|
+
);
|
1828
|
+
const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
|
1829
|
+
for (const dbIndex of dbIndexes) {
|
1830
|
+
const indexName2 = dbIndex.index_name;
|
1831
|
+
const indexColumnName = dbIndex.column_name;
|
1832
|
+
const indexIsUnique = dbIndex.is_unique;
|
1833
|
+
if (idxsInConsteraint.includes(indexName2))
|
1834
|
+
continue;
|
1835
|
+
if (typeof indexToReturn[indexName2] !== "undefined") {
|
1836
|
+
indexToReturn[indexName2].columns.push(indexColumnName);
|
1837
|
+
} else {
|
1838
|
+
indexToReturn[indexName2] = {
|
1839
|
+
name: indexName2,
|
1840
|
+
columns: [indexColumnName],
|
1841
|
+
isUnique: indexIsUnique
|
1842
|
+
};
|
1843
|
+
}
|
1844
|
+
}
|
1845
|
+
indexesCount += Object.keys(indexToReturn).length;
|
1846
|
+
if (progressCallback) {
|
1847
|
+
progressCallback("indexes", indexesCount, "fetching");
|
1848
|
+
}
|
1849
|
+
result[tableName] = {
|
1850
|
+
name: tableName,
|
1851
|
+
schema: tableSchema !== "public" ? tableSchema : "",
|
1852
|
+
columns: columnToReturn,
|
1853
|
+
indexes: indexToReturn,
|
1854
|
+
foreignKeys: foreignKeysToReturn,
|
1855
|
+
compositePrimaryKeys: primaryKeys,
|
1856
|
+
uniqueConstraints: uniqueConstrains
|
1787
1857
|
};
|
1858
|
+
} catch (e) {
|
1859
|
+
rej(e);
|
1860
|
+
return;
|
1788
1861
|
}
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
"_"
|
1793
|
-
)}_${refTableName}_${columnsTo.join("_")}_fk`;
|
1794
|
-
}
|
1795
|
-
for (const idx of Object.keys(fkByTableName)) {
|
1796
|
-
const value = fkByTableName[idx];
|
1797
|
-
result[value.tableFrom].foreignKeys[value.name] = value;
|
1798
|
-
}
|
1799
|
-
} catch (e) {
|
1800
|
-
}
|
1862
|
+
res("");
|
1863
|
+
});
|
1864
|
+
});
|
1801
1865
|
if (progressCallback) {
|
1802
|
-
progressCallback("
|
1866
|
+
progressCallback("tables", tableCount, "done");
|
1803
1867
|
}
|
1804
|
-
const
|
1805
|
-
`SELECT
|
1806
|
-
m.tbl_name as tableName,
|
1807
|
-
il.name as indexName,
|
1808
|
-
ii.name as columnName,
|
1809
|
-
il.[unique] as isUnique,
|
1810
|
-
il.seq as seq
|
1811
|
-
FROM sqlite_master AS m,
|
1812
|
-
pragma_index_list(m.name) AS il,
|
1813
|
-
pragma_index_info(il.name) AS ii
|
1814
|
-
WHERE
|
1815
|
-
m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
|
1816
|
-
);
|
1817
|
-
for (const idxRow of idxs) {
|
1818
|
-
const tableName = idxRow.tableName;
|
1819
|
-
const constraintName = idxRow.indexName;
|
1820
|
-
const columnName = idxRow.columnName;
|
1821
|
-
const isUnique = idxRow.isUnique === 1;
|
1822
|
-
const tableInResult = result[tableName];
|
1823
|
-
if (typeof tableInResult === "undefined")
|
1824
|
-
continue;
|
1825
|
-
indexesCount += 1;
|
1826
|
-
if (progressCallback) {
|
1827
|
-
progressCallback("indexes", indexesCount, "fetching");
|
1828
|
-
}
|
1829
|
-
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
1830
|
-
tableInResult.indexes[constraintName].columns.push(columnName);
|
1831
|
-
} else {
|
1832
|
-
tableInResult.indexes[constraintName] = {
|
1833
|
-
name: constraintName,
|
1834
|
-
columns: [columnName],
|
1835
|
-
isUnique
|
1836
|
-
};
|
1837
|
-
}
|
1868
|
+
for await (const _ of all) {
|
1838
1869
|
}
|
1839
1870
|
if (progressCallback) {
|
1871
|
+
progressCallback("columns", columnsCount, "done");
|
1840
1872
|
progressCallback("indexes", indexesCount, "done");
|
1841
|
-
progressCallback("
|
1873
|
+
progressCallback("fks", foreignKeysCount, "done");
|
1842
1874
|
}
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
if (type === "integer") {
|
1863
|
-
columnBuilder = new import_sqlite_core.SQLiteIntegerBuilder(columnName);
|
1864
|
-
} else if (type === "text") {
|
1865
|
-
columnBuilder = new import_sqlite_core.SQLiteTextBuilder(columnName, {});
|
1866
|
-
} else if (type === "blob") {
|
1867
|
-
columnBuilder = new import_sqlite_core.SQLiteBlobBufferBuilder(columnName);
|
1868
|
-
} else if (type === "real") {
|
1869
|
-
columnBuilder = new import_sqlite_core.SQLiteRealBuilder(columnName);
|
1870
|
-
} else {
|
1871
|
-
columnBuilder = new import_sqlite_core.SQLiteNumericBuilder(columnName);
|
1872
|
-
}
|
1873
|
-
if (c.notNull) {
|
1874
|
-
columnBuilder = columnBuilder.notNull();
|
1875
|
-
}
|
1876
|
-
if (c.default) {
|
1877
|
-
columnBuilder = columnBuilder.default(c.default);
|
1878
|
-
}
|
1879
|
-
if (c.primaryKey) {
|
1880
|
-
columnBuilder = columnBuilder.primaryKey();
|
1881
|
-
}
|
1882
|
-
columns[columnName] = columnBuilder;
|
1883
|
-
});
|
1884
|
-
tables[t.name] = (0, import_sqlite_core.sqliteTable)(t.name, columns, (cb) => {
|
1885
|
-
const res = {};
|
1886
|
-
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
1887
|
-
const gh = cpk.columns.map((c) => cb[c]);
|
1888
|
-
res[cpk.name] = new import_sqlite_core.PrimaryKeyBuilder(
|
1889
|
-
gh,
|
1890
|
-
cpk.name
|
1891
|
-
);
|
1892
|
-
});
|
1893
|
-
return res;
|
1894
|
-
});
|
1895
|
-
});
|
1896
|
-
return tables;
|
1897
|
-
};
|
1898
|
-
}
|
1899
|
-
});
|
1900
|
-
|
1901
|
-
// node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js
|
1902
|
-
var require_balanced_match = __commonJS({
|
1903
|
-
"node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js"(exports, module2) {
|
1904
|
-
"use strict";
|
1905
|
-
module2.exports = balanced;
|
1906
|
-
function balanced(a, b, str) {
|
1907
|
-
if (a instanceof RegExp)
|
1908
|
-
a = maybeMatch(a, str);
|
1909
|
-
if (b instanceof RegExp)
|
1910
|
-
b = maybeMatch(b, str);
|
1911
|
-
var r = range(a, b, str);
|
1912
|
-
return r && {
|
1913
|
-
start: r[0],
|
1914
|
-
end: r[1],
|
1915
|
-
pre: str.slice(0, r[0]),
|
1916
|
-
body: str.slice(r[0] + a.length, r[1]),
|
1917
|
-
post: str.slice(r[1] + b.length)
|
1918
|
-
};
|
1919
|
-
}
|
1920
|
-
function maybeMatch(reg, str) {
|
1921
|
-
var m = str.match(reg);
|
1922
|
-
return m ? m[0] : null;
|
1923
|
-
}
|
1924
|
-
balanced.range = range;
|
1925
|
-
function range(a, b, str) {
|
1926
|
-
var begs, beg, left, right, result;
|
1927
|
-
var ai = str.indexOf(a);
|
1928
|
-
var bi = str.indexOf(b, ai + 1);
|
1929
|
-
var i = ai;
|
1930
|
-
if (ai >= 0 && bi > 0) {
|
1931
|
-
if (a === b) {
|
1932
|
-
return [ai, bi];
|
1933
|
-
}
|
1934
|
-
begs = [];
|
1935
|
-
left = str.length;
|
1936
|
-
while (i >= 0 && !result) {
|
1937
|
-
if (i == ai) {
|
1938
|
-
begs.push(i);
|
1939
|
-
ai = str.indexOf(a, i + 1);
|
1940
|
-
} else if (begs.length == 1) {
|
1941
|
-
result = [begs.pop(), bi];
|
1942
|
-
} else {
|
1943
|
-
beg = begs.pop();
|
1944
|
-
if (beg < left) {
|
1945
|
-
left = beg;
|
1946
|
-
right = bi;
|
1947
|
-
}
|
1948
|
-
bi = str.indexOf(b, i + 1);
|
1949
|
-
}
|
1950
|
-
i = ai < bi && ai >= 0 ? ai : bi;
|
1951
|
-
}
|
1952
|
-
if (begs.length) {
|
1953
|
-
result = [left, right];
|
1875
|
+
const allEnums = await db.query(
|
1876
|
+
`select n.nspname as enum_schema,
|
1877
|
+
t.typname as enum_name,
|
1878
|
+
e.enumlabel as enum_value
|
1879
|
+
from pg_type t
|
1880
|
+
join pg_enum e on t.oid = e.enumtypid
|
1881
|
+
join pg_catalog.pg_namespace n ON n.oid = t.typnamespace;`
|
1882
|
+
);
|
1883
|
+
const enumsToReturn = {};
|
1884
|
+
for (const dbEnum of allEnums) {
|
1885
|
+
const enumName = dbEnum.enum_name;
|
1886
|
+
const enumValue = dbEnum.enum_value;
|
1887
|
+
if (enumsToReturn[enumName] !== void 0 && enumsToReturn[enumName] !== null) {
|
1888
|
+
enumsToReturn[enumName].values[enumValue] = enumValue;
|
1889
|
+
} else {
|
1890
|
+
enumsToReturn[enumName] = {
|
1891
|
+
name: enumName,
|
1892
|
+
values: { [enumValue]: enumValue }
|
1893
|
+
};
|
1954
1894
|
}
|
1955
1895
|
}
|
1956
|
-
|
1957
|
-
|
1958
|
-
}
|
1959
|
-
});
|
1960
|
-
|
1961
|
-
// node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js
|
1962
|
-
var require_brace_expansion = __commonJS({
|
1963
|
-
"node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js"(exports, module2) {
|
1964
|
-
var balanced = require_balanced_match();
|
1965
|
-
module2.exports = expandTop;
|
1966
|
-
var escSlash = "\0SLASH" + Math.random() + "\0";
|
1967
|
-
var escOpen = "\0OPEN" + Math.random() + "\0";
|
1968
|
-
var escClose = "\0CLOSE" + Math.random() + "\0";
|
1969
|
-
var escComma = "\0COMMA" + Math.random() + "\0";
|
1970
|
-
var escPeriod = "\0PERIOD" + Math.random() + "\0";
|
1971
|
-
function numeric(str) {
|
1972
|
-
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
|
1973
|
-
}
|
1974
|
-
function escapeBraces(str) {
|
1975
|
-
return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
|
1976
|
-
}
|
1977
|
-
function unescapeBraces(str) {
|
1978
|
-
return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
|
1979
|
-
}
|
1980
|
-
function parseCommaParts(str) {
|
1981
|
-
if (!str)
|
1982
|
-
return [""];
|
1983
|
-
var parts = [];
|
1984
|
-
var m = balanced("{", "}", str);
|
1985
|
-
if (!m)
|
1986
|
-
return str.split(",");
|
1987
|
-
var pre = m.pre;
|
1988
|
-
var body = m.body;
|
1989
|
-
var post = m.post;
|
1990
|
-
var p = pre.split(",");
|
1991
|
-
p[p.length - 1] += "{" + body + "}";
|
1992
|
-
var postParts = parseCommaParts(post);
|
1993
|
-
if (post.length) {
|
1994
|
-
p[p.length - 1] += postParts.shift();
|
1995
|
-
p.push.apply(p, postParts);
|
1896
|
+
if (progressCallback) {
|
1897
|
+
progressCallback("enums", Object.keys(enumsToReturn).length, "done");
|
1996
1898
|
}
|
1997
|
-
|
1998
|
-
return
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
1899
|
+
const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
|
1900
|
+
return {
|
1901
|
+
version: "5",
|
1902
|
+
dialect: "pg",
|
1903
|
+
tables: result,
|
1904
|
+
enums: enumsToReturn,
|
1905
|
+
schemas: schemasObject,
|
1906
|
+
_meta: {
|
1907
|
+
schemas: {},
|
1908
|
+
tables: {},
|
1909
|
+
columns: {}
|
1910
|
+
},
|
1911
|
+
internal: internals
|
1912
|
+
};
|
1913
|
+
};
|
1914
|
+
columnToDefault = {
|
1915
|
+
"numeric(": "::numeric",
|
1916
|
+
// text: "::text",
|
1917
|
+
// "character varying": "::character varying",
|
1918
|
+
// "double precision": "::double precision",
|
1919
|
+
// "time with time zone": "::time with time zone",
|
1920
|
+
"time without time zone": "::time without time zone",
|
1921
|
+
// "timestamp with time zone": "::timestamp with time zone",
|
1922
|
+
"timestamp without time zone": "::timestamp without time zone",
|
1923
|
+
// date: "::date",
|
1924
|
+
// interval: "::interval",
|
1925
|
+
// character: "::bpchar",
|
1926
|
+
// macaddr8: "::macaddr8",
|
1927
|
+
// macaddr: "::macaddr",
|
1928
|
+
// inet: "::inet",
|
1929
|
+
// cidr: "::cidr",
|
1930
|
+
// jsonb: "::jsonb",
|
1931
|
+
// json: "::json",
|
1932
|
+
"character(": "::bpchar"
|
1933
|
+
};
|
1934
|
+
defaultForColumn = (column) => {
|
1935
|
+
if (column.data_type === "serial" || column.data_type === "smallserial" || column.data_type === "bigserial") {
|
1936
|
+
return void 0;
|
2005
1937
|
}
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
var pre = m.pre;
|
2026
|
-
var post = m.post.length ? expand2(m.post, false) : [""];
|
2027
|
-
if (/\$$/.test(m.pre)) {
|
2028
|
-
for (var k = 0; k < post.length; k++) {
|
2029
|
-
var expansion = pre + "{" + m.body + "}" + post[k];
|
2030
|
-
expansions.push(expansion);
|
2031
|
-
}
|
2032
|
-
} else {
|
2033
|
-
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
2034
|
-
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
2035
|
-
var isSequence = isNumericSequence || isAlphaSequence;
|
2036
|
-
var isOptions = m.body.indexOf(",") >= 0;
|
2037
|
-
if (!isSequence && !isOptions) {
|
2038
|
-
if (m.post.match(/,.*\}/)) {
|
2039
|
-
str = m.pre + "{" + m.body + escClose + m.post;
|
2040
|
-
return expand2(str);
|
2041
|
-
}
|
2042
|
-
return [str];
|
2043
|
-
}
|
2044
|
-
var n;
|
2045
|
-
if (isSequence) {
|
2046
|
-
n = m.body.split(/\.\./);
|
1938
|
+
const hasDifferentDefaultCast = Object.keys(columnToDefault).find(
|
1939
|
+
(it) => column.data_type.startsWith(it)
|
1940
|
+
);
|
1941
|
+
if (column.column_default === null) {
|
1942
|
+
return void 0;
|
1943
|
+
}
|
1944
|
+
const columnDefaultAsString = column.column_default.toString();
|
1945
|
+
if (columnDefaultAsString.endsWith(
|
1946
|
+
hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column.data_type
|
1947
|
+
)) {
|
1948
|
+
const nonPrefixPart = column.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`).length - 1;
|
1949
|
+
const rt = column.column_default.toString().substring(1, nonPrefixPart);
|
1950
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column.data_type.startsWith("numeric")) {
|
1951
|
+
return Number(rt);
|
1952
|
+
} else if (column.data_type === "json" || column.data_type === "jsonb") {
|
1953
|
+
const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
|
1954
|
+
return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`}`;
|
1955
|
+
} else if (column.data_type === "boolean") {
|
1956
|
+
return column.column_default === "true";
|
2047
1957
|
} else {
|
2048
|
-
|
2049
|
-
if (n.length === 1) {
|
2050
|
-
n = expand2(n[0], false).map(embrace);
|
2051
|
-
if (n.length === 1) {
|
2052
|
-
return post.map(function(p) {
|
2053
|
-
return m.pre + n[0] + p;
|
2054
|
-
});
|
2055
|
-
}
|
2056
|
-
}
|
1958
|
+
return `'${rt}'`;
|
2057
1959
|
}
|
2058
|
-
|
2059
|
-
if (
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
|
2064
|
-
var test = lte;
|
2065
|
-
var reverse = y < x;
|
2066
|
-
if (reverse) {
|
2067
|
-
incr *= -1;
|
2068
|
-
test = gte;
|
2069
|
-
}
|
2070
|
-
var pad = n.some(isPadded);
|
2071
|
-
N = [];
|
2072
|
-
for (var i = x; test(i, y); i += incr) {
|
2073
|
-
var c;
|
2074
|
-
if (isAlphaSequence) {
|
2075
|
-
c = String.fromCharCode(i);
|
2076
|
-
if (c === "\\")
|
2077
|
-
c = "";
|
2078
|
-
} else {
|
2079
|
-
c = String(i);
|
2080
|
-
if (pad) {
|
2081
|
-
var need = width - c.length;
|
2082
|
-
if (need > 0) {
|
2083
|
-
var z = new Array(need + 1).join("0");
|
2084
|
-
if (i < 0)
|
2085
|
-
c = "-" + z + c.slice(1);
|
2086
|
-
else
|
2087
|
-
c = z + c;
|
2088
|
-
}
|
2089
|
-
}
|
2090
|
-
}
|
2091
|
-
N.push(c);
|
2092
|
-
}
|
1960
|
+
} else {
|
1961
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column.data_type.startsWith("numeric")) {
|
1962
|
+
return Number(columnDefaultAsString);
|
1963
|
+
} else if (column.data_type === "boolean") {
|
1964
|
+
return column.column_default === "true";
|
2093
1965
|
} else {
|
2094
|
-
|
2095
|
-
for (var j = 0; j < n.length; j++) {
|
2096
|
-
N.push.apply(N, expand2(n[j], false));
|
2097
|
-
}
|
2098
|
-
}
|
2099
|
-
for (var j = 0; j < N.length; j++) {
|
2100
|
-
for (var k = 0; k < post.length; k++) {
|
2101
|
-
var expansion = pre + N[j] + post[k];
|
2102
|
-
if (!isTop || isSequence || expansion)
|
2103
|
-
expansions.push(expansion);
|
2104
|
-
}
|
1966
|
+
return `${columnDefaultAsString}`;
|
2105
1967
|
}
|
2106
1968
|
}
|
2107
|
-
|
2108
|
-
}
|
1969
|
+
};
|
2109
1970
|
}
|
2110
1971
|
});
|
2111
1972
|
|
@@ -2146,14 +2007,162 @@ var utils_studio_exports = {};
|
|
2146
2007
|
__export(utils_studio_exports, {
|
2147
2008
|
DrizzleORMPgClient: () => DrizzleORMPgClient,
|
2148
2009
|
TursoSqlite: () => TursoSqlite,
|
2149
|
-
drizzleSchemaPg: () =>
|
2150
|
-
drizzleSchemaSQLite: () =>
|
2010
|
+
drizzleSchemaPg: () => pgSchemaToDrizzle,
|
2011
|
+
drizzleSchemaSQLite: () => sqliteSchemaToDrizzle,
|
2151
2012
|
pgPushIntrospect: () => pgPushIntrospect,
|
2152
2013
|
sqlitePushIntrospect: () => sqlitePushIntrospect
|
2153
2014
|
});
|
2154
2015
|
module.exports = __toCommonJS(utils_studio_exports);
|
2155
|
-
|
2156
|
-
|
2016
|
+
|
2017
|
+
// src/serializer/schemaToDrizzle.ts
|
2018
|
+
var import_pg_core = require("drizzle-orm/pg-core");
|
2019
|
+
var import_sqlite_core = require("drizzle-orm/sqlite-core");
|
2020
|
+
var pgSchemaToDrizzle = (schema, schemaName) => {
|
2021
|
+
const tables = {};
|
2022
|
+
Object.values(schema.tables).forEach((t) => {
|
2023
|
+
const columns = {};
|
2024
|
+
Object.values(t.columns).forEach((c) => {
|
2025
|
+
const columnName = c.name;
|
2026
|
+
const type = c.type;
|
2027
|
+
let columnBuilder;
|
2028
|
+
if (type === "bigint") {
|
2029
|
+
columnBuilder = new import_pg_core.PgBigInt53Builder(columnName);
|
2030
|
+
} else if (type === "bigserial") {
|
2031
|
+
columnBuilder = new import_pg_core.PgBigSerial53Builder(columnName);
|
2032
|
+
} else if (type === "boolean") {
|
2033
|
+
columnBuilder = new import_pg_core.PgBooleanBuilder(columnName);
|
2034
|
+
} else if (type === "cidr") {
|
2035
|
+
columnBuilder = new import_pg_core.PgCidrBuilder(columnName);
|
2036
|
+
} else if (type === "date") {
|
2037
|
+
columnBuilder = new import_pg_core.PgDateBuilder(columnName);
|
2038
|
+
} else if (type === "double precision") {
|
2039
|
+
columnBuilder = new import_pg_core.PgDoublePrecisionBuilder(columnName);
|
2040
|
+
} else if (type === "inet") {
|
2041
|
+
columnBuilder = new import_pg_core.PgInetBuilder(columnName);
|
2042
|
+
} else if (type === "integer") {
|
2043
|
+
columnBuilder = new import_pg_core.PgIntegerBuilder(columnName);
|
2044
|
+
} else if (type === "interval" || type.startsWith("interval ")) {
|
2045
|
+
columnBuilder = new import_pg_core.PgIntervalBuilder(columnName, {});
|
2046
|
+
} else if (type === "json") {
|
2047
|
+
columnBuilder = new import_pg_core.PgJsonBuilder(columnName);
|
2048
|
+
} else if (type === "jsonb") {
|
2049
|
+
columnBuilder = new import_pg_core.PgJsonbBuilder(columnName);
|
2050
|
+
} else if (type === "macaddr") {
|
2051
|
+
columnBuilder = new import_pg_core.PgMacaddrBuilder(columnName);
|
2052
|
+
} else if (type === "macaddr8") {
|
2053
|
+
columnBuilder = new import_pg_core.PgMacaddr8Builder(columnName);
|
2054
|
+
} else if (type === "numeric" || type.startsWith("numeric(")) {
|
2055
|
+
columnBuilder = new import_pg_core.PgNumericBuilder(columnName);
|
2056
|
+
} else if (type === "real") {
|
2057
|
+
columnBuilder = new import_pg_core.PgRealBuilder(columnName);
|
2058
|
+
} else if (type === "serial") {
|
2059
|
+
columnBuilder = new import_pg_core.PgSerialBuilder(columnName);
|
2060
|
+
} else if (type === "smallint") {
|
2061
|
+
columnBuilder = new import_pg_core.PgSmallIntBuilder(columnName);
|
2062
|
+
} else if (type === "smallserial") {
|
2063
|
+
columnBuilder = new import_pg_core.PgSmallSerialBuilder(columnName);
|
2064
|
+
} else if (type === "text") {
|
2065
|
+
columnBuilder = new import_pg_core.PgTextBuilder(columnName, {});
|
2066
|
+
} else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
|
2067
|
+
columnBuilder = new import_pg_core.PgTimeBuilder(columnName, false, void 0);
|
2068
|
+
} else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
|
2069
|
+
columnBuilder = new import_pg_core.PgTimestampBuilder(columnName, false, void 0);
|
2070
|
+
} else if (type === "uuid") {
|
2071
|
+
columnBuilder = new import_pg_core.PgUUIDBuilder(columnName);
|
2072
|
+
} else if (type === "varchar" || type.startsWith("varchar(")) {
|
2073
|
+
columnBuilder = new import_pg_core.PgVarcharBuilder(columnName, {});
|
2074
|
+
} else if (type === "char" || type.startsWith("char(")) {
|
2075
|
+
columnBuilder = new import_pg_core.PgCharBuilder(columnName, {});
|
2076
|
+
} else {
|
2077
|
+
columnBuilder = (0, import_pg_core.customType)({
|
2078
|
+
dataType() {
|
2079
|
+
return type;
|
2080
|
+
}
|
2081
|
+
})(columnName);
|
2082
|
+
}
|
2083
|
+
if (c.notNull) {
|
2084
|
+
columnBuilder = columnBuilder.notNull();
|
2085
|
+
}
|
2086
|
+
if (c.default) {
|
2087
|
+
columnBuilder = columnBuilder.default(c.default);
|
2088
|
+
}
|
2089
|
+
if (c.primaryKey) {
|
2090
|
+
columnBuilder = columnBuilder.primaryKey();
|
2091
|
+
}
|
2092
|
+
columns[columnName] = columnBuilder;
|
2093
|
+
});
|
2094
|
+
if (schemaName === "public") {
|
2095
|
+
tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
|
2096
|
+
const res = {};
|
2097
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
2098
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
2099
|
+
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
2100
|
+
gh,
|
2101
|
+
cpk.name
|
2102
|
+
);
|
2103
|
+
});
|
2104
|
+
return res;
|
2105
|
+
});
|
2106
|
+
} else {
|
2107
|
+
tables[t.name] = (0, import_pg_core.pgSchema)(schemaName).table(t.name, columns, (cb) => {
|
2108
|
+
const res = {};
|
2109
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
2110
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
2111
|
+
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
2112
|
+
gh,
|
2113
|
+
cpk.name
|
2114
|
+
);
|
2115
|
+
});
|
2116
|
+
return res;
|
2117
|
+
});
|
2118
|
+
}
|
2119
|
+
});
|
2120
|
+
return tables;
|
2121
|
+
};
|
2122
|
+
var sqliteSchemaToDrizzle = (schema) => {
|
2123
|
+
const tables = {};
|
2124
|
+
Object.values(schema.tables).forEach((t) => {
|
2125
|
+
const columns = {};
|
2126
|
+
Object.values(t.columns).forEach((c) => {
|
2127
|
+
const columnName = c.name;
|
2128
|
+
const type = c.type;
|
2129
|
+
let columnBuilder;
|
2130
|
+
if (type === "integer") {
|
2131
|
+
columnBuilder = new import_sqlite_core.SQLiteIntegerBuilder(columnName);
|
2132
|
+
} else if (type === "text") {
|
2133
|
+
columnBuilder = new import_sqlite_core.SQLiteTextBuilder(columnName, {});
|
2134
|
+
} else if (type === "blob") {
|
2135
|
+
columnBuilder = new import_sqlite_core.SQLiteBlobBufferBuilder(columnName);
|
2136
|
+
} else if (type === "real") {
|
2137
|
+
columnBuilder = new import_sqlite_core.SQLiteRealBuilder(columnName);
|
2138
|
+
} else {
|
2139
|
+
columnBuilder = new import_sqlite_core.SQLiteNumericBuilder(columnName);
|
2140
|
+
}
|
2141
|
+
if (c.notNull) {
|
2142
|
+
columnBuilder = columnBuilder.notNull();
|
2143
|
+
}
|
2144
|
+
if (c.default) {
|
2145
|
+
columnBuilder = columnBuilder.default(c.default);
|
2146
|
+
}
|
2147
|
+
if (c.primaryKey) {
|
2148
|
+
columnBuilder = columnBuilder.primaryKey();
|
2149
|
+
}
|
2150
|
+
columns[columnName] = columnBuilder;
|
2151
|
+
});
|
2152
|
+
tables[t.name] = (0, import_sqlite_core.sqliteTable)(t.name, columns, (cb) => {
|
2153
|
+
const res = {};
|
2154
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
2155
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
2156
|
+
res[cpk.name] = new import_sqlite_core.PrimaryKeyBuilder(
|
2157
|
+
gh,
|
2158
|
+
cpk.name
|
2159
|
+
);
|
2160
|
+
});
|
2161
|
+
return res;
|
2162
|
+
});
|
2163
|
+
});
|
2164
|
+
return tables;
|
2165
|
+
};
|
2157
2166
|
|
2158
2167
|
// src/cli/commands/sqliteIntrospect.ts
|
2159
2168
|
init_views();
|
@@ -3331,7 +3340,7 @@ var sqlitePushIntrospect = async (client, filters) => {
|
|
3331
3340
|
}
|
3332
3341
|
return false;
|
3333
3342
|
};
|
3334
|
-
const res = await
|
3343
|
+
const res = await fromDatabase(client, filter2);
|
3335
3344
|
const schema = { id: originUUID, prevId: "", ...res };
|
3336
3345
|
return { schema };
|
3337
3346
|
};
|
@@ -3362,7 +3371,7 @@ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
|
|
3362
3371
|
}
|
3363
3372
|
return false;
|
3364
3373
|
};
|
3365
|
-
const res = await
|
3374
|
+
const res = await fromDatabase2(client, filter2, schemaFilters);
|
3366
3375
|
const schema = { id: originUUID, prevId: "", ...res };
|
3367
3376
|
const { internal, ...schemaWithoutInternals } = schema;
|
3368
3377
|
return { schema: schemaWithoutInternals };
|