Skip to content

Commit

Permalink
Merge 13cdfae into 144fa83
Browse files Browse the repository at this point in the history
  • Loading branch information
okv committed Sep 8, 2019
2 parents 144fa83 + 13cdfae commit b223309
Show file tree
Hide file tree
Showing 12 changed files with 4,028 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
38 changes: 38 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"extends": "airbnb-base",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "script"
},
"rules": {
"comma-dangle": ["error", "never"],
"object-curly-spacing": ["error", "never"],
"indent": ["error", "tab"],
"no-tabs": 0,
"arrow-body-style": ["off"],
"arrow-parens": ["error", "always"],
"no-underscore-dangle": ["off"],
"camelcase": ["error", {
"properties": "never"
}],
"max-len": ["error", {
"code": 80,
"tabWidth": 1,
"ignoreTemplateLiterals": true
}],
"function-paren-newline": ["error", "consistent"],
"class-methods-use-this": [0],
"global-require": ["off"],
"prefer-destructuring": ["off"],
"strict": ["error", "global"],
"no-plusplus": ["error", {"allowForLoopAfterthoughts": true}],
"no-else-return": ["off"],
"no-lonely-if": ["off"],
"no-param-reassign": ["off"],
"consistent-return": ["off"],
"prefer-rest-params": ["off"]
},
"env": {
"mocha": true
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.nyc_output
coverage
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.npmignore
test
testUtils
.eslintignore
.eslintrc.json
.travis.yml
.nyc_output
coverage
.nycrc
10 changes: 10 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cache": true,
"all": true,
"exclude": [
"node_modules/**",
"test/**",
"testUtils/**",
"coverage/**"
]
}
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

language: node_js

cache:
npm: false

node_js:
- "stable"
- "12"
- "10"
- "8"
- "6"
- "4"

script:
- >
nodeVersionMajor=`node --version | grep -Eo 'v[0-9]+' | sed 's/v//'`;
if [ $nodeVersionMajor -eq 12 ]; then
npm audit;
else
echo "*** Do not run \`npm audit\` for non node.js 12 builds ($nodeVersionMajor)";
fi;
- npm run lint

- npm test

- >
nodeVersionMajor=`node --version | grep -Eo 'v[0-9]+' | sed 's/v//'`;
if [ $nodeVersionMajor -eq 12 ]; then
npm run makeCodeCoverageSummaryReport;
npm run makeCodeCoverageDetailReport;
coveralls < coverage/lcov.info;
else
echo "*** Do not make coverage reports for non node.js 12 builds ($nodeVersionMajor)";
fi;
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,40 @@
[East](https://github.com/okv/east) (node.js database migration tool)
plugin which logs duration of every migration.

Work in progress...
[![Build Status](https://travis-ci.org/okv/east-migration-duration-logger.svg?branch=master)](https://travis-ci.org/okv/east-migration-duration-logger)
[![Coverage Status](https://coveralls.io/repos/github/okv/east-migration-duration-logger/badge.svg)](https://coveralls.io/github/okv/east-migration-duration-logger)
[![Npm version](https://img.shields.io/npm/v/east-migration-duration-logger.svg)](https://www.npmjs.org/package/east-migration-duration-logger)


## Installation

```sh
npm install east-migration-duration-logger
```


## Usage

Add this plugin to the `plugins` section to `.eastrc` e.g.:

```json
{
"plugins": ["east-migration-duration-logger"]
}
```

That's it, after that duration of migrate, rollback actions will be logged
to the output e.g.:

```
> east migrate
arget migrations:
1_doSomething
2_doSomethingElse
Migrate "1_doSomething"
Action migrate of "1_doSomething" done in 206ms
Migration done
Migrate "2_doSomethingElse"
Action migrate of "2_doSomethingElse" done in 1ms
Migration done
```
50 changes: 50 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

exports.register = (registerParams) => {
const migratorHooks = registerParams.migratorHooks;

let startDate;

const createFinishHandler = (handlerParams) => {
const actionName = handlerParams.actionName;
const status = handlerParams.status;

return (params) => {
const duration = Date.now() - startDate;

const migration = params.migration;
const migrationParams = params.migrationParams;

const logger = migrationParams.logger || console;

logger.log(
`Action ${actionName} of "${migration.name}" ${status} ` +
`in ${duration}ms`
);
};
};

migratorHooks.on('beforeMigrate', () => {
startDate = Date.now();
});
migratorHooks.on(
'afterMigrate',
createFinishHandler({actionName: 'migrate', status: 'done'})
);
migratorHooks.on(
'migrateError',
createFinishHandler({actionName: 'migrate', status: 'failed'})
);

migratorHooks.on('beforeRollback', () => {
startDate = Date.now();
});
migratorHooks.on(
'afterRollback',
createFinishHandler({actionName: 'rollback', status: 'done'})
);
migratorHooks.on(
'rollbackError',
createFinishHandler({actionName: 'rollback', status: 'failed'})
);
};
Loading

0 comments on commit b223309

Please sign in to comment.