database migration - How do I migrate my existing RavenDB store values so queries continue to work? -
i have object lives in raven store:
public class aumobilenumber : valueobject { private const string validvalueregex = @"^(\+61|61|0)?4[0-9]{8}$"; public aumobilenumber(string value) { value = (value ?? string.empty).replace(" ", ""); if (!regex.ismatch(value, validvalueregex)) throw new invalidoperationexception("the number supplied not valid au mobile. +61400555123, 61 400 555 123, 0400555123, 400 555 123 valid."); value = "+61" + value.substring(value.indexof("4"), value.length - value.indexof("4")); } public string value { get; private set; } public override string tostring() { return value; } }
this current version of type. previous version had line
value = value.substring(value.indexof("4"), value.length - value.indexof("4"));
instead of one
value = "+61" + value.substring(value.indexof("4"), value.length - value.indexof("4"));
so might imagine had lot of in db old version of code:
{ "value": "422601983" }
when created new object in store (that used aumobilenumber
) this:
{ "value": "+61422601983" }
this fine until queries had predicates based on value of aumobilenumber
started fail. or rather, not return expected results.
so thought "migrate" data 1 of these:
class aumobilenumberincludesplus61 : idocumentconversionlistener { const long version = 201309030814; public void entitytodocument(string key, object entity, ravenjobject document, ravenjobject metadata) { var m = entity aumobilenumber; if (m == null) return; metadata["customer-schema-version"] = version; document["value"] = m.tostring(); } public void documenttoentity(string key, object entity, ravenjobject document, ravenjobject metadata) { var m = entity aumobilenumber; if (m == null) return; if (metadata.value<long>("customer-schema-version") >= version) return; entity = new aumobilenumber(document.value<string>("value")); } }
the problem here debugged , execution never seemed reach past return;
guard clauses.
how protectively migrate numbers *
+61*
1 of these idocumentconversionlistener
s or doing wrong?
i've attempted write test show how broken requires hav json previous form of code.. way think 1 if insert raven store raw json , don't know how that.
any ideas?
it seems answer may patching. more discussion here: https://groups.google.com/forum/#!searchin/ravendb/migrate/ravendb/xkhpbfile48/khj8jmpcej4j
Comments
Post a Comment