merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

merchant-0006.sql (2581B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2024 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 merchant-0006.sql
     18 -- @brief add selected choice index to contract terms
     19 -- @author Christian Blättler
     20 
     21 -- Everything in one big transaction
     22 BEGIN;
     23 
     24 -- Check patch versioning is in place.
     25 SELECT _v.register_patch('merchant-0006', NULL, NULL);
     26 
     27 SET search_path TO merchant;
     28 
     29 ALTER TABLE merchant_inventory
     30   ALTER COLUMN image SET DATA TYPE TEXT;
     31 
     32 CREATE TABLE IF NOT EXISTS merchant_categories
     33   (category_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
     34   ,merchant_serial BIGINT NOT NULL
     35     REFERENCES merchant_instances (merchant_serial) ON DELETE CASCADE
     36   ,category_name TEXT NOT NULL UNIQUE
     37   ,category_name_i18n BYTEA NOT NULL
     38   );
     39 
     40 COMMENT ON TABLE merchant_categories
     41   IS 'product categories (with translations) to group products from inventory (primarily for the point-of-sale app)';
     42 COMMENT ON COLUMN merchant_categories.category_name
     43   IS 'name of the category';
     44 COMMENT ON COLUMN merchant_categories.category_name_i18n
     45   IS 'JSON with translations of the category name';
     46 
     47 CREATE TABLE merchant_product_categories
     48   (category_serial BIGINT NOT NULL
     49     REFERENCES merchant_categories (category_serial) ON DELETE CASCADE
     50   ,product_serial BIGINT NOT NULL
     51     REFERENCES merchant_inventory (product_serial) ON DELETE CASCADE);
     52 CREATE INDEX merchant_categories_by_category
     53   ON merchant_product_categories (category_serial);
     54 CREATE INDEX merchant_categories_by_product
     55   ON merchant_product_categories (product_serial);
     56 
     57 COMMENT ON TABLE merchant_product_categories
     58   IS 'N:M map from products to categories (a product can be in any number of categories, including zero)';
     59 COMMENT ON COLUMN merchant_product_categories.category_serial
     60   IS 'Reference to a category the product is part of';
     61 COMMENT ON COLUMN merchant_product_categories.product_serial
     62   IS 'Reference to a product which is in the given category';
     63 
     64 
     65 -- Complete transaction
     66 COMMIT;