forge-sql-orm 2.0.27 → 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.
@@ -127,11 +127,20 @@ function getTableMetadata(table2) {
127
127
  ...builders
128
128
  };
129
129
  }
130
- function generateDropTableStatements(tables) {
130
+ function generateDropTableStatements(tables, options) {
131
131
  const dropStatements = [];
132
+ const validOptions = options ?? { sequence: true, table: true };
133
+ if (!validOptions.sequence && !validOptions.table) {
134
+ console.warn('No drop operations requested: both "table" and "sequence" options are false');
135
+ return [];
136
+ }
132
137
  tables.forEach((tableName) => {
133
- dropStatements.push(`DROP TABLE IF EXISTS \`${tableName}\`;`);
134
- dropStatements.push(`DROP SEQUENCE IF EXISTS \`${tableName}\`;`);
138
+ if (validOptions.table) {
139
+ dropStatements.push(`DROP TABLE IF EXISTS \`${tableName}\`;`);
140
+ }
141
+ if (validOptions.sequence) {
142
+ dropStatements.push(`DROP SEQUENCE IF EXISTS \`${tableName}\`;`);
143
+ }
135
144
  });
136
145
  return dropStatements;
137
146
  }
@@ -1246,7 +1255,7 @@ const forgeSystemTables = [migrations];
1246
1255
  async function dropSchemaMigrations() {
1247
1256
  try {
1248
1257
  const tables = await getTables();
1249
- const dropStatements = generateDropTableStatements(tables);
1258
+ const dropStatements = generateDropTableStatements(tables, { sequence: true, table: true });
1250
1259
  for (const statement of dropStatements) {
1251
1260
  console.warn(statement);
1252
1261
  await sql$1.sql.executeDDL(statement);
@@ -1326,6 +1335,24 @@ function formatCreateTableStatement(statement) {
1326
1335
  function wrapWithForeignKeyChecks(statements) {
1327
1336
  return ["SET foreign_key_checks = 0", ...statements, "SET foreign_key_checks = 1"];
1328
1337
  }
1338
+ async function dropTableSchemaMigrations() {
1339
+ try {
1340
+ const tables = await getTables();
1341
+ const dropStatements = generateDropTableStatements(tables, { sequence: false, table: true });
1342
+ for (const statement of dropStatements) {
1343
+ console.warn(statement);
1344
+ await sql$1.sql.executeDDL(statement);
1345
+ }
1346
+ return getHttpResponse(
1347
+ 200,
1348
+ "⚠️ All data in these tables has been permanently deleted. This operation cannot be undone."
1349
+ );
1350
+ } catch (error) {
1351
+ console.error(error);
1352
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
1353
+ return getHttpResponse(500, errorMessage);
1354
+ }
1355
+ }
1329
1356
  const getHttpResponse = (statusCode, body) => {
1330
1357
  let statusText = "";
1331
1358
  if (statusCode === 200) {
@@ -1346,6 +1373,7 @@ exports.applyFromDriverTransform = applyFromDriverTransform;
1346
1373
  exports.applySchemaMigrations = applySchemaMigrations;
1347
1374
  exports.default = ForgeSQLORM;
1348
1375
  exports.dropSchemaMigrations = dropSchemaMigrations;
1376
+ exports.dropTableSchemaMigrations = dropTableSchemaMigrations;
1349
1377
  exports.fetchSchemaWebTrigger = fetchSchemaWebTrigger;
1350
1378
  exports.forgeDateString = forgeDateString;
1351
1379
  exports.forgeDateTimeString = forgeDateTimeString;