delete imported nodes that are not present in the old database
332153
def check_deleted_nodes(self):
        
        imported_nodes = Node.objects.filter(data__contains=['imported'])
        deleted_nodes = []

        for node in imported_nodes:
            if OldNode.objects.filter(pk=node.pk).count() == 0:
                user = node.user
                deleted_nodes.append(node)
                node.delete()
                # delete user if there are no other nodes assigned to her
                if user.node_set.count() == 0:
                    user.delete()

        if len(deleted_nodes) > 0:
            self.message('deleted %d imported nodes from local DB' % len(deleted_nodes))
        self.deleted_nodes = deleted_nodes
1217079
protected void objectsRemoved(DBIDs ids) {
    final Logging log = getLogger();
    StepProgress stepprog = log.isVerbose() ? new StepProgress(3) : null;

    // delete the materialized (old) kNNs
    log.beginStep(stepprog, 1, "New deletions ocurred, remove their materialized kNNs.");
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      storage.delete(iter);
    }

    // update the affected kNNs
    log.beginStep(stepprog, 2, "New deletions ocurred, update the affected kNNs.");
    ArrayDBIDs rkNN_ids = updateKNNsAfterDeletion(ids);

    // inform listener
    log.beginStep(stepprog, 3, "New deletions ocurred, inform listeners.");
    fireKNNsRemoved(ids, rkNN_ids);

    log.ensureCompleted(stepprog);
  }
26583
def allow_migrate(self, db, model):
        
        if db != 'old_nodeshot' or model._meta.app_label != 'oldimporter':
            return False
        return True
26122
def _clean_cleaned_data(self):
        
        reference_node_id = 0

        if '_ref_node_id' in self.cleaned_data:
            reference_node_id = self.cleaned_data['_ref_node_id']
            del self.cleaned_data['_ref_node_id']

        position_type = self.cleaned_data['_position']
        del self.cleaned_data['_position']

        return position_type, reference_node_id
1360626
public function restoreDatabase(): void
    {
        $currentDirectory = getcwd();
        $installer = $this->getInstallerService();
        $this->findDirectoryToRunScripts();
        $installer->setOutput(new NullOutput());
        $installer->importSchema();
        $installer->importData();
        chdir($currentDirectory);
    }
1230226
def clear_schema(self):
        """"""
        execute = self.cursor.execute
        execute('TRUNCATE TABLE gauged_data')
        execute('TRUNCATE TABLE gauged_keys')
        execute('TRUNCATE TABLE gauged_writer_history')
        execute('TRUNCATE TABLE gauged_cache')
        execute('TRUNCATE TABLE gauged_statistics')
        self.db.commit()
1156998
def purge_collection(keys):
    ""
    for key in keys:
        m = re.match(r'(.*) \((\d+)\)', key)
        name = m.group(1)
        node_id = m.group(2)
        value = render_value_for_node(node_id)
        print 'remove node with name:{0} and id:{1}'.format(name, node_id)

        delete_node(node_id=node_id)
        if isinstance(value, dict):
            purge_collection(value.keys())
1268618
function _handleSingleMutation(mutation) {
  var addedNodes = _toArray(mutation.addedNodes);
  var addedRefs = addedNodes.filter(_isRefNode);

  // assign added nodes
  addedRefs.map(_assignRef.bind(this));

  var removedNodes = _toArray(mutation.removedNodes);
  var removedRefs = removedNodes.filter(_isRefNode);

  // assign removed nodes
  removedRefs.map(_deleteRef.bind(this));
}
257027
def remove_unused_links(self, used):
        
        unused = []

        self._execute("SELECT * FROM {}".format(self.LINK_STATE_TABLE))
        for row in self.cursor:
            relpath, inode, mtime = row
            inode = self._from_sqlite(inode)
            path = os.path.join(self.root_dir, relpath)

            if path in used:
                continue

            if not os.path.exists(path):
                continue

            actual_inode = get_inode(path)
            actual_mtime, _ = get_mtime_and_size(path)

            if inode == actual_inode and mtime == actual_mtime:
                logger.debug("Removing '{}' as unused link.".format(path))
                remove(path)
                unused.append(relpath)

        for relpath in unused:
            cmd = 'DELETE FROM {} WHERE path = "{}"'
            self._execute(cmd.format(self.LINK_STATE_TABLE, relpath))
1141462
def pruneChanges(self, changeHorizon):
        

        if not changeHorizon:
            return None

        def thd(conn):
            changes_tbl = self.db.model.changes

            # First, get the list of changes to delete.  This could be written
            # as a subquery but then that subquery would be run for every
            # table, which is very inefficient; also, MySQL's subquery support
            # leaves much to be desired, and doesn't support this particular
            # form.
            q = sa.select([changes_tbl.c.changeid],
                          order_by=[sa.desc(changes_tbl.c.changeid)],
                          offset=changeHorizon)
            res = conn.execute(q)
            ids_to_delete = [r.changeid for r in res]

            # and delete from all relevant tables, in dependency order
            for table_name in ('scheduler_changes', 'change_files',
                               'change_properties', 'changes', 'change_users'):
                remaining = ids_to_delete[:]
                while remaining:
                    batch, remaining = remaining[:100], remaining[100:]
                    table = self.db.model.metadata.tables[table_name]
                    conn.execute(
                        table.delete(table.c.changeid.in_(batch)))
        yield self.db.pool.do(thd)
795677
function deleteFn(point) {
	if (point && typeof(point) === 'string') {
		const tree = point.split('.');
		let source = goblin.db;

		return tree.every((node, i) => {
			if (source[node] === undefined) {
				logger('DB_DELETE_INVALID_POINT', node);
				return false;
			}

			if (i === tree.length - 1) {
				let oldValue = source[node];

				if (Array.isArray(source)) {
					source.splice(node, 1);
					return true;
				}

				if (delete source[node]) {
					goblin.goblinDataEmitter.emit('change', {
						type: 'delete',
						value: undefined,
						oldValue: oldValue
					});

					return true;
				} else {
					return false;
				}
			}

			source = source[node];
			return true;
		});
	}

	logger('DB_DELETE_MISSING_POINT');
	return false;
}
816389
def remove():
    
    if exists(env.venv_path):
        run("rm -rf %s" % env.venv_path)
    if exists(env.proj_path):
        run("rm -rf %s" % env.proj_path)
    for template in get_templates().values():
        remote_path = template["remote_path"]
        if exists(remote_path):
            sudo("rm %s" % remote_path)
    if exists(env.repo_path):
        run("rm -rf %s" % env.repo_path)
    sudo("supervisorctl update")
    psql("DROP DATABASE IF EXISTS %s;" % env.proj_name)
    psql("DROP USER IF EXISTS %s;" % env.proj_name)
1192868
def purge(self, dbid):
        '''
        
        '''
        db_path = os.path.join(self.path, dbid)
        if os.path.exists(db_path):
            shutil.rmtree(db_path, ignore_errors=True)
            return True
        return False
579444
def _update_indexes_for_deleted_object(collection, obj):
    """"""
    for index in _db[collection].indexes.values():
        _remove_from_index(index, obj)
519778
protected void removeUnnecessaryOperations() {

        for (Class<? extends Entity> entityClass : deletedObjects.keySet()) {

            // Collect ids of deleted entities + remove duplicates
            Set<String> ids = new HashSet<String>();
            Iterator<Entity> entitiesToDeleteIterator = deletedObjects.get(entityClass).values().iterator();
            while (entitiesToDeleteIterator.hasNext()) {
                Entity entityToDelete = entitiesToDeleteIterator.next();
                if (!ids.contains(entityToDelete.getId())) {
                    ids.add(entityToDelete.getId());
                } else {
                    entitiesToDeleteIterator.remove(); // Removing duplicate deletes
                }
            }

            // Now we have the deleted ids, we can remove the inserted objects (as they cancel each other)
            for (String id : ids) {
                if (insertedObjects.containsKey(entityClass) && insertedObjects.get(entityClass).containsKey(id)) {
                    insertedObjects.get(entityClass).remove(id);
                    deletedObjects.get(entityClass).remove(id);
                }
            }
        }
    }
734857
def delete_node(node_id, purge_data,**kwargs):
    
    user_id = kwargs.get('user_id')
    try:
        node_i = db.DBSession.query(Node).filter(Node.id == node_id).one()
    except NoResultFound:
        raise ResourceNotFoundError("Node %s not found"%(node_id))

    group_items = db.DBSession.query(ResourceGroupItem).filter(
                                        ResourceGroupItem.node_id==node_id).all()
    for gi in group_items:
        db.DBSession.delete(gi)

    if purge_data == 'Y':
        _purge_datasets_unique_to_resource('NODE', node_id)

    log.info("Deleting node %s, id=%s", node_i.name, node_id)

    node_i.network.check_write_permission(user_id)
    db.DBSession.delete(node_i)
    db.DBSession.flush()
    return 'OK'
653683
def _clean(self):
        """"""
        found_ids = {}
        nodes = [self._nodes[_node.Root.ID]]
        while nodes:
            node = nodes.pop()
            found_ids[node.id] = None
            nodes = nodes + node.children

        for node_id in self._nodes:
            if node_id in found_ids:
                continue
            logger.error('Dangling node: %s', node_id)

        for node_id in found_ids:
            if node_id in self._nodes:
                continue
            logger.error('Unregistered node: %s', node_id)