Ejemplo n.º 1
0
 def handle(self, *args, **options):
     should_proceed = are_you_sure(WARNING) if options["interactive"] else True
     if not should_proceed:
         print "Ok, aborting"
         sys.exit()
         
     db = get_db()
     for doc in get_design_docs(db):
         logging.debug("compacting views for app: %s" % doc.name)
         print("compacting views for app: %s" % doc.name)
         db.compact(doc.name)
    def handle(self, **options):
        # build a data structure indexing databases to relevant design docs
        db_label_map = defaultdict(lambda: set())

        # pull design docs from preindex plugins
        plugins = get_preindex_plugins()
        for plugin in plugins:
            for design in plugin.get_designs():
                if design.design_path:
                    db_label_map[design.db.uri].add(design.app_label)

        designs_to_delete = {}
        for db_uri in db_label_map:
            db = Database(db_uri)
            expected_designs = db_label_map[db_uri]
            design_docs = get_design_docs(db)
            found_designs = set(dd.name for dd in design_docs)
            to_delete = found_designs - expected_designs
            if to_delete:
                designs_to_delete[db] = [
                    ddoc._doc for ddoc in design_docs if ddoc.name in to_delete
                ]
                print('\ndeleting from {}:\n---------------------'.format(
                    db.dbname))
                print('\n'.join(sorted(to_delete)))

        if designs_to_delete:
            if options['noinput'] or input('\n'.join([
                    '\n\nReally delete all the above design docs?',
                    'If any of these views are actually live, bad things will happen. '
                    '(Type "delete designs" to continue):',
                    '',
            ])).lower() == 'delete designs':
                for db, design_docs in designs_to_delete.items():
                    for design_doc in design_docs:
                        # If we don't delete conflicts, then they take the place of the
                        # document when it's deleted. (That's how couch works.)
                        # This results in a huge reindex for an old conflicted version
                        # of a design doc we don't even want anymore.
                        delete_conflicts(db, design_doc['_id'])
                    db.delete_docs(design_docs)
            else:
                print('aborted!')
        else:
            print('database already completely pruned!')
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        # build a data structure indexing databases to relevant design docs
        db_label_map = defaultdict(lambda: set())

        # pull design docs from normal couchbkit apps
        app_infos = [get_app_sync_info(app) for app in get_apps()]
        for info in app_infos:
            for design in info.designs:
                if design.design_path:
                    db_label_map[design.db.uri].add(design.app_label)

        # pull design docs from preindex plugins
        plugins = get_preindex_plugins()
        for plugin in plugins:
            for design in plugin.get_designs():
                if design.design_path:
                    db_label_map[design.db.uri].add(design.app_label)

        designs_to_delete = {}
        for db_uri in db_label_map:
            db = Database(db_uri)
            expected_designs = db_label_map[db_uri]
            design_docs = get_design_docs(db)
            found_designs = set(dd.name for dd in design_docs)
            to_delete = found_designs - expected_designs
            if to_delete:
                designs_to_delete[db] = [ddoc._doc for ddoc in design_docs if ddoc.name in to_delete]
                print '\ndeleting from {}:\n---------------------'.format(db.dbname)
                print '\n'.join(sorted(to_delete))

        if designs_to_delete:
            if options['noinput'] or raw_input('\n'.join([
                    '\n\nReally delete all the above design docs?',
                    'If any of these views are actually live, bad things will happen. '
                    '(Type "delete designs" to continue):',
                    '',
            ])).lower() == 'delete designs':
                for db, design_docs in designs_to_delete.items():
                    db.delete_docs(design_docs)
            else:
                print 'aborted!'
        else:
            print 'database already completely pruned!'
Ejemplo n.º 4
0
    def handle(self, *args, **options):
        # build a data structure indexing databases to relevant design docs
        db_label_map = defaultdict(lambda: set())

        # pull design docs from preindex plugins
        plugins = get_preindex_plugins()
        for plugin in plugins:
            for design in plugin.get_designs():
                if design.design_path:
                    db_label_map[design.db.uri].add(design.app_label)

        designs_to_delete = {}
        for db_uri in db_label_map:
            db = Database(db_uri)
            expected_designs = db_label_map[db_uri]
            design_docs = get_design_docs(db)
            found_designs = set(dd.name for dd in design_docs)
            to_delete = found_designs - expected_designs
            if to_delete:
                designs_to_delete[db] = [ddoc._doc for ddoc in design_docs if ddoc.name in to_delete]
                print '\ndeleting from {}:\n---------------------'.format(db.dbname)
                print '\n'.join(sorted(to_delete))

        if designs_to_delete:
            if options['noinput'] or raw_input('\n'.join([
                    '\n\nReally delete all the above design docs?',
                    'If any of these views are actually live, bad things will happen. '
                    '(Type "delete designs" to continue):',
                    '',
            ])).lower() == 'delete designs':
                for db, design_docs in designs_to_delete.items():
                    for design_doc in design_docs:
                        # If we don't delete conflicts, then they take the place of the
                        # document when it's deleted. (That's how couch works.)
                        # This results in a huge reindex for an old conflicted version
                        # of a design doc we don't even want anymore.
                        delete_conflicts(db, design_doc['_id'])
                    db.delete_docs(design_docs)
            else:
                print 'aborted!'
        else:
            print 'database already completely pruned!'