22 lines
838 B
Go
22 lines
838 B
Go
package store
|
|
|
|
import "context"
|
|
|
|
// A single transaction prevents filing and routing changes from partially
|
|
// succeeding, and treats saving an unchanged policy as a successful operation.
|
|
func (s *Store) UpdateDomainPolicy(ctx context.Context, id uint64, mode, target, status, number, note string) error {
|
|
tx, err := s.db.BeginTx(ctx, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer tx.Rollback()
|
|
var found uint64
|
|
if err = tx.QueryRowContext(ctx, `SELECT id FROM domains WHERE id=? AND kind='custom' FOR UPDATE`, id).Scan(&found); err != nil {
|
|
return ErrNotFound
|
|
}
|
|
if _, err = tx.ExecContext(ctx, `UPDATE domains SET resolution_mode=?,cname_target=NULLIF(?,''),filing_status=?,filing_number=NULLIF(?,''),filing_note=NULLIF(?,'') WHERE id=?`, mode, target, status, number, note, id); err != nil {
|
|
return err
|
|
}
|
|
return tx.Commit()
|
|
}
|