/*
  This file is part of Anastasis
  Copyright (C) 2020, 2021, 2022, 2026 Anastasis SARL

  Anastasis is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file stasis/do_gc.c
 * @brief garbage collection for the Anastasis database
 * @author Christian Grothoff
 */
#include "platform.h"
#include "anastasis-db_pg.h"
#include "anastasis/anastasis-database/do_gc.h"
#include "anastasis/anastasis-database/preflight.h"


enum GNUNET_DB_QueryStatus
ANASTASIS_DB_do_gc (struct GNUNET_TIME_Absolute expire_backups,
                    struct GNUNET_TIME_Absolute expire_pending_payments)
{
  struct GNUNET_PQ_QueryParam params[] = {
    GNUNET_PQ_query_param_absolute_time (&expire_backups),
    GNUNET_PQ_query_param_absolute_time (&expire_pending_payments),
    GNUNET_PQ_query_param_end
  };

  GNUNET_break (GNUNET_OK ==
                ANASTASIS_DB_preflight ());
  /* Every delete lives in the stored procedure: the rows referencing
     anastasis_user have to go before the account rows themselves, and doing
     that in one statement makes the whole collection atomic. */
  PREPARE ("do_gc",
           "SELECT anastasis_do_gc ($1, $2);");
  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                             "do_gc",
                                             params);
}


/* end of do_gc.c */
