npm package diff
Package: @forge/sql
Versions: 2.3.0-next.0 - 2.3.0-next.1
Modified: package/out/errors.js
Index: package/out/errors.js
===================================================================
--- package/out/errors.js
+++ package/out/errors.js
@@ -28,21 +28,31 @@
exports.ForgeSQLAPIError = ForgeSQLAPIError;
class MigrationExecutionError extends ForgeSQLError {
migrationName;
migrationsYetToRun;
- constructor(migrationName, migrationsYetToRun) {
+ cause;
+ constructor(migrationName, migrationsYetToRun, cause) {
super(`Failed to execute migration with name ${migrationName}`);
this.migrationName = migrationName;
this.migrationsYetToRun = migrationsYetToRun;
+ this.cause = cause;
+ this.migrationName = migrationName;
+ this.migrationsYetToRun = migrationsYetToRun;
+ this.cause = cause;
}
}
exports.MigrationExecutionError = MigrationExecutionError;
class MigrationCheckPointError extends ForgeSQLError {
migrationName;
migrationsYetToRun;
- constructor(migrationName, migrationsYetToRun) {
+ cause;
+ constructor(migrationName, migrationsYetToRun, cause) {
super(`Failed to checkpoint after running migration with name ${migrationName}`);
this.migrationName = migrationName;
this.migrationsYetToRun = migrationsYetToRun;
+ this.cause = cause;
+ this.migrationName = migrationName;
+ this.migrationsYetToRun = migrationsYetToRun;
+ this.cause = cause;
}
}
exports.MigrationCheckPointError = MigrationCheckPointError;
Modified: package/out/migration.js
Index: package/out/migration.js
===================================================================
--- package/out/migration.js
+++ package/out/migration.js
@@ -46,15 +46,15 @@
try {
await this.sqlClient.executeDDL(migration.statement);
}
catch (error) {
- throw new errors_1.MigrationExecutionError(migration.name, migrationsToRun.map((m) => m.name));
+ throw new errors_1.MigrationExecutionError(migration.name, migrationsToRun.map((m) => m.name), error);
}
try {
await this.sqlClient.prepare(INSERT_SCHEMA_VERSION_QUERY).bindParams(migration.name).execute();
}
catch (error) {
- throw new errors_1.MigrationCheckPointError(migration.name, migrationsToRun.map((m) => m.name));
+ throw new errors_1.MigrationCheckPointError(migration.name, migrationsToRun.map((m) => m.name), error);
}
migrationsSuccessfullyRun.push(migration.name);
}
return migrationsSuccessfullyRun;
Modified: package/out/__test__/migration.test.js
Index: package/out/__test__/migration.test.js
===================================================================
--- package/out/__test__/migration.test.js
+++ package/out/__test__/migration.test.js
@@ -4,8 +4,9 @@
const sql_1 = require("../sql");
const errorCodes_1 = require("../errorCodes");
const jest_when_1 = require("jest-when");
const sql_statement_1 = require("../sql-statement");
+const errors_1 = require("../errors");
jest.mock('../sql');
describe('Migration', () => {
let migrationRunner;
let mockSqlClient;
@@ -91,8 +92,88 @@
expect(result).toEqual(['v_002_create_table_bar']);
expect(mockSqlClient.prepare).toHaveBeenCalledTimes(1);
expect(mockSqlClient.executeDDL).toHaveBeenCalledTimes(3);
});
+ it('should throw forge sql api error during check point', async () => {
+ migrationRunner.enqueue('v_001_create_table_foo', CREATE_TABLE_FOO_QUERY);
+ migrationRunner.enqueue('v_002_create_table_bar', CREATE_TABLE_BAR_QUERY);
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith((0, jest_when_1.when)((arg) => arg.startsWith('CREATE TABLE IF NOT EXISTS __migrations')))
+ .mockResolvedValue({ rows: [] });
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith('SELECT id, name, migratedAt FROM __migrations;')
+ .mockResolvedValue({
+ rows: [{ name: 'v_001_create_table_foo', statement: CREATE_TABLE_FOO_QUERY, migratedAt: new Date() }]
+ });
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith(CREATE_TABLE_BAR_QUERY)
+ .mockRejectedValue(new errors_1.ForgeSQLAPIError({ status: 400, statusText: 'Invalid query' }, { code: 'SQL_EXECUTION_ERROR', message: '', suggestion: 'Check your SQL query' }));
+ await expect(migrationRunner.run()).rejects.toMatchObject({
+ migrationName: 'v_002_create_table_bar',
+ migrationsYetToRun: ['v_002_create_table_bar'],
+ cause: new errors_1.ForgeSQLAPIError({ status: 400, statusText: 'Invalid query' }, { code: 'SQL_EXECUTION_ERROR', message: '', suggestion: 'Check your SQL query' })
+ });
+ });
+ it('should throw an error when a migration fails', async () => {
+ migrationRunner.enqueue('v_001_create_table_foo', CREATE_TABLE_FOO_QUERY);
+ migrationRunner.enqueue('v_002_create_table_bar', CREATE_TABLE_BAR_QUERY);
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith((0, jest_when_1.when)((arg) => arg.startsWith('CREATE TABLE IF NOT EXISTS __migrations')))
+ .mockResolvedValue({ rows: [] });
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith('SELECT id, name, migratedAt FROM __migrations;')
+ .mockResolvedValue({
+ rows: [{ name: 'v_001_create_table_foo', statement: CREATE_TABLE_FOO_QUERY, migratedAt: new Date() }]
+ });
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith(CREATE_TABLE_BAR_QUERY)
+ .mockRejectedValue(new errors_1.ForgeSQLAPIError({ status: 400, statusText: 'Invalid query' }, { code: 'SQL_EXECUTION_ERROR', message: '', suggestion: 'Check your SQL query' }));
+ await expect(migrationRunner.run()).rejects.toMatchObject({
+ migrationName: 'v_002_create_table_bar',
+ migrationsYetToRun: ['v_002_create_table_bar'],
+ cause: new errors_1.ForgeSQLAPIError({ status: 400, statusText: 'Invalid query' }, { code: 'SQL_EXECUTION_ERROR', message: '', suggestion: 'Check your SQL query' })
+ });
+ });
+ it('should throw generic error when a migration fails', async () => {
+ migrationRunner.enqueue('v_001_create_table_foo', CREATE_TABLE_FOO_QUERY);
+ migrationRunner.enqueue('v_002_create_table_bar', CREATE_TABLE_BAR_QUERY);
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith((0, jest_when_1.when)((arg) => arg.startsWith('CREATE TABLE IF NOT EXISTS __migrations')))
+ .mockResolvedValue({ rows: [] });
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith('SELECT id, name, migratedAt FROM __migrations;')
+ .mockResolvedValue({
+ rows: [{ name: 'v_001_create_table_foo', statement: CREATE_TABLE_FOO_QUERY, migratedAt: new Date() }]
+ });
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith(CREATE_TABLE_BAR_QUERY)
+ .mockRejectedValue(new Error('Failed to execute migration'));
+ await expect(migrationRunner.run()).rejects.toMatchObject({
+ migrationName: 'v_002_create_table_bar',
+ migrationsYetToRun: ['v_002_create_table_bar'],
+ cause: new Error('Failed to execute migration')
+ });
+ });
+ it('should throw generic error when check point fails', async () => {
+ migrationRunner.enqueue('v_001_create_table_foo', CREATE_TABLE_FOO_QUERY);
+ migrationRunner.enqueue('v_002_create_table_bar', CREATE_TABLE_BAR_QUERY);
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith((0, jest_when_1.when)((arg) => arg.startsWith('CREATE TABLE IF NOT EXISTS __migrations')))
+ .mockResolvedValue({ rows: [] });
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith('SELECT id, name, migratedAt FROM __migrations;')
+ .mockResolvedValue({
+ rows: [{ name: 'v_001_create_table_foo', statement: CREATE_TABLE_FOO_QUERY, migratedAt: new Date() }]
+ });
+ (0, jest_when_1.when)(mockSqlClient.executeDDL)
+ .calledWith(CREATE_TABLE_BAR_QUERY)
+ .mockRejectedValue(new Error('Failed to execute migration'));
+ await expect(migrationRunner.run()).rejects.toMatchObject({
+ migrationName: 'v_002_create_table_bar',
+ migrationsYetToRun: ['v_002_create_table_bar'],
+ cause: new Error('Failed to execute migration')
+ });
+ });
});
describe('when no migrations have been run in the past', () => {
it('should execute migrations that have not been previously run', async () => {
const CREATE_TABLE_FOO_QUERY = 'CREATE TABLE IF NOT EXISTS foo (id INT)';
Modified: package/package.json
Index: package/package.json
===================================================================
--- package/package.json
+++ package/package.json
@@ -1,7 +1,7 @@
{
"name": "@forge/sql",
- "version": "2.3.0-next.0",
+ "version": "2.3.0-next.1",
"description": "Forge SQL sdk",
"author": "Atlassian",
"license": "UNLICENSED",
"main": "out/index.js",
Modified: package/out/errors.d.ts.map
Index: package/out/errors.d.ts.map
===================================================================
--- package/out/errors.d.ts.map
+++ package/out/errors.d.ts.map
@@ -1,1 +1,1 @@
-{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,UAAU;IAKzB,IAAI,EAAE,MAAM,CAAC;IAGb,OAAO,EAAE,MAAM,CAAC;IAGhB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAGnC;AAGD,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AASD,MAAM,WAAW,uBAAuB;IAEtC,MAAM,EAAE,MAAM,CAAC;IAGf,UAAU,EAAE,MAAM,CAAC;IAGnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAMD,qBAAa,gBAAiB,SAAQ,aAAa;IAMjD,eAAe,EAAE,uBAAuB,CAAC;IAMzC,IAAI,EAAE,MAAM,CAAC;IAGb,OAAO,EAAE,MAAM,CAAC;IAGhB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEtB,eAAe,EAAE,uBAAuB,EAAE,UAAU,EAAE,UAAU;CAgB7E;AAED,qBAAa,uBAAwB,SAAQ,aAAa;IAEtD,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,EAAE;gBAD5B,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,MAAM,EAAE;CAIxC;AAED,qBAAa,wBAAyB,SAAQ,aAAa;IAEvD,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,EAAE;gBAD5B,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,MAAM,EAAE;CAIxC"}
\ No newline at end of file
+{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"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out/migration.d.ts.map
===================================================================
--- package/out/migration.d.ts.map
+++ package/out/migration.d.ts.map
@@ -1,1 +1,1 @@
-{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,aAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,aAAK,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC;AAcF,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,SAAS,EAAE,SAAS;IAK1B,UAAU;IAIT,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,eAAe;IAQzD,WAAW,IAAI,eAAe,EAAE;IAIjC,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAYnC,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAiC/B;AAED,eAAO,MAAM,eAAe,iBAA2B,CAAC"}
\ No newline at end of file
+{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,aAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,aAAK,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC;AAcF,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,SAAS,EAAE,SAAS;IAK1B,UAAU;IAIT,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,eAAe;IAQzD,WAAW,IAAI,eAAe,EAAE;IAIjC,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAYnC,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAmC/B;AAED,eAAO,MAAM,eAAe,iBAA2B,CAAC"}
\ No newline at end of file
Modified: package/out/errors.d.ts
Index: package/out/errors.d.ts
===================================================================
--- package/out/errors.d.ts
+++ package/out/errors.d.ts
@@ -22,12 +22,14 @@
}
export declare class MigrationExecutionError extends ForgeSQLError {
readonly migrationName: string;
readonly migrationsYetToRun: string[];
- constructor(migrationName: string, migrationsYetToRun: string[]);
+ readonly cause?: Error | undefined;
+ constructor(migrationName: string, migrationsYetToRun: string[], cause?: Error | undefined);
}
export declare class MigrationCheckPointError extends ForgeSQLError {
readonly migrationName: string;
readonly migrationsYetToRun: string[];
- constructor(migrationName: string, migrationsYetToRun: string[]);
+ readonly cause?: Error | undefined;
+ constructor(migrationName: string, migrationsYetToRun: string[], cause?: Error | undefined);
}
//# sourceMappingURL=errors.d.ts.map
\ No newline at end of file