Created
January 14, 2016 16:42
-
-
Save manuelbieh/606710b003b5fe448100 to your computer and use it in GitHub Desktop.
Creates migration files for existing sequelize models
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
import * as models from "models"; | |
import fs from "fs"; | |
for(let model in models) { | |
let attributes = models[model].attributes; | |
for(let column in attributes) { | |
delete attributes[column].Model; | |
delete attributes[column].fieldName; | |
delete attributes[column].field; | |
for(let property in attributes[column]) { | |
if(property.startsWith('_')) { | |
delete attributes[column][property]; | |
} | |
} | |
} | |
let schema = JSON.stringify(attributes, null, 2); | |
let tableName = models[model].tableName; | |
let template = `'use strict'; | |
module.exports = { | |
up: function(queryInterface, Sequelize) { | |
return queryInterface.createTable('${tableName}', ${schema}); | |
}, | |
down: function(queryInterface, Sequelize) { | |
return queryInterface.dropTable(${tableName}); | |
} | |
};` | |
if(models[model].tableName !== undefined) { | |
fs.writeFileSync('./tmp/' + models[model].tableName + '.js', template); | |
} | |
}; |
It's not working with v5 :(
can post here you error message and stack to check it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not working with v5 :(