Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Replicator create_target can't be used since you must pass a Database instance #452

Closed
segevfiner opened this issue Oct 7, 2019 · 1 comment

Comments

@segevfiner
Copy link

Bug Description

Replicator supports creating a replication with create_target, but this can't actually be used as target_db only supports a database instance which means it must be an existing database.

2. What you expected to happen

That Replicator supports using create_target without pre-creating the database.

3. What actually happened

You can only pass it an already created database.

Environment details

python-cloudant 2.12.0
Python 3.7.4

@bessbd
Copy link
Contributor

bessbd commented Oct 9, 2019

Hi @segevfiner ,

Even though Replicator requires database instances, it does not mean those databases have to exist.
Consider the following example:

import time

from cloudant import couchdb_admin_party
from cloudant.database import CouchDatabase
from cloudant.document import Document
from cloudant.replicator import Replicator

RANDOM_DOC_ID = 'random_id'

with couchdb_admin_party(url='http://localhost:5984') as client:
    source_db = client.create_database('test_source_db')
    source_db.create_document({
        '_id': RANDOM_DOC_ID,
        'foo': 'bar'
    })

    target_db = CouchDatabase(client, 'test_target_db')

    assert not target_db.exists()

    replicator = Replicator(client)
    replication_document = replicator.create_replication(
        source_db=source_db,
        target_db=target_db,
        create_target=True
    )

    while replicator.replication_state(
            replication_document['_id']) != 'completed':
        time.sleep(1)

    assert Document(target_db, RANDOM_DOC_ID).exists()
    print('done')

I'll go ahead and close this issue. Please reopen or create a new one if this answer does not help with your use case or if you need any further clarification.

@bessbd bessbd closed this as completed Oct 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants