diff options
Diffstat (limited to 'src/stasis/stasis-0001.sql')
-rw-r--r-- | src/stasis/stasis-0001.sql | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/src/stasis/stasis-0001.sql b/src/stasis/stasis-0001.sql index e0ebfa6..fe08cdc 100644 --- a/src/stasis/stasis-0001.sql +++ b/src/stasis/stasis-0001.sql @@ -1,6 +1,6 @@ -- -- This file is part of Anastasis --- Copyright (C) 2020, 2021 Anastasis SARL SA +-- Copyright (C) 2020, 2021, 2022, 2023 Anastasis SARL SA -- -- ANASTASIS 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 @@ -20,30 +20,41 @@ BEGIN; -- Check patch versioning is in place. SELECT _v.register_patch('stasis-0001', NULL, NULL); +CREATE SCHEMA anastasis; +COMMENT ON SCHEMA anastasis IS 'anastasis backend data'; + +SET search_path TO anastasis; + + +CREATE TYPE taler_amount + AS + (val INT8 + ,frac INT4 + ); +COMMENT ON TYPE taler_amount + IS 'Stores an amount, fraction is in units of 1/100000000 of the base value'; + CREATE TABLE IF NOT EXISTS anastasis_truth_payment (truth_uuid BYTEA PRIMARY KEY CHECK(LENGTH(truth_uuid)=32), - amount_val INT8 NOT NULL, - amount_frac INT4 NOT NULL, + amount taler_amount NOT NULL, expiration INT8 NOT NULL); COMMENT ON TABLE anastasis_truth_payment IS 'Records about payments for truth uploads'; COMMENT ON COLUMN anastasis_truth_payment.truth_uuid IS 'Identifier of the truth'; -COMMENT ON COLUMN anastasis_truth_payment.amount_val +COMMENT ON COLUMN anastasis_truth_payment.amount IS 'Amount we were paid'; -COMMENT ON COLUMN anastasis_truth_payment.amount_frac - IS 'Amount we were paid fraction'; COMMENT ON COLUMN anastasis_truth_payment.expiration IS 'At which date will the truth payment expire'; CREATE TABLE IF NOT EXISTS anastasis_truth (truth_uuid BYTEA PRIMARY KEY CHECK(LENGTH(truth_uuid)=32), - key_share_data BYTEA CHECK(LENGTH(key_share_data)=80) NOT NULL, - method_name VARCHAR NOT NULL, + key_share_data BYTEA CHECK(LENGTH(key_share_data)=72) NOT NULL, + method_name TEXT NOT NULL, encrypted_truth BYTEA NOT NULL, - truth_mime VARCHAR NOT NULL, + truth_mime TEXT NOT NULL, expiration INT8 NOT NULL); COMMENT ON TABLE anastasis_truth IS 'Truth data is needed to authenticate clients during recovery'; @@ -73,11 +84,10 @@ COMMENT ON COLUMN anastasis_user.expiration_date CREATE TABLE IF NOT EXISTS anastasis_recdoc_payment - (payment_id BIGSERIAL PRIMARY KEY, + (payment_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, user_id BYTEA NOT NULL REFERENCES anastasis_user(user_id), post_counter INT4 NOT NULL DEFAULT 0 CHECK(post_counter >= 0), - amount_val INT8 NOT NULL, - amount_frac INT4 NOT NULL, + amount taler_amount NOT NULL, payment_identifier BYTEA NOT NULL CHECK(LENGTH(payment_identifier)=32), creation_date INT8 NOT NULL, paid BOOLEAN NOT NULL DEFAULT FALSE); @@ -89,10 +99,8 @@ COMMENT ON COLUMN anastasis_recdoc_payment.user_id IS 'Link to the corresponding user who paid'; COMMENT ON COLUMN anastasis_recdoc_payment.post_counter IS 'For how many posts does the user pay'; -COMMENT ON COLUMN anastasis_recdoc_payment.amount_val +COMMENT ON COLUMN anastasis_recdoc_payment.amount IS 'Amount we were paid'; -COMMENT ON COLUMN anastasis_recdoc_payment.amount_frac - IS 'Amount we were paid fraction'; COMMENT ON COLUMN anastasis_recdoc_payment.payment_identifier IS 'Payment identifier which the user has to provide'; COMMENT ON COLUMN anastasis_recdoc_payment.creation_date @@ -102,10 +110,9 @@ COMMENT ON COLUMN anastasis_recdoc_payment.paid CREATE TABLE IF NOT EXISTS anastasis_challenge_payment - (payment_id BIGSERIAL PRIMARY KEY, + (payment_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, truth_uuid BYTEA CHECK(LENGTH(truth_uuid)=32) NOT NULL, - amount_val INT8 NOT NULL, - amount_frac INT4 NOT NULL, + amount taler_amount NOT NULL, payment_identifier BYTEA NOT NULL CHECK(LENGTH(payment_identifier)=32), creation_date INT8 NOT NULL, counter INT4 NOT NULL DEFAULT 3, @@ -118,10 +125,8 @@ COMMENT ON COLUMN anastasis_challenge_payment.payment_id IS 'Serial number which identifies the payment'; COMMENT ON COLUMN anastasis_challenge_payment.truth_uuid IS 'Link to the corresponding challenge which is paid'; -COMMENT ON COLUMN anastasis_challenge_payment.amount_val +COMMENT ON COLUMN anastasis_challenge_payment.amount IS 'Amount we were paid'; -COMMENT ON COLUMN anastasis_challenge_payment.amount_frac - IS 'Amount we were paid fraction'; COMMENT ON COLUMN anastasis_challenge_payment.payment_identifier IS 'Payment identifier which the user has to provide'; COMMENT ON COLUMN anastasis_challenge_payment.counter @@ -140,6 +145,8 @@ CREATE TABLE IF NOT EXISTS anastasis_recoverydocument account_sig BYTEA NOT NULL CHECK(LENGTH(account_sig)=64), recovery_data_hash BYTEA NOT NULL CHECK(length(recovery_data_hash)=64), recovery_data BYTEA NOT NULL, + recovery_meta_data BYTEA NOT NULL, + creation_date INT8 NOT NULL, PRIMARY KEY (user_id, version)); COMMENT ON TABLE anastasis_recoverydocument IS 'Stores a recovery document which contains the policy and the encrypted core secret'; @@ -151,8 +158,12 @@ COMMENT ON COLUMN anastasis_recoverydocument.account_sig IS 'Signature of the recovery document'; COMMENT ON COLUMN anastasis_recoverydocument.recovery_data_hash IS 'Hash of the recovery document to prevent unnecessary uploads'; +COMMENT ON COLUMN anastasis_recoverydocument.creation_date + IS 'Creation date of the recovery document (when it was uploaded)'; COMMENT ON COLUMN anastasis_recoverydocument.recovery_data IS 'Contains the encrypted policy and core secret'; +COMMENT ON COLUMN anastasis_recoverydocument.recovery_meta_data + IS 'Contains an encrypted human-readable and sometimes user-generated description of the backup'; CREATE TABLE IF NOT EXISTS anastasis_challengecode @@ -194,11 +205,10 @@ COMMENT ON INDEX anastasis_challengecode_expiration_index CREATE TABLE IF NOT EXISTS anastasis_auth_iban_in - (auth_in_serial_id BIGSERIAL UNIQUE + (auth_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE ,wire_reference INT8 NOT NULL PRIMARY KEY ,wire_subject TEXT NOT NULL - ,credit_val INT8 NOT NULL - ,credit_frac INT4 NOT NULL + ,credit taler_amount NOT NULL ,debit_account_details TEXT NOT NULL ,credit_account_details TEXT NOT NULL ,execution_date INT8 NOT NULL @@ -209,6 +219,8 @@ COMMENT ON COLUMN anastasis_auth_iban_in.wire_reference IS 'Unique number identifying the wire transfer in LibEuFin/Nexus'; COMMENT ON COLUMN anastasis_auth_iban_in.wire_subject IS 'For authentication, this contains the code, but also additional text'; +COMMENT ON COLUMN anastasis_auth_iban_in.credit + IS 'Amount we were credited'; COMMENT ON COLUMN anastasis_auth_iban_in.execution_date IS 'Used both for (theoretical) garbage collection and to see if the transfer happened on time'; COMMENT ON COLUMN anastasis_auth_iban_in.credit_account_details |