create_tables.c (2788B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file src/auditordb/create_tables.c 18 * @brief Implementation of the create_tables function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_pq_lib.h" 22 #include "auditor-database/create_tables.h" 23 #include "pg_helper.h" 24 25 26 enum GNUNET_GenericReturnValue 27 TALER_AUDITORDB_create_tables ( 28 const struct GNUNET_CONFIGURATION_Handle *cfg, 29 bool support_partitions, 30 uint32_t num_partitions) 31 { 32 enum GNUNET_GenericReturnValue ret = GNUNET_OK; 33 struct GNUNET_PQ_Context *conn; 34 struct GNUNET_PQ_QueryParam params[] = { 35 support_partitions 36 ? GNUNET_PQ_query_param_uint32 (&num_partitions) 37 : GNUNET_PQ_query_param_null (), 38 GNUNET_PQ_query_param_end 39 }; 40 struct GNUNET_PQ_PreparedStatement ps[] = { 41 GNUNET_PQ_make_prepare ("create_tables", 42 "SELECT" 43 " auditor.do_create_tables" 44 " ($1);"), 45 GNUNET_PQ_PREPARED_STATEMENT_END 46 }; 47 struct GNUNET_PQ_ExecuteStatement es[] = { 48 GNUNET_PQ_make_try_execute ("SET search_path TO auditor;"), 49 GNUNET_PQ_EXECUTE_STATEMENT_END 50 }; 51 52 conn = GNUNET_PQ_connect_with_cfg (cfg, 53 "auditordb-postgres", 54 "auditor-", 55 es, 56 ps); 57 if (NULL == conn) 58 { 59 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 60 "Failed to connect to database\n"); 61 return GNUNET_SYSERR; 62 } 63 if (0 > 64 GNUNET_PQ_eval_prepared_non_select (conn, 65 "create_tables", 66 params)) 67 { 68 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 69 "Failed to run 'create_tables' prepared statement\n"); 70 ret = GNUNET_SYSERR; 71 } 72 if (GNUNET_OK == ret) 73 { 74 ret = GNUNET_PQ_exec_sql (conn, 75 "procedures"); 76 if (GNUNET_OK != ret) 77 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 78 "Failed to load stored procedures\n"); 79 } 80 GNUNET_PQ_disconnect (conn); 81 return ret; 82 }