Skip to content

Commit

Permalink
refactor: improve visual outlook of migration:status command
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 27, 2019
1 parent 0b9e0b0 commit 84b7447
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions commands/Status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { inject } from '@adonisjs/fold'
import { BaseCommand, flags } from '@adonisjs/ace'
import { DatabaseContract } from '@ioc:Adonis/Lucid/Database'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
import { MigrationListNode } from '@ioc:Adonis/Lucid/Migrator'

/**
* The command is meant to migrate the database by execute migrations
Expand All @@ -37,6 +38,23 @@ export default class Status extends BaseCommand {
super(app)
}

/**
* Colorizes the status string
*/
private _colorizeStatus (status: MigrationListNode['status']) {
if (status === 'pending') {
return this.colors.yellow('pending')
}

if (status === 'migrated') {
return this.colors.green('completed')
}

if (status === 'corrupt') {
return this.colors.red('corrupt')
}
}

/**
* Handle command
*/
Expand All @@ -63,15 +81,33 @@ export default class Status extends BaseCommand {
const list = await migrator.getList()
await migrator.close()

const columns = columnify(list.map((node) => {
/**
* List to be printed on the console
*/
const uiList = list.map((node) => {
return {
name: node.name,
status: node.status,
status: this._colorizeStatus(node.status),
batch: node.batch || 'NA',
message: node.status === 'corrupt' ? 'The migration file is missing on filesystem' : '',
}
}))
})

/**
* Columnify options
*/
const columnifyOptions = {
batch: {
minWidth: 8,
},
name: {
minWidth: 60,
},
status: {
minWidth: 14,
},
}

console.log(columns)
console.log(columnify(uiList, columnifyOptions))
}
}

0 comments on commit 84b7447

Please sign in to comment.