Skip to content

Commit

Permalink
Merge pull request #435 from thematters/issue-mat-master
Browse files Browse the repository at this point in the history
Add migration script for issuing MAT. (master)
  • Loading branch information
devformatters authored Aug 20, 2019
2 parents baae092 + 3166f4b commit fb116ca
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions db/migrations/20190819125510_issue_mat_for_team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const compact = require('lodash/compact')

const uuidv4 = require('uuid/v4')

const table = 'transaction'

const purpose = 'system-subsidy'

exports.up = async knex => {
const items = [
{
userName: 'lalaland',
role: 'admin',
amount: 2000
},
{
userName: 'yingshinlee',
role: 'admin',
amount: 2000
},
{
userName: 'satsuki',
role: 'admin',
amount: 2000
},
{
userName: 'robertu',
role: 'user',
amount: 2000
},
{
userName: 'guo',
role: 'admin',
amount: 2000
},
{
userName: 'baize417',
role: 'admin',
amount: 1000
},
{
userName: 'andyischaos',
role: 'admin',
amount: 500
}
]

const users = compact(
await Promise.all(
items.map(async ({ userName, role, amount }) => {
const user = await knex('user')
.select('id')
.where({ user_name: userName, role })
.first()
if (user) {
return { id: user.id, amount }
}
})
)
)

const result = await Promise.all(
users.map(({ id, amount }) =>
knex(table)
.insert({
uuid: uuidv4(),
recipient_id: id,
reference_id: id,
purpose,
amount
})
.into(table)
.returning(['id', 'recipient_id', 'amount'])
)
)

console.log(result)
}

exports.down = () => {}

0 comments on commit fb116ca

Please sign in to comment.