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.
@@ -48,11 +48,18 @@ export declare function getPrimaryKeys<T extends AnyMySqlTable>(table: T): [stri
48
48
  */
49
49
  export declare function getTableMetadata(table: AnyMySqlTable): MetadataInfo;
50
50
  /**
51
- * Generates SQL statements to drop tables
52
- * @param tables - Array of table names
53
- * @returns Array of SQL statements for dropping tables
51
+ * Generates SQL statements for dropping tables and/or their sequences.
52
+ *
53
+ * @param tables - List of table names to generate DROP statements for.
54
+ * @param options - Configuration object:
55
+ * - sequence: whether to drop associated sequences (default: true)
56
+ * - table: whether to drop tables themselves (default: true)
57
+ * @returns Array of SQL statements for dropping the specified objects
54
58
  */
55
- export declare function generateDropTableStatements(tables: string[]): string[];
59
+ export declare function generateDropTableStatements(tables: string[], options?: {
60
+ sequence: boolean;
61
+ table: boolean;
62
+ }): string[];
56
63
  type AliasColumnMap = Record<string, AnyColumn>;
57
64
  export declare function mapSelectAllFieldsToAlias(selections: any, name: string, uniqName: string, fields: any, aliasMap: AliasColumnMap): any;
58
65
  export declare function mapSelectFieldsWithAlias<TSelection extends SelectedFields>(fields: TSelection): {
@@ -1 +1 @@
1
- {"version":3,"file":"sqlUtils.d.ts","sourceRoot":"","sources":["../../src/utils/sqlUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA0C,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,aAAa,EAAqB,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACn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iB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED,wBAAgB,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -2,24 +2,24 @@ import { TriggerResponse } from "./index";
2
2
  /**
3
3
  * ⚠️ DEVELOPMENT ONLY WEB TRIGGER ⚠️
4
4
  *
5
- * This web trigger is designed for development environments only and will permanently delete all data in the specified tables.
6
- * It generates and executes SQL statements to drop tables and their associated constraints.
5
+ * This web trigger is designed for development environments only and will permanently delete all data in the specified tables and sequences.
6
+ * It generates and executes SQL statements to drop tables, their associated constraints, and sequences.
7
7
  *
8
8
  * @warning This trigger should NEVER be used in production environments because:
9
- * - It permanently deletes all data in the specified tables
9
+ * - It permanently deletes all data in the specified tables and sequences
10
10
  * - The operation cannot be undone
11
11
  * - It may affect application functionality
12
12
  * - It could lead to data loss and system instability
13
13
  *
14
14
  * @returns {Promise<TriggerResponse<string>>} A response containing:
15
- * - On success: 200 status with warning message about permanent deletion
15
+ * - On success: 200 status with warning message about permanent deletion of tables and sequences
16
16
  * - On failure: 500 status with error message
17
17
  *
18
18
  * @example
19
19
  * ```typescript
20
20
  * // Example usage in development only
21
21
  * await dropSchemaMigrations();
22
- * // ⚠️ Warning: This will permanently delete all data in users and orders tables
22
+ * // ⚠️ Warning: This will permanently delete all data in users and orders tables and their sequences
23
23
  * ```
24
24
  */
25
25
  export declare function dropSchemaMigrations(): Promise<TriggerResponse<string>>;
@@ -0,0 +1,26 @@
1
+ import { TriggerResponse } from "./index";
2
+ /**
3
+ * ⚠️ DEVELOPMENT ONLY WEB TRIGGER ⚠️
4
+ *
5
+ * This web trigger is designed for development environments only and will permanently delete all data in the specified tables.
6
+ * It generates and executes SQL statements to drop tables and their associated constraints.
7
+ *
8
+ * @warning This trigger should NEVER be used in production environments because:
9
+ * - It permanently deletes all data in the specified tables
10
+ * - The operation cannot be undone
11
+ * - It may affect application functionality
12
+ * - It could lead to data loss and system instability
13
+ *
14
+ * @returns {Promise<TriggerResponse<string>>} A response containing:
15
+ * - On success: 200 status with warning message about permanent deletion
16
+ * - On failure: 500 status with error message
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Example usage in development only
21
+ * await dropTableSchemaMigrations();
22
+ * // ⚠️ Warning: This will permanently delete all data in users and orders tables
23
+ * ```
24
+ */
25
+ export declare function dropTableSchemaMigrations(): Promise<TriggerResponse<string>>;
26
+ //# sourceMappingURL=dropTablesMigrationWebTrigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropTablesMigrationWebTrigger.d.ts","sourceRoot":"","sources":["../../src/webtriggers/dropTablesMigrationWebTrigger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,eAAe,EAAE,MAAM,SAAS,CAAC;AAG3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAqBlF"}
@@ -1,6 +1,7 @@
1
1
  export * from "./dropMigrationWebTrigger";
2
2
  export * from "./applyMigrationsWebTrigger";
3
3
  export * from "./fetchSchemaWebTrigger";
4
+ export * from "./dropTablesMigrationWebTrigger";
4
5
  export interface TriggerResponse<BODY> {
5
6
  body?: BODY;
6
7
  headers?: Record<string, string[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webtriggers/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AAExC,MAAM,WAAW,eAAe,CAAC,IAAI;IACnC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,eAAe,GAAI,IAAI,EAAE,YAAY,MAAM,EAAE,MAAM,IAAI,KAAG,eAAe,CAAC,IAAI,CAc1F,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webtriggers/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAEhD,MAAM,WAAW,eAAe,CAAC,IAAI;IACnC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,eAAe,GAAI,IAAI,EAAE,YAAY,MAAM,EAAE,MAAM,IAAI,KAAG,eAAe,CAAC,IAAI,CAc1F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-sql-orm",
3
- "version": "2.0.27",
3
+ "version": "2.0.28",
4
4
  "description": "Drizzle ORM integration for Forge-SQL in Atlassian Forge applications.",
5
5
  "main": "dist/ForgeSQLORM.js",
6
6
  "module": "dist/ForgeSQLORM.mjs",
@@ -32,12 +32,12 @@
32
32
  "database"
33
33
  ],
34
34
  "devDependencies": {
35
- "@eslint/js": "^9.33.0",
36
- "@typescript-eslint/eslint-plugin": "^8.39.1",
37
- "@typescript-eslint/parser": "^8.39.1",
35
+ "@eslint/js": "^9.34.0",
36
+ "@typescript-eslint/eslint-plugin": "^8.40.0",
37
+ "@typescript-eslint/parser": "^8.40.0",
38
38
  "@vitest/coverage-v8": "^3.2.4",
39
39
  "@vitest/ui": "^3.2.4",
40
- "eslint": "^9.33.0",
40
+ "eslint": "^9.34.0",
41
41
  "eslint-config-prettier": "^10.1.8",
42
42
  "eslint-plugin-import": "^2.32.0",
43
43
  "eslint-plugin-vitest": "^0.5.4",
@@ -45,7 +45,7 @@
45
45
  "ts-node": "^10.9.2",
46
46
  "typescript": "^5.9.2",
47
47
  "uuid": "^11.1.0",
48
- "vite": "^7.1.2",
48
+ "vite": "^7.1.3",
49
49
  "vitest": "^3.2.4"
50
50
  },
51
51
  "license": "MIT",
@@ -71,7 +71,7 @@
71
71
  "README.md"
72
72
  ],
73
73
  "peerDependencies": {
74
- "@forge/sql": "^3.0.3",
74
+ "@forge/sql": "^3.0.4",
75
75
  "drizzle-orm": "^0.44.4",
76
76
  "moment": "^2.30.1"
77
77
  }
@@ -239,16 +239,31 @@ export function getTableMetadata(table: AnyMySqlTable): MetadataInfo {
239
239
  }
240
240
 
241
241
  /**
242
- * Generates SQL statements to drop tables
243
- * @param tables - Array of table names
244
- * @returns Array of SQL statements for dropping tables
242
+ * Generates SQL statements for dropping tables and/or their sequences.
243
+ *
244
+ * @param tables - List of table names to generate DROP statements for.
245
+ * @param options - Configuration object:
246
+ * - sequence: whether to drop associated sequences (default: true)
247
+ * - table: whether to drop tables themselves (default: true)
248
+ * @returns Array of SQL statements for dropping the specified objects
245
249
  */
246
- export function generateDropTableStatements(tables: string[]): string[] {
250
+ export function generateDropTableStatements(
251
+ tables: string[],
252
+ options?: { sequence: boolean; table: boolean },
253
+ ): string[] {
247
254
  const dropStatements: string[] = [];
248
-
255
+ const validOptions = options ?? { sequence: true, table: true };
256
+ if (!validOptions.sequence && !validOptions.table) {
257
+ console.warn('No drop operations requested: both "table" and "sequence" options are false');
258
+ return [];
259
+ }
249
260
  tables.forEach((tableName) => {
250
- dropStatements.push(`DROP TABLE IF EXISTS \`${tableName}\`;`);
251
- dropStatements.push(`DROP SEQUENCE IF EXISTS \`${tableName}\`;`);
261
+ if (validOptions.table) {
262
+ dropStatements.push(`DROP TABLE IF EXISTS \`${tableName}\`;`);
263
+ }
264
+ if (validOptions.sequence) {
265
+ dropStatements.push(`DROP SEQUENCE IF EXISTS \`${tableName}\`;`);
266
+ }
252
267
  });
253
268
 
254
269
  return dropStatements;
@@ -6,31 +6,31 @@ import { getTables } from "../core/SystemTables";
6
6
  /**
7
7
  * ⚠️ DEVELOPMENT ONLY WEB TRIGGER ⚠️
8
8
  *
9
- * This web trigger is designed for development environments only and will permanently delete all data in the specified tables.
10
- * It generates and executes SQL statements to drop tables and their associated constraints.
9
+ * This web trigger is designed for development environments only and will permanently delete all data in the specified tables and sequences.
10
+ * It generates and executes SQL statements to drop tables, their associated constraints, and sequences.
11
11
  *
12
12
  * @warning This trigger should NEVER be used in production environments because:
13
- * - It permanently deletes all data in the specified tables
13
+ * - It permanently deletes all data in the specified tables and sequences
14
14
  * - The operation cannot be undone
15
15
  * - It may affect application functionality
16
16
  * - It could lead to data loss and system instability
17
17
  *
18
18
  * @returns {Promise<TriggerResponse<string>>} A response containing:
19
- * - On success: 200 status with warning message about permanent deletion
19
+ * - On success: 200 status with warning message about permanent deletion of tables and sequences
20
20
  * - On failure: 500 status with error message
21
21
  *
22
22
  * @example
23
23
  * ```typescript
24
24
  * // Example usage in development only
25
25
  * await dropSchemaMigrations();
26
- * // ⚠️ Warning: This will permanently delete all data in users and orders tables
26
+ * // ⚠️ Warning: This will permanently delete all data in users and orders tables and their sequences
27
27
  * ```
28
28
  */
29
29
  export async function dropSchemaMigrations(): Promise<TriggerResponse<string>> {
30
30
  try {
31
31
  const tables = await getTables();
32
32
  // Generate drop statements
33
- const dropStatements = generateStatements(tables);
33
+ const dropStatements = generateStatements(tables, { sequence: true, table: true });
34
34
 
35
35
  // Execute each statement
36
36
  for (const statement of dropStatements) {
@@ -0,0 +1,50 @@
1
+ import { sql } from "@forge/sql";
2
+ import { generateDropTableStatements as generateStatements } from "../utils/sqlUtils";
3
+ import { getHttpResponse, TriggerResponse } from "./index";
4
+ import { getTables } from "../core/SystemTables";
5
+
6
+ /**
7
+ * ⚠️ DEVELOPMENT ONLY WEB TRIGGER ⚠️
8
+ *
9
+ * This web trigger is designed for development environments only and will permanently delete all data in the specified tables.
10
+ * It generates and executes SQL statements to drop tables and their associated constraints.
11
+ *
12
+ * @warning This trigger should NEVER be used in production environments because:
13
+ * - It permanently deletes all data in the specified tables
14
+ * - The operation cannot be undone
15
+ * - It may affect application functionality
16
+ * - It could lead to data loss and system instability
17
+ *
18
+ * @returns {Promise<TriggerResponse<string>>} A response containing:
19
+ * - On success: 200 status with warning message about permanent deletion
20
+ * - On failure: 500 status with error message
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Example usage in development only
25
+ * await dropTableSchemaMigrations();
26
+ * // ⚠️ Warning: This will permanently delete all data in users and orders tables
27
+ * ```
28
+ */
29
+ export async function dropTableSchemaMigrations(): Promise<TriggerResponse<string>> {
30
+ try {
31
+ const tables = await getTables();
32
+ // Generate drop statements
33
+ const dropStatements = generateStatements(tables, { sequence: false, table: true });
34
+
35
+ // Execute each statement
36
+ for (const statement of dropStatements) {
37
+ console.warn(statement);
38
+ await sql.executeDDL(statement);
39
+ }
40
+
41
+ return getHttpResponse<string>(
42
+ 200,
43
+ "⚠️ All data in these tables has been permanently deleted. This operation cannot be undone.",
44
+ );
45
+ } catch (error: unknown) {
46
+ console.error(error);
47
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
48
+ return getHttpResponse<string>(500, errorMessage);
49
+ }
50
+ }
@@ -1,6 +1,7 @@
1
1
  export * from "./dropMigrationWebTrigger";
2
2
  export * from "./applyMigrationsWebTrigger";
3
3
  export * from "./fetchSchemaWebTrigger";
4
+ export * from "./dropTablesMigrationWebTrigger";
4
5
 
5
6
  export interface TriggerResponse<BODY> {
6
7
  body?: BODY;