Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an exception to rollback transaction if SQL migration fails #117

Merged
merged 6 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
mesaugat marked this conversation as resolved.
Show resolved Hide resolved
"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;
mesaugat marked this conversation as resolved.
Show resolved Hide resolved
}
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still gimmicky. Does the job for now though.

throw err;
}

result.push(err.result);
}
}

Expand Down