UNPKG

forge-sql-orm

Version:

Drizzle ORM integration for Atlassian @forge/sql. Provides a custom driver, schema migration, two levels of caching (local and global via @forge/kvs), optimistic locking, and query analysis.

60 lines 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dropSchemaMigrations = dropSchemaMigrations; const sql_1 = require("@forge/sql"); const sqlUtils_1 = require("../utils/sqlUtils"); const index_1 = require("./index"); const core_1 = require("../core"); /** * ⚠️ DEVELOPMENT ONLY WEB TRIGGER ⚠️ * * This web trigger is designed for development environments only and will permanently delete all data in the specified tables and sequences. * It generates and executes SQL statements to drop tables, their associated constraints, and sequences. * * @warning This trigger should NEVER be used in production environments because: * - It permanently deletes all data in the specified tables and sequences * - The operation cannot be undone * - It may affect application functionality * - It could lead to data loss and system instability * * @note This function is automatically disabled in production environments and will return a 500 error if called. * * @returns {Promise<TriggerResponse<string>>} A response containing: * - On success: 200 status with warning message about permanent deletion of tables and sequences * - On failure: 500 status with error message (including when called in production) * * @example * ```typescript * // Example usage in development only * await dropSchemaMigrations(); * // ⚠️ Warning: This will permanently delete all data in users and orders tables and their sequences * ``` */ async function dropSchemaMigrations() { const productionCheck = (0, sqlUtils_1.checkProductionEnvironment)("dropSchemaMigrations"); if (productionCheck) { return productionCheck; } try { const tables = await (0, core_1.getTables)(); // Generate drop statements const dropStatements = (0, sqlUtils_1.generateDropTableStatements)(tables, { sequence: true, table: true }); // Execute each statement for (const statement of dropStatements) { // eslint-disable-next-line no-console console.debug(`execute DDL: ${statement}`); await sql_1.sql.executeDDL(statement); } return (0, index_1.getHttpResponse)(200, "⚠️ All data in these tables has been permanently deleted. This operation cannot be undone."); } catch (error) { const errorMessage = error?.debug?.sqlMessage ?? error?.debug?.message ?? error.message ?? "Unknown error occurred"; // eslint-disable-next-line no-console console.error(errorMessage); return (0, index_1.getHttpResponse)(500, errorMessage); } } //# sourceMappingURL=dropMigrationWebTrigger.js.map