exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

exchange-0005.sql (2742B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2025 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 BEGIN;
     18 
     19 SELECT _v.register_patch('exchange-0005', NULL, NULL);
     20 
     21 SET search_path TO exchange;
     22 
     23 -- convert all JSON-valued fields from TEXT to JSONB
     24 
     25 CREATE FUNCTION alter_table_wire_accounts5()
     26 RETURNS void
     27 LANGUAGE plpgsql
     28 AS $$
     29 BEGIN
     30   ALTER TABLE wire_accounts
     31     ALTER COLUMN debit_restrictions
     32       TYPE JSONB
     33       USING debit_restrictions::JSONB,
     34     ALTER COLUMN credit_restrictions
     35       TYPE JSONB
     36       USING credit_restrictions::JSONB;
     37 END
     38 $$;
     39 
     40 
     41 CREATE FUNCTION alter_table_legitimization_outcomes5()
     42 RETURNS void
     43 LANGUAGE plpgsql
     44 AS $$
     45 BEGIN
     46   ALTER TABLE legitimization_outcomes
     47     ALTER COLUMN jproperties
     48       TYPE JSONB
     49       USING jproperties::JSONB,
     50     ALTER COLUMN jnew_rules
     51       TYPE JSONB
     52       USING jnew_rules::JSONB;
     53 END
     54 $$;
     55 
     56 
     57 CREATE FUNCTION alter_table_legitimization_measures5()
     58 RETURNS void
     59 LANGUAGE plpgsql
     60 AS $$
     61 BEGIN
     62   ALTER TABLE legitimization_measures
     63     ALTER COLUMN jmeasures
     64       TYPE JSONB
     65       USING jmeasures::JSONB;
     66 END
     67 $$;
     68 
     69 
     70 CREATE FUNCTION alter_table_policy_fulfillments5()
     71 RETURNS void
     72 LANGUAGE plpgsql
     73 AS $$
     74 BEGIN
     75   ALTER TABLE policy_fulfillments
     76     ALTER COLUMN fulfillment_proof
     77       TYPE JSONB
     78       USING fulfillment_proof::JSONB;
     79 END
     80 $$;
     81 
     82 
     83 CREATE FUNCTION alter_table_kyc_targets5()
     84 RETURNS void
     85 LANGUAGE plpgsql
     86 AS $$
     87 DECLARE
     88   table_name TEXT DEFAULT 'kyc_targets';
     89 BEGIN
     90   EXECUTE FORMAT (
     91     'ALTER TABLE ' || table_name ||
     92     ' ADD COLUMN  open_time INT8 DEFAULT(NULL)'
     93     ',ADD COLUMN close_time INT8 DEFAULT(NULL);'
     94   );
     95 END
     96 $$;
     97 
     98 
     99 INSERT INTO exchange_tables
    100     (name
    101     ,version
    102     ,action
    103     ,partitioned
    104     ,by_range)
    105   VALUES
    106     ('wire_accounts5'
    107     ,'exchange-0005'
    108     ,'alter'
    109     ,TRUE
    110     ,FALSE),
    111     ('legitimization_outcomes5'
    112     ,'exchange-0005'
    113     ,'alter'
    114     ,TRUE
    115     ,FALSE),
    116     ('legitimization_measures5'
    117     ,'exchange-0005'
    118     ,'alter'
    119     ,TRUE
    120     ,FALSE),
    121     ('policy_fulfillments5'
    122     ,'exchange-0005'
    123     ,'alter'
    124     ,TRUE
    125     ,FALSE),
    126     ('kyc_targets5'
    127     ,'exchange-0005'
    128     ,'alter'
    129     ,TRUE
    130     ,FALSE);
    131 
    132 
    133 COMMIT;