forge-sql-orm 2.0.27 → 2.0.29
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/dist/ForgeSQLORM.js +51 -21
- package/dist/ForgeSQLORM.js.map +1 -1
- package/dist/ForgeSQLORM.mjs +51 -21
- package/dist/ForgeSQLORM.mjs.map +1 -1
- package/dist/core/ForgeSQLAnalyseOperations.d.ts.map +1 -1
- package/dist/utils/sqlUtils.d.ts +13 -6
- package/dist/utils/sqlUtils.d.ts.map +1 -1
- package/dist/webtriggers/dropMigrationWebTrigger.d.ts +5 -5
- package/dist/webtriggers/dropTablesMigrationWebTrigger.d.ts +26 -0
- package/dist/webtriggers/dropTablesMigrationWebTrigger.d.ts.map +1 -0
- package/dist/webtriggers/index.d.ts +1 -0
- package/dist/webtriggers/index.d.ts.map +1 -1
- package/package.json +16 -10
- package/src/core/ForgeSQLAnalyseOperations.ts +3 -2
- package/src/core/ForgeSQLQueryBuilder.ts +8 -8
- package/src/utils/sqlUtils.ts +40 -17
- package/src/webtriggers/dropMigrationWebTrigger.ts +6 -6
- package/src/webtriggers/dropTablesMigrationWebTrigger.ts +50 -0
- package/src/webtriggers/index.ts +1 -0
package/dist/ForgeSQLORM.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const drizzleOrm = require("drizzle-orm");
|
|
4
|
-
const
|
|
4
|
+
const luxon = require("luxon");
|
|
5
5
|
const sql = require("drizzle-orm/sql/sql");
|
|
6
6
|
const sql$1 = require("@forge/sql");
|
|
7
7
|
const mysqlProxy = require("drizzle-orm/mysql-proxy");
|
|
8
8
|
const mysqlCore = require("drizzle-orm/mysql-core");
|
|
9
|
-
const moment$1 = require("moment/moment.js");
|
|
10
9
|
const table = require("drizzle-orm/table");
|
|
11
10
|
const parseDateTime = (value, format) => {
|
|
12
11
|
let result;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
if (value instanceof Date) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
const dt = luxon.DateTime.fromFormat(value, format);
|
|
16
|
+
if (dt.isValid) {
|
|
17
|
+
result = dt.toJSDate();
|
|
18
|
+
} else {
|
|
19
|
+
const isoDt = luxon.DateTime.fromISO(value);
|
|
20
|
+
if (isoDt.isValid) {
|
|
21
|
+
result = isoDt.toJSDate();
|
|
18
22
|
} else {
|
|
19
23
|
result = new Date(value);
|
|
20
24
|
}
|
|
21
|
-
} else {
|
|
22
|
-
result = m.toDate();
|
|
23
25
|
}
|
|
24
26
|
if (isNaN(result.getTime())) {
|
|
25
27
|
result = new Date(value);
|
|
@@ -127,11 +129,20 @@ function getTableMetadata(table2) {
|
|
|
127
129
|
...builders
|
|
128
130
|
};
|
|
129
131
|
}
|
|
130
|
-
function generateDropTableStatements(tables) {
|
|
132
|
+
function generateDropTableStatements(tables, options) {
|
|
131
133
|
const dropStatements = [];
|
|
134
|
+
const validOptions = options ?? { sequence: true, table: true };
|
|
135
|
+
if (!validOptions.sequence && !validOptions.table) {
|
|
136
|
+
console.warn('No drop operations requested: both "table" and "sequence" options are false');
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
132
139
|
tables.forEach((tableName) => {
|
|
133
|
-
|
|
134
|
-
|
|
140
|
+
if (validOptions.table) {
|
|
141
|
+
dropStatements.push(`DROP TABLE IF EXISTS \`${tableName}\`;`);
|
|
142
|
+
}
|
|
143
|
+
if (validOptions.sequence) {
|
|
144
|
+
dropStatements.push(`DROP SEQUENCE IF EXISTS \`${tableName}\`;`);
|
|
145
|
+
}
|
|
135
146
|
});
|
|
136
147
|
return dropStatements;
|
|
137
148
|
}
|
|
@@ -901,7 +912,7 @@ class ForgeSQLAnalyseOperation {
|
|
|
901
912
|
* @returns {string} The SQL query for cluster statement history
|
|
902
913
|
*/
|
|
903
914
|
buildClusterStatementQuery(tables, from, to) {
|
|
904
|
-
const formatDateTime = (date) =>
|
|
915
|
+
const formatDateTime = (date) => luxon.DateTime.fromJSDate(date).toFormat("yyyy-LL-dd'T'HH:mm:ss.SSS");
|
|
905
916
|
const tableConditions = tables.map((table2) => `TABLE_NAMES LIKE CONCAT(SCHEMA_NAME, '.', '%', '${table2}', '%')`).join(" OR ");
|
|
906
917
|
const timeConditions = [];
|
|
907
918
|
if (from) {
|
|
@@ -1191,10 +1202,10 @@ const forgeDateTimeString = mysqlCore.customType({
|
|
|
1191
1202
|
return "datetime";
|
|
1192
1203
|
},
|
|
1193
1204
|
toDriver(value) {
|
|
1194
|
-
return
|
|
1205
|
+
return luxon.DateTime.fromJSDate(value).toFormat("yyyy-LL-dd'T'HH:mm:ss.SSS");
|
|
1195
1206
|
},
|
|
1196
1207
|
fromDriver(value) {
|
|
1197
|
-
const format = "
|
|
1208
|
+
const format = "yyyy-LL-dd'T'HH:mm:ss.SSS";
|
|
1198
1209
|
return parseDateTime(value, format);
|
|
1199
1210
|
}
|
|
1200
1211
|
});
|
|
@@ -1203,10 +1214,10 @@ const forgeTimestampString = mysqlCore.customType({
|
|
|
1203
1214
|
return "timestamp";
|
|
1204
1215
|
},
|
|
1205
1216
|
toDriver(value) {
|
|
1206
|
-
return
|
|
1217
|
+
return luxon.DateTime.fromJSDate(value).toFormat("yyyy-LL-dd'T'HH:mm:ss.SSS");
|
|
1207
1218
|
},
|
|
1208
1219
|
fromDriver(value) {
|
|
1209
|
-
const format = "
|
|
1220
|
+
const format = "yyyy-LL-dd'T'HH:mm:ss.SSS";
|
|
1210
1221
|
return parseDateTime(value, format);
|
|
1211
1222
|
}
|
|
1212
1223
|
});
|
|
@@ -1215,10 +1226,10 @@ const forgeDateString = mysqlCore.customType({
|
|
|
1215
1226
|
return "date";
|
|
1216
1227
|
},
|
|
1217
1228
|
toDriver(value) {
|
|
1218
|
-
return
|
|
1229
|
+
return luxon.DateTime.fromJSDate(value).toFormat("yyyy-LL-dd");
|
|
1219
1230
|
},
|
|
1220
1231
|
fromDriver(value) {
|
|
1221
|
-
const format = "
|
|
1232
|
+
const format = "yyyy-LL-dd";
|
|
1222
1233
|
return parseDateTime(value, format);
|
|
1223
1234
|
}
|
|
1224
1235
|
});
|
|
@@ -1227,7 +1238,7 @@ const forgeTimeString = mysqlCore.customType({
|
|
|
1227
1238
|
return "time";
|
|
1228
1239
|
},
|
|
1229
1240
|
toDriver(value) {
|
|
1230
|
-
return
|
|
1241
|
+
return luxon.DateTime.fromJSDate(value).toFormat("HH:mm:ss.SSS");
|
|
1231
1242
|
},
|
|
1232
1243
|
fromDriver(value) {
|
|
1233
1244
|
return parseDateTime(value, "HH:mm:ss.SSS");
|
|
@@ -1246,7 +1257,7 @@ const forgeSystemTables = [migrations];
|
|
|
1246
1257
|
async function dropSchemaMigrations() {
|
|
1247
1258
|
try {
|
|
1248
1259
|
const tables = await getTables();
|
|
1249
|
-
const dropStatements = generateDropTableStatements(tables);
|
|
1260
|
+
const dropStatements = generateDropTableStatements(tables, { sequence: true, table: true });
|
|
1250
1261
|
for (const statement of dropStatements) {
|
|
1251
1262
|
console.warn(statement);
|
|
1252
1263
|
await sql$1.sql.executeDDL(statement);
|
|
@@ -1326,6 +1337,24 @@ function formatCreateTableStatement(statement) {
|
|
|
1326
1337
|
function wrapWithForeignKeyChecks(statements) {
|
|
1327
1338
|
return ["SET foreign_key_checks = 0", ...statements, "SET foreign_key_checks = 1"];
|
|
1328
1339
|
}
|
|
1340
|
+
async function dropTableSchemaMigrations() {
|
|
1341
|
+
try {
|
|
1342
|
+
const tables = await getTables();
|
|
1343
|
+
const dropStatements = generateDropTableStatements(tables, { sequence: false, table: true });
|
|
1344
|
+
for (const statement of dropStatements) {
|
|
1345
|
+
console.warn(statement);
|
|
1346
|
+
await sql$1.sql.executeDDL(statement);
|
|
1347
|
+
}
|
|
1348
|
+
return getHttpResponse(
|
|
1349
|
+
200,
|
|
1350
|
+
"⚠️ All data in these tables has been permanently deleted. This operation cannot be undone."
|
|
1351
|
+
);
|
|
1352
|
+
} catch (error) {
|
|
1353
|
+
console.error(error);
|
|
1354
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1355
|
+
return getHttpResponse(500, errorMessage);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1329
1358
|
const getHttpResponse = (statusCode, body) => {
|
|
1330
1359
|
let statusText = "";
|
|
1331
1360
|
if (statusCode === 200) {
|
|
@@ -1346,6 +1375,7 @@ exports.applyFromDriverTransform = applyFromDriverTransform;
|
|
|
1346
1375
|
exports.applySchemaMigrations = applySchemaMigrations;
|
|
1347
1376
|
exports.default = ForgeSQLORM;
|
|
1348
1377
|
exports.dropSchemaMigrations = dropSchemaMigrations;
|
|
1378
|
+
exports.dropTableSchemaMigrations = dropTableSchemaMigrations;
|
|
1349
1379
|
exports.fetchSchemaWebTrigger = fetchSchemaWebTrigger;
|
|
1350
1380
|
exports.forgeDateString = forgeDateString;
|
|
1351
1381
|
exports.forgeDateTimeString = forgeDateTimeString;
|