Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README with mysql attribute #99

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"workbench.colorTheme": "Monokai",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"eslint.autoFixOnSave": true,
"eslint.packageManager": "yarn",
"eslint.enable": true
}
"eslint.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ const options = {
continuationKey: 'userId',
belongsToUserOptions: undefined,
metaDataFields: undefined,
metaDataContinuationKey: 'metaData'
metaDataContinuationKey: 'metaData',
mysql: false
};
```

Expand All @@ -217,7 +218,8 @@ const options = {
| [continuationKey] | String | 'userId' | The continuation-local-storage key that contains the user id. |
| [belongsToUserOptions] | Object | undefined | The options used for belongsTo between userModel and Revision model |
| [metaDataFields] | Object | undefined | The keys that will be provided in the meta data object. { key: isRequired (boolean)} format. Can be used to privovide additional fields - other associations, dates, etc to the Revision model |
| [metaDataContinuationKey] | String | 'metaData' | The continuation-local-storage key that contains the meta data object, from where the metaDataFields are extracted. |
| [metaDataContinuationKey] | String | 'metaData' | The continuation-local-storage key that contains the meta data object, from where the metaDataFields are extracted.
| [mysql] | Boolean | false | option to use MEDIUMTEXT column instead of JSONB for mysql and mariadb instances |

## Limitations

Expand Down
11 changes: 10 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ exports.init = (sequelize, optionsArg) => {
metaDataFields: null,
metaDataContinuationKey: 'metaData',
mysql: false,
mariaDB: false,
};

let ns = null;
Expand Down Expand Up @@ -431,7 +432,10 @@ exports.init = (sequelize, optionsArg) => {
.save({ transaction: opt.transaction })
.then(objectRevision => {
// Loop diffs and create a revision-diff for each
if (options.enableRevisionChangeModel) {
if (
options.enableRevisionChangeModel &&
objectRevision.operation === 'update'
) {
_.forEach(delta, difference => {
const o = helpers.diffToString(
difference.item
Expand Down Expand Up @@ -603,6 +607,8 @@ exports.init = (sequelize, optionsArg) => {

if (options.mysql) {
attributes.document.type = Sequelize.TEXT('MEDIUMTEXT');
} else if (options.mariaDB) {
attributes.document.type = Sequelize.JSON;
}

attributes[options.defaultAttributes.documentId] = {
Expand Down Expand Up @@ -669,6 +675,9 @@ exports.init = (sequelize, optionsArg) => {
if (options.mysql) {
attributes.document.type = Sequelize.TEXT('MEDIUMTEXT');
attributes.diff.type = Sequelize.TEXT('MEDIUMTEXT');
} else if (options.mariaDB) {
attributes.document.type = Sequelize.JSON;
attributes.diff.type = Sequelize.JSON;
}

if (options.UUID) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequelize-paper-trail",
"version": "3.0.1",
"version": "3.0.2",
"description": "Track changes to your Sequelize models data. Perfect for auditing or versioning.",
"author": {
"name": "Niels van Galen Last",
Expand Down Expand Up @@ -89,4 +89,4 @@
]
]
}
}
}