|
|
@@ -1,15 +1,20 @@ |
|
|
|
import models from './src/models' |
|
|
|
import seeds from './src/seeds' |
|
|
|
|
|
|
|
export const up = async queryInterface => { |
|
|
|
models.forEach(m => { |
|
|
|
queryInterface.createTable(m.tableName, m.rawAttributes) |
|
|
|
}) |
|
|
|
const createTablePromises = models.map(m => queryInterface.createTable(m.tableName, m.rawAttributes)) |
|
|
|
await Promise.all(createTablePromises) |
|
|
|
|
|
|
|
const seedTablePromise = models |
|
|
|
.filter(m => Boolean(seeds[m.modelName])) |
|
|
|
.map(m => queryInterface.bulkInsert(m.tableName, seeds[m.modelName])) |
|
|
|
return Promise.all(seedTablePromise) |
|
|
|
} |
|
|
|
|
|
|
|
export const down = async (queryInterface) => { |
|
|
|
models |
|
|
|
export const down = async queryInterface => { |
|
|
|
const dropTablePromises = models |
|
|
|
.reduce((reverse, m) => [m, ...reverse], []) |
|
|
|
.forEach(m => { |
|
|
|
queryInterface.dropTable(m.tableName) |
|
|
|
}) |
|
|
|
.map(m => queryInterface.dropTable(m.tableName)) |
|
|
|
|
|
|
|
return Promise.all(dropTablePromises) |
|
|
|
} |