mongoose-sequence icon indicating copy to clipboard operation
mongoose-sequence copied to clipboard

added fix to allow increase no. of reference fields without reseting counter

Open bhanuc opened this issue 7 years ago • 2 comments

This PR allows a user to increase his scope fields without resetting his counter. For example if we have reference fields -> ["city", "district"] and for some reason, we want reference fields -> ["city", "district", "country"], currently there is no way to do it. This increase and fix also requires modifying your existing counter collection - so a script is added for same. How the fix works: Step 1- Use the script incrementScopePrep.js to change the id of existing counters by adding a suitable suffix Step 2 - Add the following fields in options :

// Change - 
   var options = {
      id: "member_id",
      inc_field: "id",
      reference_fields: ["city", "district"]
    }
// to 
    var options = {
      id: "member_id",
      inc_field: "id",
      reference_fields: ["city", "district", "country"],
      old_reference_fields: ["city", "district"],
      old_ref_field_suffix: "old" // optional, only needed when you want a custom suffix

    }

Logic involved - While incrementing, we check if old_reference_fields is set, if yes, then we first try to find new counter as per new reference field, if found, it is incremented, else we create a counter based on seq on older counter (which has a different id)

I implemented this, as I needed this feature urgently. Would love to know opinions about this approach and any other feedback about this PR.

Also would appreciate if eslint preferences of the project are updated so PRs can be automatically formatted as per project standard. Current autofix leads to lots of extra whitespaces as visible in the PR.

bhanuc avatar Mar 07 '19 21:03 bhanuc

Coverage Status

Coverage decreased (-11.5%) to 88.489% when pulling 72c4711402727931548be96d03b10d5efda7ebd2 on bhanuc:scope_increase into 94b4daf224ca175954df96ea1f4c6c796dcb4e95 on ramiel:develop.

coveralls avatar Mar 08 '19 08:03 coveralls

Coverage Status

Coverage decreased (-11.5%) to 88.489% when pulling ec8ba324a4b957b379ca3da4d537777e444b32e3 on bhanuc:scope_increase into 94b4daf224ca175954df96ea1f4c6c796dcb4e95 on ramiel:develop.

coveralls avatar Mar 08 '19 08:03 coveralls