-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
2,325 additions
and
1,515 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
/** | ||
* adonis-lucid | ||
* Copyright(c) 2015-2015 Harminder Virk | ||
* MIT Licensed | ||
*/ | ||
|
||
const ServiceProvider = require('adonis-fold').ServiceProvider | ||
|
||
class RunnerProvider extends ServiceProvider { | ||
|
||
* register () { | ||
this.app.singleton('Adonis/Src/Runner', function (app) { | ||
const Config = app.use('Adonis/Src/Config') | ||
const Runner = require('../src/Runner') | ||
return new Runner(Config) | ||
}) | ||
} | ||
|
||
} | ||
|
||
module.exports = RunnerProvider |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
/** | ||
* adonis-lucid | ||
* Copyright(c) 2015-2015 Harminder Virk | ||
* MIT Licensed | ||
*/ | ||
|
||
const ServiceProvider = require('adonis-fold').ServiceProvider | ||
|
||
class SchemaProvider extends ServiceProvider { | ||
|
||
* register () { | ||
this.app.bind('Adonis/Src/Schema', function () { | ||
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/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/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) | ||
}) | ||
} | ||
|
||
} | ||
|
||
module.exports = SchemaProvider |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict' | ||
|
||
/** | ||
* adonis-lucid | ||
* Copyright(c) 2015-2015 Harminder Virk | ||
* MIT Licensed | ||
*/ | ||
|
||
const migrationContent = ` | ||
'use strict' | ||
const Schema = use('Schema') | ||
class NewSchema extends Schema { | ||
up () { | ||
} | ||
down () { | ||
} | ||
} | ||
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}' | ||
} | ||
|
||
/** | ||
* @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) | ||
|
||
fs.writeFile(migrationPath, migrationContent, function (error) { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(`Created ${name} migration successfully`) | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = Make |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict' | ||
|
||
/** | ||
* adonis-lucid | ||
* Copyright(c) 2015-2015 Harminder Virk | ||
* MIT Licensed | ||
*/ | ||
|
||
const autoLoader = require('auto-loader') | ||
|
||
class Rollback { | ||
|
||
constructor (Helpers, Runner) { | ||
this.migrations = Helpers.migrationsPath() | ||
this.runner = Runner | ||
} | ||
|
||
/** | ||
* @description returns command description | ||
* @method description | ||
* @return {String} | ||
* @public | ||
*/ | ||
description () { | ||
return 'Rollback migrations executed in last batch' | ||
} | ||
|
||
/** | ||
* @description command signature to define expectation for | ||
* a given command to ace | ||
* @method signature | ||
* @return {String} | ||
* @public | ||
*/ | ||
signature () { | ||
return '{--force?}' | ||
} | ||
|
||
/** | ||
* @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) | ||
} | ||
|
||
} | ||
|
||
module.exports = Rollback |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict' | ||
|
||
/** | ||
* adonis-lucid | ||
* Copyright(c) 2015-2015 Harminder Virk | ||
* MIT Licensed | ||
*/ | ||
|
||
const autoLoader = require('auto-loader') | ||
|
||
class Run { | ||
|
||
constructor (Helpers, Runner) { | ||
this.migrations = Helpers.migrationsPath() | ||
this.runner = Runner | ||
} | ||
|
||
/** | ||
* @description returns command description | ||
* @method description | ||
* @return {String} | ||
* @public | ||
*/ | ||
description () { | ||
return 'Run latest migrations' | ||
} | ||
|
||
/** | ||
* @description command signature to define expectation for | ||
* a given command to ace | ||
* @method signature | ||
* @return {String} | ||
* @public | ||
*/ | ||
signature () { | ||
return '{--force?}' | ||
} | ||
|
||
/** | ||
* @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) | ||
} | ||
|
||
} | ||
|
||
module.exports = Run |
Oops, something went wrong.