Skip to content

Instantly share code, notes, and snippets.

@Necmttn
Created August 13, 2021 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Necmttn/ae501074a4192272b96db1b68b26162c to your computer and use it in GitHub Desktop.
Save Necmttn/ae501074a4192272b96db1b68b26162c to your computer and use it in GitHub Desktop.
compare_sql_tables.js
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