diff --git a/.vscode/settings.json b/.vscode/settings.json index 8720c4e..2b280cd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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 + } +} \ No newline at end of file diff --git a/README.md b/README.md index fd4e415..cf1e465 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,8 @@ const options = { continuationKey: 'userId', belongsToUserOptions: undefined, metaDataFields: undefined, - metaDataContinuationKey: 'metaData' + metaDataContinuationKey: 'metaData', + mysql: false }; ``` @@ -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 diff --git a/lib/index.js b/lib/index.js index 329f783..4607a4c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -45,6 +45,7 @@ exports.init = (sequelize, optionsArg) => { metaDataFields: null, metaDataContinuationKey: 'metaData', mysql: false, + mariaDB: false, }; let ns = null; @@ -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 @@ -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] = { @@ -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) { diff --git a/package.json b/package.json index e584c45..6bcedd8 100644 --- a/package.json +++ b/package.json @@ -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", @@ -89,4 +89,4 @@ ] ] } -} +} \ No newline at end of file