def handle(self, *args, **options): if len(args) != 1: raise CommandError('Usage: manage.py migrate_rev2_data <old_db>') db = get_db() source_db = args[0] # the source db needs to have the migration views built so just force-sync the # design doc print "prepping source database %s" % source_db source = db.server.get_or_create_db(source_db) path_to_migration = os.path.join(settings.BHOMA_ROOT_DIR, "apps", "migration") loader = FileSystemDocLoader(path_to_migration, "_design", design_name="migration") loader.sync(source) print "migrating rev1 data to from %s to %s" % (source_db, db.dbname) replicate(db.server, source_db, db.dbname, filter="migration/migrates_rev_2") print "migration complete"
def sync(self, app, verbosity=2): """ used to sync views of all applications and eventually create database """ app_name = app.__name__.rsplit('.', 1)[0] app_label = app_name.split('.')[-1] if app_label in self._databases: if verbosity >=1: print "sync `%s` in CouchDB" % app_name db = self._databases[app_label] try: db.server.create_db(db.dbname) except: pass app_path = os.path.abspath(os.path.join(sys.modules[app.__name__].__file__, "..")) loader = FileSystemDocLoader(app_path, "_design", design_name=app_label) loader.sync(db)
def setUp(self): server = get_db().server self.databases = [TEST_CLINIC_1, TEST_CLINIC_2, TEST_NATIONAL] # cleanup for database in self.databases: try: delete(server, database) except Exception, e: pass # create databases self.clinic_1_db = server.get_or_create_db(TEST_CLINIC_1) self.clinic_2_db = server.get_or_create_db(TEST_CLINIC_2) self.national_db = server.get_or_create_db(TEST_NATIONAL) # load design docs design_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "patient", "models") loader = FileSystemDocLoader(design_path, "_design", design_name="patient") for database in [self.clinic_1_db, self.clinic_2_db, self.national_db]: loader.sync(database, verbose=True) self.server = server
def sync(self, app, verbosity=2): """ used to sync views of all applications and eventually create database. """ app_name = app.__name__.rsplit('.', 1)[0] app_label = app_name.split('.')[-1] if app_label in self._databases: if verbosity >=1: print "sync `%s` in CouchDB" % app_name db = self._databases[app_label] try: db.server.create_db(db.dbname) except: pass app_path = os.path.abspath(os.path.join(sys.modules[app.__name__].__file__, "..")) design_path = "%s/%s" % (app_path, "_design") if not os.path.isdir(design_path): if settings.DEBUG: print >>sys.stderr, "%s don't exists, no ddoc synchronized" % design_path return loader = FileSystemDocLoader(app_path, "_design", design_name=app_label) loader.sync(db)