Skip to content

Instantly share code, notes, and snippets.

@arnold-almeida
Last active August 29, 2015 14:17
Show Gist options
  • Save arnold-almeida/9cfbcea10f2f97d3b700 to your computer and use it in GitHub Desktop.
Save arnold-almeida/9cfbcea10f2f97d3b700 to your computer and use it in GitHub Desktop.
knex migrate:reset for pg
'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