コード例 #1
0
    def test_get_last(self):
        indices = ["a string", ["a", "list"]]
        save_args = get_safe_write_kwargs()

        for index in indices:
            self.addCleanup(
                lambda idx:
                [cp.delete() for cp in ExportSchema.get_all_checkpoints(idx)],
                index)

        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            dt = datetime.utcnow()
            schema1 = ExportSchema(index=index, timestamp=dt)
            schema1.save(**save_args)
            self.assert_docs_equal(schema1, ExportSchema.last(index))
            schema2 = ExportSchema(index=index,
                                   timestamp=dt + timedelta(seconds=1))
            schema2.save(**save_args)
            self.assert_docs_equal(schema2, ExportSchema.last(index))
            schema3 = ExportSchema(index=index,
                                   timestamp=dt - timedelta(seconds=1))
            schema3.save(**save_args)
            # still schema2 (which has a later date than schema3)
            self.assert_docs_equal(schema2, ExportSchema.last(index))
コード例 #2
0
 def handle(self, *args, **options):
     db = ExportSchema.get_db()
     for index in ExportSchema.get_all_indices():
         last = ExportSchema.last(index)
         if not last.timestamp:
             config = ExportConfiguration(db, index, disable_checkpoints=True)
             config.create_new_checkpoint()
             assert ExportSchema.last(index).timestamp
             print "set timestamp for %s" % index
         else:
             print "%s all set" % index
コード例 #3
0
 def handle(self, *args, **options):
     db = ExportSchema.get_db()
     for index in ExportSchema.get_all_indices():
         last = ExportSchema.last(index)
         if not last.timestamp:
             config = ExportConfiguration(db,
                                          index,
                                          disable_checkpoints=True)
             config.create_new_checkpoint()
             assert ExportSchema.last(index).timestamp
             print "set timestamp for %s" % index
         else:
             print "%s all set" % index
コード例 #4
0
ファイル: schema.py プロジェクト: kennknowles/couchexport
def build_latest_schema(schema_index):
    """
    Build a schema, directly from the index. Also creates a saved checkpoint.
    """
    from couchexport.export import ExportConfiguration
    db = Database(settings.COUCH_DATABASE)
    previous_export = ExportSchema.last(schema_index)
    try:
        current_seq = int(db.info()["update_seq"])
    except ValueError:
        pass # we must be on bigcouch, so comparing seqs is useless
    else:
        if previous_export and not previous_export.is_bigcouch \
                           and int(previous_export.seq) > current_seq:
            # something weird happened (like the couch database changing)
            # better rebuild from scratch
            previous_export = None

    config = ExportConfiguration(db, schema_index,
                                 previous_export=previous_export)
    schema = config.get_latest_schema()
    if not schema:
        return None
    updated_checkpoint = config.create_new_checkpoint()
    return updated_checkpoint
コード例 #5
0
ファイル: test_schema.py プロジェクト: ansarbek/commcare-hq
    def testGetLast(self):
        indices = ["a string", ["a", "list"]]
        save_args = get_safe_write_kwargs()

        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            dt = datetime.utcnow()
            schema1 = ExportSchema(index=index, timestamp=dt)
            schema1.save(**save_args)
            self.assertEqual(schema1._id, ExportSchema.last(index)._id)
            schema2 = ExportSchema(index=index, timestamp=dt + timedelta(seconds=1))
            schema2.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
            schema3 = ExportSchema(index=index, timestamp=dt - timedelta(seconds=1))
            schema3.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
コード例 #6
0
ファイル: schema.py プロジェクト: kennknowles/couchexport
def build_latest_schema(schema_index):
    """
    Build a schema, directly from the index. Also creates a saved checkpoint.
    """
    from couchexport.export import ExportConfiguration
    db = Database(settings.COUCH_DATABASE)
    previous_export = ExportSchema.last(schema_index)
    try:
        current_seq = int(db.info()["update_seq"])
    except ValueError:
        pass  # we must be on bigcouch, so comparing seqs is useless
    else:
        if previous_export and not previous_export.is_bigcouch \
                           and int(previous_export.seq) > current_seq:
            # something weird happened (like the couch database changing)
            # better rebuild from scratch
            previous_export = None

    config = ExportConfiguration(db,
                                 schema_index,
                                 previous_export=previous_export)
    schema = config.get_latest_schema()
    if not schema:
        return None
    updated_checkpoint = config.create_new_checkpoint()
    return updated_checkpoint
コード例 #7
0
    def testGetLast(self):
        indices = ["a string", ["a", "list"]]
        save_args = get_safe_write_kwargs()

        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            dt = datetime.utcnow()
            schema1 = ExportSchema(index=index, timestamp=dt)
            schema1.save(**save_args)
            self.assertEqual(schema1._id, ExportSchema.last(index)._id)
            schema2 = ExportSchema(index=index, timestamp=dt + timedelta(seconds=1))
            schema2.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
            schema3 = ExportSchema(index=index, timestamp=dt - timedelta(seconds=1))
            schema3.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
コード例 #8
0
    def testGetLast(self):
        indices = ["a string", ["a", "list"]]
        save_args = get_safe_write_kwargs()

        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            # by design, if something has a timestamp it always wins out, even
            # if something has a higher seq

            dt = datetime.utcnow()
            schema1 = ExportSchema(seq="2", index=index, timestamp=dt)
            schema1.save(**save_args)
            self.assertEqual(schema1._id, ExportSchema.last(index)._id)
            schema2 = ExportSchema(seq="1", index=index, timestamp=dt + timedelta(seconds=1))
            schema2.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
            schema3 = ExportSchema(seq="3", index=index, timestamp=dt - timedelta(seconds=1))
            schema3.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
コード例 #9
0
ファイル: test_schema.py プロジェクト: kkrampa/commcare-hq
    def test_get_last(self):
        indices = ["a string", ["a", "list"]]
        save_args = get_safe_write_kwargs()

        for index in indices:
            self.addCleanup(
                lambda idx: [cp.delete() for cp in ExportSchema.get_all_checkpoints(idx)],
                index
            )

        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            dt = datetime.utcnow()
            schema1 = ExportSchema(index=index, timestamp=dt)
            schema1.save(**save_args)
            self.assert_docs_equal(schema1, ExportSchema.last(index))
            schema2 = ExportSchema(index=index, timestamp=dt + timedelta(seconds=1))
            schema2.save(**save_args)
            self.assert_docs_equal(schema2, ExportSchema.last(index))
            schema3 = ExportSchema(index=index, timestamp=dt - timedelta(seconds=1))
            schema3.save(**save_args)
            # still schema2 (which has a later date than schema3)
            self.assert_docs_equal(schema2, ExportSchema.last(index))
コード例 #10
0
ファイル: schema.py プロジェクト: ansarbek/commcare-hq
def build_latest_schema(schema_index):
    """
    Build a schema, directly from the index. Also creates a saved checkpoint.
    """
    from couchexport.export import ExportConfiguration
    db = Database(settings.COUCH_DATABASE)
    previous_export = ExportSchema.last(schema_index)
    config = ExportConfiguration(db, schema_index,
                                 previous_export=previous_export)
    schema = config.get_latest_schema()
    if not schema:
        return None
    updated_checkpoint = config.create_new_checkpoint()
    return updated_checkpoint
コード例 #11
0
ファイル: schema.py プロジェクト: xbryanc/commcare-hq
def build_latest_schema(schema_index):
    """
    Build a schema, directly from the index. Also creates a saved checkpoint.
    """
    from couchexport.export import ExportConfiguration
    db = Database(settings.COUCH_DATABASE)
    previous_export = ExportSchema.last(schema_index)
    config = ExportConfiguration(db,
                                 schema_index,
                                 previous_export=previous_export)
    schema = config.get_latest_schema()
    if not schema:
        return None
    updated_checkpoint = config.create_new_checkpoint()
    return updated_checkpoint
コード例 #12
0
ファイル: schema.py プロジェクト: wbnigeria/couchexport
def build_latest_schema(schema_index):
    """
    Build a schema, directly from the index. Also creates a saved checkpoint.
    """
    from couchexport.export import ExportConfiguration
    db = Database(settings.COUCH_DATABASE)
    current_seq = db.info()["update_seq"]
    previous_export = ExportSchema.last(schema_index)
    config = ExportConfiguration(get_db(), schema_index, 
                                 previous_export=previous_export)
    schema = get_schema_new(config)
    if not schema:
        return None
    updated_checkpoint = ExportSchema(seq=current_seq, schema=schema, 
                                      index=schema_index)
    updated_checkpoint.save()
    return updated_checkpoint
コード例 #13
0
 def last_checkpoint(self):
     return None if self.disable_checkpoints else ExportSchema.last(
         self.schema_index)
コード例 #14
0
ファイル: export.py プロジェクト: nnestle/commcare-hq
 def last_checkpoint(self):
     return None if self.disable_checkpoints else ExportSchema.last(self.schema_index)
コード例 #15
0
ファイル: export.py プロジェクト: wbnigeria/couchexport
 def last_checkpoint(self):
     return self.previous_export or ExportSchema.last(self.schema_index)