Skip to content

Commit

Permalink
Merge pull request #117 from leapfrogtechnology/fix-transaction-issue
Browse files Browse the repository at this point in the history
Throw an exception to rollback transaction if SQL migration fails
  • Loading branch information
mesaugat authored Mar 25, 2021
2 parents 1d3a739 + 6ff475e commit fac47a2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"id": "db1",
"client": "mssql",
"connection": {
"host": "localhost",
"host": "db",
"port": 1433,
"user": "sa",
"database": "tempdb",
"password": "Password@123"
"password": "Secret@123"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@leapfrogtechnology/sync-db",
"description": "Command line utility to synchronize and version control relational database objects across databases",
"version": "1.0.0-beta.10",
"version": "1.0.0-beta.11",
"license": "MIT",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -64,8 +64,8 @@
"globby": "^10.0.2",
"knex": "^0.20.11",
"ramda": "^0.26.1",
"tslib": "^1",
"ts-node": "^8",
"tslib": "^1",
"yamljs": "^0.3.0"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions src/migration/KnexMigrationSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class KnexMigrationSource {
* @returns {string}
*/
getMigrationName(migration: string): string {
this.log('getMigrationName - resolve: ', migration);

return migration;
}

Expand Down
9 changes: 8 additions & 1 deletion src/service/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export async function executeOperation<T extends OperationContext>(

result.success = true;
} catch (e) {
logDb(`Error caught for connection ${connectionId}:`, e);
logDb(`Error caught for connection ${connectionId}:`);

result.error = e;
}

Expand All @@ -74,5 +75,11 @@ export async function executeOperation<T extends OperationContext>(
await context.params.onFailed(result);
}

if (result.error) {
logDb('Result:\n%O', result);

throw { result };
}

return result;
}
6 changes: 5 additions & 1 deletion src/util/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export async function runSequentially<T>(promisers: Promiser<T>[]): Promise<T[]>

result.push(value);
} catch (err) {
throw err;
if (!err.result) {
throw err;
}

result.push(err.result);
}
}

Expand Down

0 comments on commit fac47a2

Please sign in to comment.