Last active
August 29, 2015 14:17
-
-
Save arnold-almeida/9cfbcea10f2f97d3b700 to your computer and use it in GitHub Desktop.
knex migrate:reset for pg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var chalk = require('chalk'); | |
/** | |
* @todo - Display error message when there are no tables to drop | |
* @todo - Get the migrations to display on CLI like when you run | |
* | |
* knex migrate:latest | |
* | |
* @param {[type]} knex [description] | |
* @param {[type]} Promise [description] | |
*/ | |
exports.seed = function(knex, Promise) { | |
var query = 'SELECT table_schema,table_name FROM information_schema.tables;'; | |
return knex | |
.raw(query) | |
.then(function(resp) { | |
return Promise | |
.map(resp.rows, function(row){ | |
if (row.table_schema === 'public') { | |
var table = row.table_name | |
console.log(chalk.red("Dropping :"), table) | |
return knex.schema.dropTable(table).exec(); | |
} | |
}) | |
}) | |
.finally(function() { | |
console.log(chalk.green("Running all migrations :")) | |
return knex.migrate.latest(knex.client.migrationConfig); | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment