I have a Simpleschema of a Meteor Collection like this:
Users.attachSchema(new SimpleSchema({: {
...
age: {
type: String,
optional: true
},
...
}));
Now i want to change age's type to type: Number.
Q1: Do i have to run a migration?
Q2: If so, how would the migration look like?
Usually these kinds of question are really broad but I just try to give you some idea on how to think about this issue:
Q1: Do i have to run a migration?
If you have external models, controllers or views which depend on or make use of
age(even implicitly) and expect it to be anumber, then you need to migrate.Q2: If so, how would the migration look like?
There are many options here.
For instance you can do a fast migration and just change the schema to use
Numberand update any code that uses age to handle it as a Number. To ensure compatibility you would require to write a patch, that updates all existing documents withagebeing aStringtoNumber.You can also do a much slower migration and keep your model backwards compatible by extending your schema:
Then you write a helper, that always returns the age in the new format, with fallback to the old structure:
Then you rewrite the other code to use only
getAgeto retrieve the age. Note, that you also need to update methods, that insert / update user documents, so they useageNuminstead ofage.Using this approach all new users will have a
Numberbased age by default, while older documents, that have not been updated yet are still supported. This avoids the need to patch all documents for integrity.There are many other options here and it is hard to give a more precise answer.