-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for db.import #265
Conversation
As discussed previously and as a first easy step before we implement full support for transactions, the base adapter interface should require implementation of an This method should return a Promise, with a simple result like the number of imported records. It should reject when the transaction fails, probably simply by forwarding the backend error. This method should probably be exposed at the Collection level as well, so users can bulk import large datasets right from their collection instance; sample api: const coll = kinto.collection("articles");
const recordsToImport = [{title: "art00001", ..., }, ..., {title: "art99999", ...}];
coll.import(recordsToImport)
.then(res => {
console.log(`${res} records were imported.`);
}); |
We've added adapter import method for LocalStorage and IndexedDB with @leplatrem. |
Remaining tasks:
|
In order to update the FirefoxStorage adapter, we need to add tests in Firefox. Here is the flow to run the FirefoxStorage tests:
|
Ok so we are almost there I guess. The remaining problem to handle is the We do not want import to overwrite records in a more recent version. |
|
||
if (!records.every(record => { | ||
return record.id && this.idSchema.validate(record.id); | ||
})) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about rejecting at first invalid record encountered instead? If we provide the id, that's useful for debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with some()
?
An even better solution would be to import only records of the dump with a last_modified value newer than the current collection_timestamp. |
} | ||
|
||
if (!records.every(record => record.last_modified)) { | ||
return reject("Record has no last_modified value."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
The difficulty with only importing items with lastModified later than the newest value is that you will end up keeping things that should be removed. I'd suggest either 1) Only allow import of a new collection or 2) Allow a collection to be completely replaced if (and only if) the imported data has a last modified value newer than the old collection. |
Yes that's the idea. Also you raise an important point, we should probably handle tombstones in our import in order to remove deleted records. |
|
2d23a24
to
eb3f916
Compare
eb3f916
to
7017aac
Compare
This looks good to me. I guess we r? @n1k0 when ready. |
@@ -214,6 +214,29 @@ articles.list({sort: "-title"}) | |||
> - By default, the records are sorted on `last_modified` in descending order. | |||
> - As mentioned in the [limitations](limitations.md) section, the sort is performed in memory. | |||
|
|||
## Importing initial records locally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Importing a data dump locally
8ae26d6
to
8b3d1e5
Compare
LGTM, r+ |
8b3d1e5
to
2067e3a
Compare
Add Collection#loadDump() method (fixes #265)
|
||
> #### Notes | ||
> | ||
> - Existing records are replaced if they do not have more recent modifications. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This…
For some of the Mozilla platform use-cases, it's desirable to have the ability to import initial data. Since we only need it here, for the time being, we can prototype the idea in the Firefox storage adapter and apply what we learn to the other adapters.