-
-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathmigration-helper.js
More file actions
executable file
·35 lines (29 loc) · 1 KB
/
migration-helper.js
File metadata and controls
executable file
·35 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import _ from 'lodash';
import helpers from './index';
const Sequelize = helpers.generic.getSequelize();
module.exports = {
getTableName(modelName) {
return Sequelize.Utils.pluralize(modelName);
},
generateTableCreationFileContent(args) {
return helpers.template.render('migrations/create-table.js', {
tableName: this.getTableName(args.name),
attributes: helpers.model.transformAttributes(args.attributes),
createdAt: args.underscored ? 'created_at' : 'createdAt',
updatedAt: args.underscored ? 'updated_at' : 'updatedAt',
paranoid: args.paranoid,
underscored: args.underscored,
});
},
generateMigrationName(args) {
return _.trimStart(_.kebabCase('create-' + args.name), '-');
},
generateTableCreationFile(args) {
const migrationName = this.generateMigrationName(args);
const migrationPath = helpers.path.getMigrationPath(migrationName);
helpers.asset.write(
migrationPath,
this.generateTableCreationFileContent(args)
);
},
};