Skip to content

Commit 8e04ce2

Browse files
feat: modernize assets & skeleton files (#909)
1 parent 7419ddb commit 8e04ce2

36 files changed

+310
-387
lines changed

.github/stale.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Number of days of inactivity before an issue becomes stale
2+
daysUntilStale: 60
3+
# Number of days of inactivity before a stale issue is closed
4+
daysUntilClose: 7
5+
# Issues with these labels will never be considered stale
6+
exemptLabels:
7+
- bug
8+
- feature
9+
- semver:major
10+
# Comment to post when marking an issue as stale. Set to `false` to disable
11+
markComment: >
12+
This issue has been automatically marked as stale because it has not had
13+
recent activity. It will be closed if no further activity occurs. Thank you
14+
for your contributions.
15+
# Comment to post when closing a stale issue. Set to `false` to disable
16+
closeComment: false

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@
3030
"gulp": "^4.0.0",
3131
"mocha": "^6.0.0",
3232
"mysql2": "latest",
33-
"nodeify": "^1.0.1",
3433
"pg": "latest",
3534
"pg-hstore": "latest",
3635
"sequelize": "latest",
3736
"sqlite3": "latest",
3837
"through2": "^3.0.0"
3938
},
4039
"options": {
41-
"mocha": "--require scripts/mocha-bootload.js --check-leaks --exit --timeout 30000 --colors --recursive --reporter spec"
40+
"mocha": "--require scripts/mocha-bootload.js --bail --check-leaks --exit --timeout 30000 --colors --recursive --reporter spec"
4241
},
4342
"eslintIgnore": [
4443
"test/support",
Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
'use strict';
22

33
module.exports = {
4-
up: (queryInterface, Sequelize) => {
5-
return queryInterface
6-
.createTable('<%= tableName %>', {
7-
id: {
8-
allowNull: false,
9-
autoIncrement: true,
10-
primaryKey: true,
11-
type: Sequelize.INTEGER
12-
},
13-
14-
<% attributes.forEach(function(attribute) { %>
15-
<%= attribute.fieldName %>: {
16-
type: Sequelize.<%= attribute.dataFunction ? `${attribute.dataFunction.toUpperCase()}(Sequelize.${attribute.dataType.toUpperCase()})` : attribute.dataValues ? `${attribute.dataType.toUpperCase()}(${attribute.dataValues})` : attribute.dataType.toUpperCase() %>
17-
},
18-
<% }) %>
4+
up: async (queryInterface, Sequelize) => {
5+
await queryInterface.createTable('<%= tableName %>', {
6+
id: {
7+
allowNull: false,
8+
autoIncrement: true,
9+
primaryKey: true,
10+
type: Sequelize.INTEGER
11+
},
1912

20-
<%= createdAt %>: {
21-
allowNull: false,
22-
type: Sequelize.DATE
13+
<% attributes.forEach(function(attribute) { %>
14+
<%= attribute.fieldName %>: {
15+
type: Sequelize.<%= attribute.dataFunction ? `${attribute.dataFunction.toUpperCase()}(Sequelize.${attribute.dataType.toUpperCase()})` : attribute.dataValues ? `${attribute.dataType.toUpperCase()}(${attribute.dataValues})` : attribute.dataType.toUpperCase() %>
2316
},
17+
<% }) %>
18+
19+
<%= createdAt %>: {
20+
allowNull: false,
21+
type: Sequelize.DATE
22+
},
2423

25-
<%= updatedAt %>: {
26-
allowNull: false,
27-
type: Sequelize.DATE
28-
}
29-
});
24+
<%= updatedAt %>: {
25+
allowNull: false,
26+
type: Sequelize.DATE
27+
}
28+
});
3029
},
3130

32-
down: (queryInterface, Sequelize) => {
33-
return queryInterface.dropTable('<%= tableName %>');
31+
down: async (queryInterface, Sequelize) => {
32+
await queryInterface.dropTable('<%= tableName %>');
3433
}
3534
};

src/assets/migrations/skeleton.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
'use strict';
22

33
module.exports = {
4-
up: (queryInterface, Sequelize) => {
5-
/*
6-
Add altering commands here.
7-
Return a promise to correctly handle asynchronicity.
8-
9-
Example:
10-
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
11-
*/
4+
up: async (queryInterface, Sequelize) => {
5+
/**
6+
* Add altering commands here.
7+
*
8+
* Example:
9+
* await queryInterface.createTable('users', { id: Sequelize.INTEGER });
10+
*/
1211
},
1312

14-
down: (queryInterface, Sequelize) => {
15-
/*
16-
Add reverting commands here.
17-
Return a promise to correctly handle asynchronicity.
18-
19-
Example:
20-
return queryInterface.dropTable('users');
21-
*/
13+
down: async (queryInterface, Sequelize) => {
14+
/**
15+
* Add reverting commands here.
16+
*
17+
* Example:
18+
* await queryInterface.dropTable('users');
19+
*/
2220
}
2321
};

src/assets/models/model.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
'use strict';
22

3+
const { Model } = require('sequelize');
4+
35
module.exports = (sequelize, DataTypes) => {
4-
const <%= name %> = sequelize.define('<%= name %>', {
6+
class <%= name %> extends Model {
7+
/**
8+
* Helper method for defining associations.
9+
* This method is not part of Sequelize lifecycle.
10+
* The `models/index` file will call this method automatically.
11+
*/
12+
static associate (models) {
13+
// define association here
14+
}
15+
};
16+
17+
<%= name %>.init({
518
<% attributes.forEach(function(attribute, index) { %>
619
<%= attribute.fieldName %>: DataTypes.<%= attribute.dataFunction ? `${attribute.dataFunction.toUpperCase()}(DataTypes.${attribute.dataType.toUpperCase()})` : attribute.dataValues ? `${attribute.dataType.toUpperCase()}(${attribute.dataValues})` : attribute.dataType.toUpperCase() %>
720
<%= (Object.keys(attributes).length - 1) > index ? ',' : '' %>
821
<% }) %>
922
}, {
23+
sequelize,
24+
modelName: '<%= name %>',
1025
<%= underscored ? 'underscored: true,' : '' %>
1126
});
1227

13-
<%= name %>.associate = function(models) {
14-
// associations can be defined here
15-
};
16-
1728
return <%= name %>;
1829
};

src/assets/seeders/skeleton.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
'use strict';
22

33
module.exports = {
4-
up: (queryInterface, Sequelize) => {
5-
/*
6-
Add altering commands here.
7-
Return a promise to correctly handle asynchronicity.
8-
9-
Example:
10-
return queryInterface.bulkInsert('People', [{
11-
name: 'John Doe',
12-
isBetaMember: false
13-
}], {});
4+
up: async (queryInterface, Sequelize) => {
5+
/**
6+
* Add seed commands here.
7+
*
8+
* Example:
9+
* await queryInterface.bulkInsert('People', [{
10+
* name: 'John Doe',
11+
* isBetaMember: false
12+
* }], {});
1413
*/
1514
},
1615

17-
down: (queryInterface, Sequelize) => {
18-
/*
19-
Add reverting commands here.
20-
Return a promise to correctly handle asynchronicity.
21-
22-
Example:
23-
return queryInterface.bulkDelete('People', null, {});
24-
*/
16+
down: async (queryInterface, Sequelize) => {
17+
/**
18+
* Add commands to revert seed here.
19+
*
20+
* Example:
21+
* await queryInterface.bulkDelete('People', null, {});
22+
*/
2523
}
2624
};

src/commands/model_generate.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ exports.handler = function (args) {
3030
ensureMigrationsFolder();
3131
checkModelFileExistence(args);
3232

33-
3433
try {
3534
helpers.model.generateFile(args);
3635
} catch (err) {

src/core/migrator.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Umzug from 'umzug';
22
import _ from 'lodash';
3-
import { promisify } from 'util';
43
import pTry from 'p-try';
54

65
import helpers from '../helpers/index';
@@ -34,10 +33,7 @@ function getSequelizeInstance () {
3433
export function getMigrator (type, args) {
3534
return pTry(() => {
3635
if (!(helpers.config.configFileExists() || args.url)) {
37-
helpers.view.error(
38-
'Cannot find "' + helpers.config.getConfigFile() +
39-
'". Have you run "sequelize init"?'
40-
);
36+
helpers.view.error(`Cannot find "${helpers.config.getConfigFile()}". Have you run "sequelize init"?`);
4137
process.exit(1);
4238
}
4339

@@ -49,14 +45,7 @@ export function getMigrator (type, args) {
4945
migrations: {
5046
params: [sequelize.getQueryInterface(), Sequelize],
5147
path: helpers.path.getPath(type),
52-
pattern: /\.c?js$/,
53-
wrap: fun => {
54-
if (fun.length === 3) {
55-
return promisify(fun);
56-
} else {
57-
return fun;
58-
}
59-
}
48+
pattern: /\.c?js$/
6049
}
6150
});
6251

src/sequelize.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import helpers from './helpers/index';
1919

2020
helpers.view.teaser();
2121

22-
const cli = yargs
22+
yargs
2323
.help()
2424
.version()
2525
.command('db:migrate', 'Run pending migrations', migrate)
@@ -42,11 +42,7 @@ const cli = yargs
4242
.command(['model:generate', 'model:create'], 'Generates a model and its migration', modelGenerate)
4343
.command(['seed:generate', 'seed:create'], 'Generates a new seed file', seedGenerate)
4444
.wrap(yargs.terminalWidth())
45-
.strict();
46-
47-
const args = cli.argv;
48-
49-
// if no command then show help
50-
if (!args._[0]) {
51-
cli.showHelp();
52-
}
45+
.demandCommand(1, 'Please specify a command')
46+
.help()
47+
.strict()
48+
.argv;

test/db/migrate-json.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ const _ = require('lodash');
111111
done();
112112
});
113113
}, {
114-
migrationFile: 'new/*createPerson',
115-
config: { promisifyMigrations: false }
114+
migrationFile: 'new/*createPerson'
116115
});
117116
});
118117
});

0 commit comments

Comments
 (0)