Updated migration.js

Makes the script more informative by printing columns that are getting skipped because they already exist.
This commit is contained in:
Bobby Wibowo 2018-09-07 22:34:00 +07:00
parent 715132a0d6
commit 635027bde4
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -20,7 +20,9 @@ migration.start = async () => {
await Promise.all(tables.map(table => { await Promise.all(tables.map(table => {
const columns = Object.keys(map[table]) const columns = Object.keys(map[table])
return Promise.all(columns.map(async column => { return Promise.all(columns.map(async column => {
if (await db.schema.hasColumn(table, column)) { return } if (await db.schema.hasColumn(table, column)) {
return console.log(`Column "${column}" already exists in table "${table}".`)
}
const columnType = map[table][column] const columnType = map[table][column]
return db.schema.table(table, t => { t[columnType](column) }) return db.schema.table(table, t => { t[columnType](column) })
.then(() => console.log(`Added column "${column}" to table "${table}".`)) .then(() => console.log(`Added column "${column}" to table "${table}".`))