Created
August 13, 2021 19:45
-
-
Save Necmttn/ae501074a4192272b96db1b68b26162c to your computer and use it in GitHub Desktop.
compare_sql_tables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createDisctionaryOfColumns = (tableDefination) => { | |
return tableDefination.split(',').reduce((prev,column) => { | |
const part = column.trim().split(/\s+/); | |
console.log(part) | |
const cName = part[0]; | |
const type = part[1]; | |
prev[cName]= type; | |
return prev; | |
}, {}) | |
} | |
const a = createDisctionaryOfColumns(xtech_table) | |
const b = createDisctionaryOfColumns(meltano_table) | |
const diff = (a, b) => { | |
const errors = { | |
typeMismatch: [], | |
columnMissing: [] | |
}; | |
Object.entries(a).forEach(([k,v]) => { | |
if (!b[k]) { | |
errors.columnMissing.push(`missing column: ${k} value: ${v}`) | |
console.error(`missing column: ${k} value: ${v}`) | |
return; | |
} | |
if(b[k] !== a[k]) { | |
errors.typeMismatch.push(`${k} is different, xtech: ${a[k]} meltano: ${b[k]}`); | |
console.error(`${k} is different, xtech: ${a[k]} meltano: ${b[k]}` ) | |
} | |
}) | |
return errors; | |
} | |
const result = diff(a, b) | |
console.log(JSON.stringify({ | |
result, | |
type: result.typeMismatch.length, | |
column: result.columnMissing.length | |
}, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment