Create db cleanups for models#34
Conversation
|
Before proceeding to other models, please take a look if the |
swansontec
left a comment
There was a problem hiding this comment.
We need to get this tested. I have set up a push-test.edge.app server, so we can just deploy the code there and then tweak the edge-react-gui app to talk there instead of the production server. For that to work, we need to ensure that the database setup code also sets up the correct view documents. Otherwise the queries will fail.
| const cleanedDoc = uncleaner(cleaner)(doc) | ||
| await db.insert({ | ||
| ...cleanedDoc.doc, | ||
| _id: cleanedDoc.id, | ||
| _rev: cleanedDoc.rev ?? undefined | ||
| }) |
There was a problem hiding this comment.
The asCouchDoc uncleaner is supposed to handle this stuff. So db.insert(wasCouchThing(packThing(data))) is all you really need.
There was a problem hiding this comment.
I'm still not so sure how this works since insert expect a nano document type but asCouchDoc cannot be dereferenced to nano. For example, although they are structurally similar, CouchDoc names id as 'id' rather than '_id'.
There was a problem hiding this comment.
An uncleaner undoes the effect of a cleaner. That means re-assembling the fields the way Couch likes:
const asCouchFoo = asCouchDoc(asObject({ foo: asString }))
const wasCouchFoo = uncleaner(asCouchFoo)
asCouchFoo({ _id: '1', _rev: '2', foo: '3' }) // Goes to the clean format
wasCouchFoo({ id: '1', rev: '2', doc: { foo: '3' } }) // Goes back to the couch format
swansontec
left a comment
There was a problem hiding this comment.
We are getting a lot closer! Time for round two. Sorry if this is annoying, but that's why this work takes a long time - you have to do enough cleanup before you can even see the next level of dirtiness.
Another general note is that I have always been putting connection as the first parameter, not the last one. That keeps things consistent, since it's always present in the same place. I like to leave the last slot open for optional parameters.
I have taken the API key and defaults database cleanups into the serverlet PR, so we can merge them right away. That way your PR can focus just on the, users, devices, and thresholds.
| const cleanedDoc = uncleaner(cleaner)(doc) | ||
| await db.insert({ | ||
| ...cleanedDoc.doc, | ||
| _id: cleanedDoc.id, | ||
| _rev: cleanedDoc.rev ?? undefined | ||
| }) |
There was a problem hiding this comment.
An uncleaner undoes the effect of a cleaner. That means re-assembling the fields the way Couch likes:
const asCouchFoo = asCouchDoc(asObject({ foo: asString }))
const wasCouchFoo = uncleaner(asCouchFoo)
asCouchFoo({ _id: '1', _rev: '2', foo: '3' }) // Goes to the clean format
wasCouchFoo({ id: '1', rev: '2', doc: { foo: '3' } }) // Goes back to the couch format
swansontec
left a comment
There was a problem hiding this comment.
Ah, this is much nicer! One question this time.
98fe40e to
1dc37b6
Compare
1dc37b6 to
852ae32
Compare
fd54b08 to
a8806c1
Compare
swansontec
left a comment
There was a problem hiding this comment.
This looks almost ready. We need to fix some conflict errors, and then we can deploy to push-test.edge.app for testing.
a8806c1 to
0e43c93
Compare
|
I have deployed this branch to the push-test.edge.app server, but it's not working very well. If you want to test it yourself, I can get you credentials to work with the server. To adjust the client, just modify |
Uh oh!
There was an error while loading. Please reload this page.