Esempio n. 1
0
    def forwards(apps, schema_editor):
        if settings.UNIT_TESTING:
            return

        try:
            get_blob_db()
        except Exception:
            raise MigrationError(
                "Cannot get blob db:\n{error}{message}".format(
                    error=traceback.format_exc(),
                    message=BLOB_DB_NOT_CONFIGURED,
                ))

        try:
            BlobMigrationState.objects.get(slug=slug)
            return  # already migrated
        except BlobMigrationState.DoesNotExist:
            pass

        migrator = MIGRATIONS[slug]
        total = 0
        for doc_type, model_class in doc_type_tuples_to_dict(migrator.doc_types).items():
            total += get_doc_count_by_type(model_class.get_db(), doc_type)
        if total > 500:
            message = MIGRATION_INSTRUCTIONS.format(slug=slug, total=total)
            raise MigrationNotComplete(message)

        # just do the migration if the number of documents is small
        migrated, skipped = migrator.migrate()
        if skipped:
            raise MigrationNotComplete(DOCS_SKIPPED_WARNING.format(skipped))
Esempio n. 2
0
    def forwards(apps, schema_editor):
        if settings.UNIT_TESTING:
            return

        try:
            get_blob_db()
        except Exception:
            raise MigrationError(
                "Cannot get blob db:\n{error}{message}".format(
                    error=traceback.format_exc(),
                    message=BLOB_DB_NOT_CONFIGURED,
                ))

        try:
            BlobMigrationState.objects.get(slug=slug)
            return  # already migrated
        except BlobMigrationState.DoesNotExist:
            pass

        migrator = MIGRATIONS[slug]
        total = 0
        for doc_type, model_class in doc_type_tuples_to_dict(
                migrator.doc_types).items():
            total += get_doc_count_by_type(model_class.get_db(), doc_type)
        if total > 500:
            message = MIGRATION_INSTRUCTIONS.format(slug=slug, total=total)
            raise MigrationNotComplete(message)

        # just do the migration if the number of documents is small
        migrated, skipped = migrator.migrate()
        if skipped:
            raise MigrationNotComplete(DOCS_SKIPPED_WARNING.format(skipped))
Esempio n. 3
0
    def __init__(self, slug, doc_types, doc_migrator_class):
        self.slug = slug
        self.doc_migrator_class = doc_migrator_class
        self.doc_types = doc_types

        sorted_types = sorted(doc_type_tuples_to_dict(self.doc_types))
        self.iteration_key = "{}-blob-migration/{}".format(
            self.slug, " ".join(sorted_types))
Esempio n. 4
0
    def setUp(self):
        super(BaseMigrationTest, self).setUp()
        self.discard_migration_state(self.slug)
        self._old_flags = {}
        self.docs_to_delete = []

        for model in doc_type_tuples_to_dict(mod.MIGRATIONS[self.slug].doc_types).values():
            self._old_flags[model] = model.migrating_blobs_from_couch
            model.migrating_blobs_from_couch = True
Esempio n. 5
0
    def setUp(self):
        super(BaseMigrationTest, self).setUp()
        self.discard_migration_state(self.slug)
        self._old_flags = {}
        self.docs_to_delete = []

        for model in doc_type_tuples_to_dict(mod.MIGRATIONS[self.slug].doc_types).values():
            self._old_flags[model] = model._migrating_blobs_from_couch
            model._migrating_blobs_from_couch = True
Esempio n. 6
0
    def __init__(self, slug, doc_types, doc_migrator_class):
        self.slug = slug
        self.doc_migrator_class = doc_migrator_class
        self.doc_types = doc_types
        first_type = doc_types[0]
        self.couchdb = (first_type[0] if isinstance(first_type, tuple) else first_type).get_db()

        sorted_types = sorted(doc_type_tuples_to_dict(self.doc_types))
        self.iteration_key = "{}-blob-migration/{}".format(self.slug, " ".join(sorted_types))
Esempio n. 7
0
    def __init__(self, slug, doc_types, doc_migrator_class):
        self.slug = slug
        self.doc_migrator_class = doc_migrator_class
        self.doc_types = doc_types
        first_type = doc_types[0]
        self.couchdb = (first_type[0] if isinstance(first_type, tuple) else first_type).get_db()

        sorted_types = sorted(doc_type_tuples_to_dict(self.doc_types))
        self.iteration_key = "{}-blob-migration/{}".format(self.slug, " ".join(sorted_types))
Esempio n. 8
0
    def __init__(self, slug, doc_types, doc_migrator_class):
        self.slug = slug
        self.doc_migrator_class = doc_migrator_class
        self.doc_types = doc_types
        first_type = doc_types[0]
        first_type = (first_type[0] if isinstance(first_type, tuple) else first_type)
        self.couchdb = first_type.get_db() if hasattr(first_type, "get_db") else None

        doc_types_map = doc_type_tuples_to_dict(self.doc_types)
        sorted_types = sorted(doc_types_map)
        self.iteration_key = "{}-blob-migration/{}".format(self.slug, " ".join(sorted_types))

        def get_type_code(doc):
            if doc_types_map:
                return doc_types_map[doc["doc_type"]]._blobdb_type_code
            return None
        self.get_type_code = get_type_code
Esempio n. 9
0
    def __init__(self, slug, doc_types, doc_migrator_class):
        self.slug = slug
        self.doc_migrator_class = doc_migrator_class
        self.doc_types = doc_types
        first_type = doc_types[0]
        first_type = (first_type[0] if isinstance(first_type, tuple) else first_type)
        self.couchdb = first_type.get_db() if hasattr(first_type, "get_db") else None

        doc_types_map = doc_type_tuples_to_dict(self.doc_types)
        sorted_types = sorted(doc_types_map)
        self.iteration_key = "{}-blob-migration/{}".format(self.slug, " ".join(sorted_types))

        def get_type_code(doc):
            if doc_types_map:
                return doc_types_map[doc["doc_type"]]._blobdb_type_code
            return None
        self.get_type_code = get_type_code
Esempio n. 10
0
 def doc_types(self):
     return set(doc_type_tuples_to_dict(mod.MIGRATIONS[self.slug].doc_types))
Esempio n. 11
0
 def doc_types(self):
     return set(doc_type_tuples_to_dict(mod.MIGRATIONS[self.slug].doc_types))