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.
@@ -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
- dropStatements.push(`DROP TABLE IF EXISTS \`${tableName}\`;`);
132
- dropStatements.push(`DROP SEQUENCE IF EXISTS \`${tableName}\`;`);
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);
@@ -1324,6 +1333,24 @@ function formatCreateTableStatement(statement) {
1324
1333
  function wrapWithForeignKeyChecks(statements) {
1325
1334
  return ["SET foreign_key_checks = 0", ...statements, "SET foreign_key_checks = 1"];
1326
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
+ }
1327
1354
  const getHttpResponse = (statusCode, body) => {
1328
1355
  let statusText = "";
1329
1356
  if (statusCode === 200) {
@@ -1345,6 +1372,7 @@ export {
1345
1372
  applySchemaMigrations,
1346
1373
  ForgeSQLORM as default,
1347
1374
  dropSchemaMigrations,
1375
+ dropTableSchemaMigrations,
1348
1376
  fetchSchemaWebTrigger,
1349
1377
  forgeDateString,
1350
1378
  forgeDateTimeString,