Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(scripts): stop the explain script tripping over git grep colours
Browse files Browse the repository at this point in the history
The explain script was using `cut` to split paths from git grep before
the colon character. This fails on system where control characters such
as colours are emitted before the colon.

A more robust approach is to use a regex to pull out the specific text
we're looking for. The script is already hard-coded with other paths
like `lib/db/mysql.js`, so matching against the expected migration path
doesn't seem like too much of a stretch to me.
  • Loading branch information
philbooth committed Oct 30, 2018
1 parent b0dd33d commit ff0ac5c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions scripts/explain-warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,15 @@ function getProcedureNames () {
}

function getPath (procedure) {
return cp.execSync(
`git grep "${procedure}" | grep 'CREATE PROCEDURE' | cut -d ':' -f 1 | sed '/^$/d'`,
const path = cp.execSync(
`git grep "${procedure}" | grep 'CREATE PROCEDURE' | sed '/^$/d'`,
RETURN_STRING
)
.trim()
.match(/(lib\/db\/schema\/patch-[0-9]+-[0-9]+\.sql)/)

if (path) {
return path[1]
}
}

function extractSelects (path, procedure) {
Expand Down

0 comments on commit ff0ac5c

Please sign in to comment.