不要怂,就是干,撸起袖子干!

Commit ca91b664 by sdepold

sequelize --init is creating the migrations folder now

1 parent e22d93ac
Showing with 28 additions and 1 deletions
...@@ -7,6 +7,7 @@ const path = require("path") ...@@ -7,6 +7,7 @@ const path = require("path")
, _ = Sequelize.Utils._ , _ = Sequelize.Utils._
var configPath = __dirname + '/../config' var configPath = __dirname + '/../config'
, migrationsPath = __dirname + '/../migrations'
, configFile = configPath + '/config.json' , configFile = configPath + '/config.json'
, configPathExists = path.existsSync(configPath) , configPathExists = path.existsSync(configPath)
, configFileExists = path.existsSync(configFile) , configFileExists = path.existsSync(configFile)
...@@ -22,6 +23,29 @@ var writeConfig = function(config) { ...@@ -22,6 +23,29 @@ var writeConfig = function(config) {
fs.writeFileSync(configFile, config) fs.writeFileSync(configFile, config)
} }
var createMigrationsFolder = function(force) {
if(force) {
console.log('Deleting the migrations folder.')
try {
fs.readdirSync(migrationsPath).forEach(function(filename) {
fs.unlinkSync(migrationsPath + '/' + filename)
})
} catch(e) {}
try {
fs.rmdirSync(migrationsPath)
console.log('Successfully deleted the migrations folder.')
} catch(e) {}
}
console.log('Creating migrations folder.')
try {
fs.mkdirSync(migrationsPath)
console.log('Successfully create migrations folder.')
} catch(e) {
console.log('Migrations folder already exist.')
}
}
var readConfig = function() { var readConfig = function() {
try { try {
return JSON.parse(fs.readFileSync(configFile)) return JSON.parse(fs.readFileSync(configFile))
...@@ -58,8 +82,9 @@ if(program.migrate) { ...@@ -58,8 +82,9 @@ if(program.migrate) {
if(program.undo) { if(program.undo) {
sequelize.migrator.findOrCreateSequelizeMetaModel().success(function(Meta) { sequelize.migrator.findOrCreateSequelizeMetaModel().success(function(Meta) {
Meta.find({ order: 'id DESC' }).success(function(meta) { Meta.find({ order: 'id DESC' }).success(function(meta) {
if(meta) if(meta) {
migrator = sequelize.getMigrator(_.extend(migratorOptions, meta), true) migrator = sequelize.getMigrator(_.extend(migratorOptions, meta), true)
}
migrator.migrate({ method: 'down' }) migrator.migrate({ method: 'down' })
}) })
...@@ -83,6 +108,8 @@ if(program.migrate) { ...@@ -83,6 +108,8 @@ if(program.migrate) {
} else { } else {
console.log('A config.json already exists. Run "sequelize --init --force" to overwrite it.') console.log('A config.json already exists. Run "sequelize --init --force" to overwrite it.')
} }
createMigrationsFolder(program.force)
} else { } else {
console.log('Please define any params!') console.log('Please define any params!')
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!