couchdb-net icon indicating copy to clipboard operation
couchdb-net copied to clipboard

Resolve conflicts

Open mauro-rogledi opened this issue 2 years ago • 4 comments

I didn't understand how to work with conflicts. I need to find, apply resolution logic, and remove any conflicts.

According to the couchdb specification the command to send would be this:

GET /recipes/SpaghettiWithMeatballs?rev=6-136813b440a00a24834f5cb1ddf5b1f1

I haven't found how to do this with your library. Thank you

mauro-rogledi avatar Jun 20 '22 12:06 mauro-rogledi

I tried adding this method to the CouchDatabase class of your library and it works. Could it be interesting to add it to the standard version?

public async Task<TSource?> FindAsync(string docId, string rev, bool withConflicts = false,
    CancellationToken cancellationToken = default)
        {
            IFlurlRequest request = NewRequest()
                    .AppendPathSegment(docId);

            if (rev?.Length > 0)
            {
                request = request.SetQueryParam("rev", rev);
            }

            if (withConflicts)
            {
                request = request.SetQueryParam("conflicts", "true");
            }

            IFlurlResponse? response = await request
                .AllowHttpStatus(HttpStatusCode.NotFound)
                .GetAsync(cancellationToken)
                .ConfigureAwait(false);

            return response != null && response.StatusCode == (int)HttpStatusCode.OK
                ? await response.GetJsonAsync<TSource>().ConfigureAwait(false)
                : null;
        }

mauro-rogledi avatar Jun 21 '22 07:06 mauro-rogledi

Hi, sorry for the late answer,

I checked the docs, they say to merge them manually, upload the new version and then delete the conflicted one to resolve. https://docs.couchdb.org/en/stable/replication/conflicts.html#working-with-conflicting-documents

So I can give a look at how to implement this correctly as both the get and the delete need a rev parameter

matteobortolazzo avatar Jul 03 '22 12:07 matteobortolazzo

But the merge itself must be done manually so not sure how useful it would be to add the rev to the library

matteobortolazzo avatar Jul 03 '22 12:07 matteobortolazzo

Hello!

Because not only @mauro-rogledi need passing revision to FindAsync, but also I need to pass revision to AddOrUpdateAsync method, I made the pull request covering both cases.

I suggest not to add parameters, but introduced parameter object for both methods in my pull request.

dmlarionov avatar Jul 16 '22 12:07 dmlarionov

@dmlarionov PR is now merged in dev, sorry for the delay. Will release soon

matteobortolazzo avatar Oct 19 '22 21:10 matteobortolazzo