--
-- This file is part of TALER
-- Copyright (C) 2026 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
-- Foundation; either version 3, or (at your option) any later version.
--
-- TALER 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 General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
--

BEGIN;

SELECT _v.register_patch('exchange-0007', NULL, NULL);

SET search_path TO exchange;


-- 0004-refresh.sql was incorrectly added to exchange-0004 post-release,
-- so we need to do the migration again, in case it was skipped
CREATE FUNCTION alter_table_refresh7()
RETURNS VOID
LANGUAGE plpgsql
AS $$
BEGIN
  ALTER TABLE refresh
    ADD COLUMN IF NOT EXISTS revealed BOOLEAN NOT NULL DEFAULT(FALSE),
    ADD COLUMN IF NOT EXISTS transfer_pubs BYTEA[];
  COMMENT ON COLUMN refresh.revealed
    IS 'TRUE if the client has successfully revealed the secrets in the cut-and-choose step.';
  COMMENT ON COLUMN refresh.transfer_pubs
    IS 'The selected batch of transfer public keys, at noreveal_index';
END $$;


INSERT INTO exchange_tables
    (name
    ,version
    ,action
    ,partitioned
    ,by_range)
  VALUES
    ('refresh7'
    ,'exchange-0007'
    ,'alter'
    ,TRUE
    ,FALSE);

COMMIT;
