From c5532d452fd0694ed7f2f9405aae3917e66e9ede Mon Sep 17 00:00:00 2001 From: Chase Anderson Date: Tue, 25 Feb 2020 08:55:55 -0600 Subject: [PATCH 1/5] Update README with mysql attribute --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 From 6c21c2e08c6a39e8e10afb6329bfd2edd7f7ab92 Mon Sep 17 00:00:00 2001 From: Chase Anderson Date: Tue, 7 Jul 2020 11:30:15 -0600 Subject: [PATCH 2/5] mariaDB option --- .vscode/settings.json | 8 +++++--- lib/index.js | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8720c4e..9a984e6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,9 @@ { "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/lib/index.js b/lib/index.js index 329f783..4473e22 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; @@ -603,6 +604,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 +672,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) { From 76c9aee9a003612c8179d57a6f7aaa2209b35759 Mon Sep 17 00:00:00 2001 From: Chase Anderson Date: Tue, 7 Jul 2020 11:48:56 -0600 Subject: [PATCH 3/5] only create revisionChange on update --- .vscode/settings.json | 1 + lib/index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 9a984e6..2b280cd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "workbench.colorTheme": "Monokai", "editor.formatOnPaste": true, "editor.formatOnSave": true, "eslint.packageManager": "yarn", diff --git a/lib/index.js b/lib/index.js index 4473e22..77f952e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -432,7 +432,7 @@ 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 From da6039a01134c01e3311bc656599372b29e32e52 Mon Sep 17 00:00:00 2001 From: Chase Anderson Date: Tue, 7 Jul 2020 11:54:25 -0600 Subject: [PATCH 4/5] update version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 1d118649a0a15c6d383b95f11c1fff17031e074b Mon Sep 17 00:00:00 2001 From: Chase Anderson Date: Tue, 7 Jul 2020 12:01:22 -0600 Subject: [PATCH 5/5] pretty test --- lib/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 77f952e..4607a4c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -45,7 +45,7 @@ exports.init = (sequelize, optionsArg) => { metaDataFields: null, metaDataContinuationKey: 'metaData', mysql: false, - mariaDB: false + mariaDB: false, }; let ns = null; @@ -432,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 && objectRevision.operation === 'update') { + if ( + options.enableRevisionChangeModel && + objectRevision.operation === 'update' + ) { _.forEach(delta, difference => { const o = helpers.diffToString( difference.item @@ -605,7 +608,7 @@ exports.init = (sequelize, optionsArg) => { if (options.mysql) { attributes.document.type = Sequelize.TEXT('MEDIUMTEXT'); } else if (options.mariaDB) { - attributes.document.type = Sequelize.JSON + attributes.document.type = Sequelize.JSON; } attributes[options.defaultAttributes.documentId] = {