out_addresses <- function(path_addresses_db, path_out_addresses) {
  if (is.null(.globals$con_address)) {
    withr::defer({
      DBI::dbDisconnect(.globals$con_address)
      .globals$con_address <- NULL
    })
  }

  addresses <-
    prep_open_address_db(path_addresses_db) |>
    # keep only the addresses that resolved, others aren't useful in output
    dplyr::filter(match_indicator == "Match") |>
    # id column is an artifact of the lookup, the key is "address"
    dplyr::select(-id) |>
    dplyr::rename(
      address_lookup = address,
      address_resolved = matched_address
    ) |>
    dplyr::relocate(address_resolved, .after = address_lookup) |>
    dplyr::collect() |>
    dplyr::mutate(dplyr::across(c(dplyr::starts_with("match_"), tiger_side), factor))

  fs::dir_create(fs::path_dir(path_out_addresses))
  arrow::write_parquet(addresses, path_out_addresses, version = "2.6")

  path_out_addresses
}
