Skip to content

Commit

Permalink
Merge branch 'release-2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 29, 2015
2 parents 3b6dc8a + 1607304 commit f734af0
Show file tree
Hide file tree
Showing 25 changed files with 472 additions and 227 deletions.
3 changes: 0 additions & 3 deletions .cz.json

This file was deleted.

10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
language: node_js
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
node_js:
- "iojs"
- "4.0.0"
- "5.3.0"
sudo: false
install:
- npm install
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"author": "adonisjs",
"license": "MIT",
"devDependencies": {
"adonis-fold": "^2.0.0",
"chai": "^3.2.0",
"co": "^4.6.0",
"coveralls": "^2.11.4",
"cz-conventional-changelog": "^1.1.2",
"fs-extra": "^0.26.3",
"istanbul": "^0.3.20",
"loadtest": "^1.2.14",
Expand All @@ -25,7 +25,7 @@
"standard": "^5.4.1"
},
"peerDependencies": {
"adonis-fold": "^1.0.0"
"adonis-fold": "^2.0.0"
},
"dependencies": {
"auto-loader": "^0.2.0",
Expand Down
20 changes: 6 additions & 14 deletions providers/SchemaProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,16 @@ class SchemaProvider extends ServiceProvider {
return require('../src/Schema')
})

this.app.bind('Adonis/Commands/Make', function (app) {
const Helpers = app.use('Adonis/Src/Helpers')
const Make = require('../src/Commands/Make')
return new Make(Helpers)
this.app.bind('Adonis/Commands/Make', function () {
return require('../src/Commands/Make')
})

this.app.bind('Adonis/Commands/Run', function (app) {
const Helpers = app.use('Adonis/Src/Helpers')
const Runner = app.use('Adonis/Src/Runner')
const Run = require('../src/Commands/Run')
return new Run(Helpers, Runner)
this.app.bind('Adonis/Commands/Run', function () {
return require('../src/Commands/Run')
})

this.app.bind('Adonis/Commands/Rollback', function (app) {
const Helpers = app.use('Adonis/Src/Helpers')
const Runner = app.use('Adonis/Src/Runner')
const Rollback = require('../src/Commands/Rollback')
return new Rollback(Helpers, Runner)
this.app.bind('Adonis/Commands/Rollback', function () {
return require('../src/Commands/Rollback')
})
}

Expand Down
89 changes: 40 additions & 49 deletions src/Commands/Make.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* MIT Licensed
*/

const fs = require('fs')
const Ioc = require('adonis-fold').Ioc

const migrationContent = `
'use strict'
Expand All @@ -24,57 +27,45 @@ class NewSchema extends Schema {
module.exports = NewSchema
`

const fs = require('fs')

class Make {

constructor (Helpers) {
this.helpers = Helpers
}

/**
* @description returns command description
* @method description
* @return {String}
* @public
*/
description () {
return 'Create a new migration file'
}

/**
* @description command signature to define expectation for
* a given command to ace
* @method signature
* @return {String}
* @public
*/
signature () {
return '{name}'
}
let Make = exports = module.exports = {}

/**
* @description creates a new migration file
* @method handle
* @param {Object} options
* @param {Object} flags
* @return {Object}
* @public
*/
handle (options) {
return new Promise((resolve, reject) => {
const name = `${new Date().getTime()}_${options.name}.js`
const migrationPath = this.helpers.migrationsPath(name)
Make.description = 'Create a new migration file'
Make.signature = '{name}'

fs.writeFile(migrationPath, migrationContent, function (error) {
if (error) {
reject(error)
} else {
resolve(`Created ${name} migration successfully`)
}
})
/**
* @description writes file with content to a given path
* @method writeFile
* @param {String} migrationPath
* @param {String} migrationContent
* @return {Object}
* @public
*/
Make.writeFile = function (migrationPath, migrationContent) {
return new Promise((resolve, reject) => {
fs.writeFile(migrationPath, migrationContent, function (error) {
if (error) {
return reject(error)
}
resolve()
})
}
})
}

module.exports = Make
/**
* @description creates a new migration file
* @method handle
* @param {Object} options
* @param {Object} flags
* @return {Object}
* @public
*/
Make.handle = function * (options) {
const helpers = Ioc.make('Adonis/Src/Helpers')
const Console = Ioc.use('Adonis/Src/Console')

const name = `${new Date().getTime()}_${options.name}.js`
const migrationPath = helpers.migrationsPath(name)

yield Make.writeFile(migrationPath, migrationContent)
Console.success(Console.icon('success') + ' created %s migration successfully', name)
}
67 changes: 27 additions & 40 deletions src/Commands/Rollback.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,39 @@
*/

const autoLoader = require('auto-loader')
const Ioc = require('adonis-fold').Ioc

class Rollback {
let Rollback = exports = module.exports = {}

constructor (Helpers, Runner) {
this.migrations = Helpers.migrationsPath()
this.runner = Runner
}
Rollback.description = 'Rollback migrations executed in last batch'
Rollback.signature = '{--force?}'

/**
* @description returns command description
* @method description
* @return {String}
* @public
*/
description () {
return 'Rollback migrations executed in last batch'
/**
* @description rollback all migrations using
* runner provider
* @method handle
* @param {Object} options
* @param {Object} flags
* @return {Object}
* @public
*/
Rollback.handle = function * (options, flags) {
const Helpers = Ioc.make('Adonis/Src/Helpers')
const Runner = Ioc.make('Adonis/Src/Runner')
const Console = Ioc.use('Adonis/Src/Console')
const migrations = Helpers.migrationsPath()

if (process.env.NODE_ENV === 'production' && !flags.force) {
throw new Error('Cannot run migrations in production')
}
const migrationsFiles = autoLoader.load(migrations)
const response = yield Runner.down(migrationsFiles)

/**
* @description command signature to define expectation for
* a given command to ace
* @method signature
* @return {String}
* @public
*/
signature () {
return '{--force?}'
if (response.status === 'completed') {
Console.success(Console.icon('success') + ' latest migrations batch has been rolled back')
}

/**
* @description rollback all migrations using
* runner provider
* @method handle
* @param {Object} options
* @param {Object} flags
* @return {Object}
* @public
*/
* handle (options, flags) {
if (process.env.NODE_ENV === 'production' && !flags.force) {
throw new Error('Cannot run migrations in production')
}
const migrationsFiles = autoLoader.load(this.migrations)
return yield this.runner.down(migrationsFiles)
if (response.status === 'skipped') {
Console.info(Console.icon('info') + ' already at the last batch')
}

}

module.exports = Rollback
67 changes: 27 additions & 40 deletions src/Commands/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,39 @@
*/

const autoLoader = require('auto-loader')
const Ioc = require('adonis-fold').Ioc

class Run {
let Run = exports = module.exports = {}

constructor (Helpers, Runner) {
this.migrations = Helpers.migrationsPath()
this.runner = Runner
}
Run.description = 'Run latest migrations'
Run.signature = '{--force?}'

/**
* @description returns command description
* @method description
* @return {String}
* @public
*/
description () {
return 'Run latest migrations'
/**
* @description rollback all migrations using
* runner provider
* @method handle
* @param {Object} options
* @param {Object} flags
* @return {Object}
* @public
*/
Run.handle = function * (options, flags) {
const Helpers = Ioc.make('Adonis/Src/Helpers')
const Runner = Ioc.make('Adonis/Src/Runner')
const Console = Ioc.use('Adonis/Src/Console')
const migrations = Helpers.migrationsPath()

if (process.env.NODE_ENV === 'production' && !flags.force) {
throw new Error('Cannot run migrations in production')
}
const migrationsFiles = autoLoader.load(migrations)
const response = yield Runner.up(migrationsFiles)

/**
* @description command signature to define expectation for
* a given command to ace
* @method signature
* @return {String}
* @public
*/
signature () {
return '{--force?}'
if (response.status === 'completed') {
Console.success(Console.icon('success') + ' database migrated successfully')
}

/**
* @description migrate all migrations using runner
* provider
* @method handle
* @param {Object} options
* @param {Object} flags
* @return {Object}
* @public
*/
* handle (options, flags) {
if (process.env.NODE_ENV === 'production' && !flags.force) {
throw new Error('Cannot run migrations in production')
}
const migrationsFiles = autoLoader.load(this.migrations)
return yield this.runner.up(migrationsFiles)
if (response.status === 'skipped') {
Console.info(Console.icon('info') + ' already the latest version')
}

}

module.exports = Run
7 changes: 5 additions & 2 deletions src/Runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const log = new CatLog('adonis:lucid')
class Runner {

constructor (Config) {
const config = Config.get('database.connection')
const connection = Config.get('database.connection')
const config = Config.get(`database.${connection}`)
this.knex = require('knex')(config)
this.migrationsTable = Config.get('database.migrationsTable')
this.migrationsTable = Config.get('database.migrationsTable', 'adonis_schema')
this.lockTable = `${this.migrationsTable}_lock`
this.migrations = []
}
Expand Down Expand Up @@ -322,6 +323,7 @@ class Runner {
return ''
})
.then((response) => {
this.knex.destroy()
const status = _.size(migrated) > 0 ? 'completed' : 'skipped'
resolve({migrated, status})
})
Expand All @@ -347,6 +349,7 @@ class Runner {
}
})
.then((response) => {
this.knex.destroy()
const status = _.size(migrated) > 0 ? 'completed' : 'skipped'
resolve({migrated, status})
})
Expand Down

0 comments on commit f734af0

Please sign in to comment.