Line data Source code
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 7 : TALER_AUDITORDB_create_tables (
28 : const struct GNUNET_CONFIGURATION_Handle *cfg,
29 : bool support_partitions,
30 : uint32_t num_partitions)
31 : {
32 7 : enum GNUNET_GenericReturnValue ret = GNUNET_OK;
33 : struct GNUNET_PQ_Context *conn;
34 7 : struct GNUNET_PQ_QueryParam params[] = {
35 : support_partitions
36 0 : ? GNUNET_PQ_query_param_uint32 (&num_partitions)
37 7 : : GNUNET_PQ_query_param_null (),
38 : GNUNET_PQ_query_param_end
39 : };
40 7 : struct GNUNET_PQ_PreparedStatement ps[] = {
41 7 : GNUNET_PQ_make_prepare ("create_tables",
42 : "SELECT"
43 : " auditor.do_create_tables"
44 : " ($1);"),
45 : GNUNET_PQ_PREPARED_STATEMENT_END
46 : };
47 7 : struct GNUNET_PQ_ExecuteStatement es[] = {
48 7 : GNUNET_PQ_make_try_execute ("SET search_path TO auditor;"),
49 : GNUNET_PQ_EXECUTE_STATEMENT_END
50 : };
51 :
52 7 : conn = GNUNET_PQ_connect_with_cfg (cfg,
53 : "auditordb-postgres",
54 : "auditor-",
55 : es,
56 : ps);
57 7 : if (NULL == conn)
58 : {
59 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
60 : "Failed to connect to database\n");
61 0 : return GNUNET_SYSERR;
62 : }
63 7 : if (0 >
64 7 : GNUNET_PQ_eval_prepared_non_select (conn,
65 : "create_tables",
66 : params))
67 : {
68 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
69 : "Failed to run 'create_tables' prepared statement\n");
70 0 : ret = GNUNET_SYSERR;
71 : }
72 7 : if (GNUNET_OK == ret)
73 : {
74 7 : ret = GNUNET_PQ_exec_sql (conn,
75 : "procedures");
76 7 : if (GNUNET_OK != ret)
77 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
78 : "Failed to load stored procedures\n");
79 : }
80 7 : GNUNET_PQ_disconnect (conn);
81 7 : return ret;
82 : }
|