sync-0001.sql (2012B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (C) 2021, 2023 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 -- Everything in one big transaction 18 BEGIN; 19 20 -- Check patch versioning is in place. 21 SELECT _v.register_patch('sync-0001', NULL, NULL); 22 23 CREATE SCHEMA sync; 24 COMMENT ON SCHEMA sync IS 'sync data'; 25 26 SET search_path TO sync; 27 28 CREATE TYPE taler_amount 29 AS 30 (val INT8 31 ,frac INT4 32 ); 33 COMMENT ON TYPE taler_amount 34 IS 'Stores an amount, fraction is in units of 1/100000000 of the base value'; 35 36 CREATE TABLE IF NOT EXISTS accounts 37 (account_pub BYTEA PRIMARY KEY CHECK (length(account_pub)=32) 38 ,expiration_date INT8 NOT NULL); 39 40 CREATE INDEX IF NOT EXISTS accounts_expire ON 41 accounts (expiration_date); 42 43 44 CREATE TABLE IF NOT EXISTS payments 45 (account_pub BYTEA CHECK (length(account_pub)=32) 46 ,order_id TEXT PRIMARY KEY 47 ,token BYTEA CHECK (length(token)=16) 48 ,timestamp INT8 NOT NULL 49 ,amount taler_amount NOT NULL 50 ,paid BOOLEAN NOT NULL DEFAULT FALSE); 51 52 CREATE INDEX IF NOT EXISTS payments_timestamp ON 53 payments (paid,timestamp); 54 55 56 CREATE TABLE IF NOT EXISTS backups 57 (account_pub BYTEA PRIMARY KEY REFERENCES accounts (account_pub) ON DELETE CASCADE 58 ,account_sig BYTEA NOT NULL CHECK (length(account_sig)=64) 59 ,prev_hash BYTEA NOT NULL CHECK (length(prev_hash)=64) 60 ,backup_hash BYTEA NOT NULL CHECK (length(backup_hash)=64) 61 ,data BYTEA NOT NULL); 62 63 64 -- Complete transaction 65 COMMIT;