This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migrations): add new generator to make migrations
- Loading branch information
1 parent
5ba8e12
commit 1c3a823
Showing
6 changed files
with
129 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict' | ||
|
||
/** | ||
* adonis-commands | ||
* Copyright(c) 2015-2015 Harminder Virk | ||
* MIT Licensed | ||
*/ | ||
|
||
const utils = require('./helpers') | ||
const Ioc = require('adonis-fold').Ioc | ||
const i = require('inflect') | ||
const schemaString = require('./strings').schema | ||
|
||
let Middleware = exports = module.exports = {} | ||
|
||
Middleware.description = 'Generate new migration schema file' | ||
Middleware.signature = '{name:Name of the migration file} {--create?} {--table?}' | ||
|
||
/** | ||
* @description handle method that will be invoked by ace when | ||
* this command is executed | ||
* @method | ||
* @param {Object} options | ||
* @param {Object} flags | ||
* @return {void} | ||
* @public | ||
*/ | ||
Middleware.handle = function * (options, flags) { | ||
const Helpers = Ioc.use('Adonis/Src/Helpers') | ||
const Ansi = Ioc.use('Adonis/Src/Ansi') | ||
const name = `${utils.makeName(options.name, 'Schema')}` | ||
const migrationsPath = Helpers.migrationsPath(`${name}.js`) | ||
const tableName = i.pluralize(name.replace('Schema', '').toLowerCase()) | ||
let templateOptions = {up: '', down: ''} | ||
if (flags.create) { | ||
templateOptions.up = `this.create('${tableName}', function (table) { | ||
table.increments() | ||
table.timestamps() | ||
table.softDeletes() | ||
})` | ||
templateOptions.down = `this.drop('${tableName}')` | ||
} | ||
|
||
if (flags.table) { | ||
templateOptions.up = `this.table('${tableName}', function (table) { | ||
})` | ||
templateOptions.down = templateOptions.up | ||
} | ||
|
||
try { | ||
const response = yield utils.generateBlueprint(schemaString, migrationsPath, name, 'migration', templateOptions) | ||
Ansi.success(response) | ||
} catch (e) { | ||
Ansi.error(e.message) | ||
} | ||
} |
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