percolatestudio/meteor-migrations

How to remove SimpleSchema columns?

Closed this issue · 2 comments

Removing a column from SimpleSchema is problematic. The obvious code is

SomeCollection.update({}, {$unset: { someAttribute: 1 }}, {multi: true});

But SimpleSchema fails with Error: someAttribute is not allowed by the schema. This works...

SomeCollection.update({}, {$unset: { someAttribute: 1 }}, {multi: true, validate: false});

...but it feels hacky and something no one will think of until they've been burned. Some ideas:

  • The framework could provide a function removeField(collection, field)
  • You could temporarily override Collection.update() and always add validate: false.
  • If nothing else, it should be mentioned in the README.
  • Something better that we didn't think of.

You realize you're in percolate migration's correct?

Anyway, you can do SomeCollection.direct to avoid collection2 cleaning your data.

My suggestion was that this framework would work around this problem, but I understand if that's not something you prioritize.

Mentioning it in the documentation could be a good idea.

I couldn't find any documentation for SomeCollection.direct, but if I'm doing a workaround, I'm happy with validate: false.