forge-sql-orm 2.0.26 → 2.0.28
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 +39 -6
- package/dist/ForgeSQLORM.js.map +1 -1
- package/dist/ForgeSQLORM.mjs +39 -6
- package/dist/ForgeSQLORM.mjs.map +1 -1
- package/dist/utils/sqlUtils.d.ts +11 -4
- package/dist/utils/sqlUtils.d.ts.map +1 -1
- package/dist/webtriggers/applyMigrationsWebTrigger.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 +9 -9
- package/src/utils/sqlUtils.ts +22 -7
- package/src/webtriggers/applyMigrationsWebTrigger.ts +10 -2
- package/src/webtriggers/dropMigrationWebTrigger.ts +6 -6
- package/src/webtriggers/dropTablesMigrationWebTrigger.ts +50 -0
- package/src/webtriggers/index.ts +1 -0
package/dist/ForgeSQLORM.mjs
CHANGED
|
@@ -125,11 +125,20 @@ function getTableMetadata(table) {
|
|
|
125
125
|
...builders
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
function generateDropTableStatements(tables) {
|
|
128
|
+
function generateDropTableStatements(tables, options) {
|
|
129
129
|
const dropStatements = [];
|
|
130
|
+
const validOptions = options ?? { sequence: true, table: true };
|
|
131
|
+
if (!validOptions.sequence && !validOptions.table) {
|
|
132
|
+
console.warn('No drop operations requested: both "table" and "sequence" options are false');
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
130
135
|
tables.forEach((tableName) => {
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
if (validOptions.table) {
|
|
137
|
+
dropStatements.push(`DROP TABLE IF EXISTS \`${tableName}\`;`);
|
|
138
|
+
}
|
|
139
|
+
if (validOptions.sequence) {
|
|
140
|
+
dropStatements.push(`DROP SEQUENCE IF EXISTS \`${tableName}\`;`);
|
|
141
|
+
}
|
|
133
142
|
});
|
|
134
143
|
return dropStatements;
|
|
135
144
|
}
|
|
@@ -1244,7 +1253,7 @@ const forgeSystemTables = [migrations];
|
|
|
1244
1253
|
async function dropSchemaMigrations() {
|
|
1245
1254
|
try {
|
|
1246
1255
|
const tables = await getTables();
|
|
1247
|
-
const dropStatements = generateDropTableStatements(tables);
|
|
1256
|
+
const dropStatements = generateDropTableStatements(tables, { sequence: true, table: true });
|
|
1248
1257
|
for (const statement of dropStatements) {
|
|
1249
1258
|
console.warn(statement);
|
|
1250
1259
|
await sql$1.executeDDL(statement);
|
|
@@ -1271,7 +1280,7 @@ const applySchemaMigrations = async (migration) => {
|
|
|
1271
1280
|
const successfulMigrations = await migrations2.run();
|
|
1272
1281
|
console.info("Migrations applied:", successfulMigrations);
|
|
1273
1282
|
const migrationList = await migrationRunner.list();
|
|
1274
|
-
const migrationHistory = Array.isArray(migrationList) && migrationList.length > 0 ? migrationList.map((y) => `${y.id}, ${y.name}, ${y.migratedAt.toUTCString()}`).join("\n") : "No migrations found";
|
|
1283
|
+
const migrationHistory = Array.isArray(migrationList) && migrationList.length > 0 ? migrationList.sort((a, b) => a.migratedAt.getTime() - b.migratedAt.getTime()).map((y) => `${y.id}, ${y.name}, ${y.migratedAt.toUTCString()}`).join("\n") : "No migrations found";
|
|
1275
1284
|
console.info("Migrations history:\nid, name, migrated_at\n", migrationHistory);
|
|
1276
1285
|
return {
|
|
1277
1286
|
headers: { "Content-Type": ["application/json"] },
|
|
@@ -1280,7 +1289,12 @@ const applySchemaMigrations = async (migration) => {
|
|
|
1280
1289
|
body: "Migrations successfully executed"
|
|
1281
1290
|
};
|
|
1282
1291
|
} catch (error) {
|
|
1283
|
-
|
|
1292
|
+
try {
|
|
1293
|
+
console.error("Error during migration:", JSON.stringify(error));
|
|
1294
|
+
} catch (e) {
|
|
1295
|
+
console.trace("Error stringify:", e);
|
|
1296
|
+
console.error("Error during migration:", error);
|
|
1297
|
+
}
|
|
1284
1298
|
return {
|
|
1285
1299
|
headers: { "Content-Type": ["application/json"] },
|
|
1286
1300
|
statusCode: 500,
|
|
@@ -1319,6 +1333,24 @@ function formatCreateTableStatement(statement) {
|
|
|
1319
1333
|
function wrapWithForeignKeyChecks(statements) {
|
|
1320
1334
|
return ["SET foreign_key_checks = 0", ...statements, "SET foreign_key_checks = 1"];
|
|
1321
1335
|
}
|
|
1336
|
+
async function dropTableSchemaMigrations() {
|
|
1337
|
+
try {
|
|
1338
|
+
const tables = await getTables();
|
|
1339
|
+
const dropStatements = generateDropTableStatements(tables, { sequence: false, table: true });
|
|
1340
|
+
for (const statement of dropStatements) {
|
|
1341
|
+
console.warn(statement);
|
|
1342
|
+
await sql$1.executeDDL(statement);
|
|
1343
|
+
}
|
|
1344
|
+
return getHttpResponse(
|
|
1345
|
+
200,
|
|
1346
|
+
"⚠️ All data in these tables has been permanently deleted. This operation cannot be undone."
|
|
1347
|
+
);
|
|
1348
|
+
} catch (error) {
|
|
1349
|
+
console.error(error);
|
|
1350
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1351
|
+
return getHttpResponse(500, errorMessage);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1322
1354
|
const getHttpResponse = (statusCode, body) => {
|
|
1323
1355
|
let statusText = "";
|
|
1324
1356
|
if (statusCode === 200) {
|
|
@@ -1340,6 +1372,7 @@ export {
|
|
|
1340
1372
|
applySchemaMigrations,
|
|
1341
1373
|
ForgeSQLORM as default,
|
|
1342
1374
|
dropSchemaMigrations,
|
|
1375
|
+
dropTableSchemaMigrations,
|
|
1343
1376
|
fetchSchemaWebTrigger,
|
|
1344
1377
|
forgeDateString,
|
|
1345
1378
|
forgeDateTimeString,
|