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))
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))
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))
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
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
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))
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))
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
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
def doc_types(self): return set(doc_type_tuples_to_dict(mod.MIGRATIONS[self.slug].doc_types))
def doc_types(self): return set(doc_type_tuples_to_dict(mod.MIGRATIONS[self.slug].doc_types))