package registry // DeleteIfUnchanged deletes listed.Host's route only while the stored row // still has the identity the caller listed it with: its kind, account and // app (the owner), whether a record provisioned it, its import gate and // seed column, and its creation time. It reports whether a row was // deleted. // // It is for a pass that decides from a route list read earlier and // deletes by host. Between the list and the delete, another writer can // put a different row at the host: an import's rollback restoring the // original route, owned by someone else, is the case it was written for. // A plain Delete would remove that row, and the operator grants it // carries. Here the check and the delete are one statement, so a row that // changed identity is never removed on the strength of the old one. func (r *Registry) DeleteIfUnchanged(listed Route) (bool, error) { if r.remote != nil { return false, errRemoteMethod } res, err := r.sql.Exec(`DELETE FROM routes WHERE host = ? AND kind = ? AND account = ? AND app = ? AND provisioned = ? AND import_gate = ? AND seed_source = ? AND created_at = ?`, listed.Host, listed.Kind, listed.Account, listed.App, b2iDB(listed.Provisioned), listed.ImportGate, listed.SeedSource, listed.CreatedAt) if err != nil { return false, err } n, err := res.RowsAffected() return n > 0, err }