Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / sql / Pg-upgrade2 / shopimages.sql
1 -- @tag:shopimages
2 -- @description: Tabelle für Shopbilder und zusätzliche Konfiguration und valid_type für Filemanagement
3 -- @depends: release_3_5_0 files shop_parts
4 -- @ignore: 0
5
6 CREATE TABLE shop_images(
7   id                      SERIAL PRIMARY KEY,
8   file_id                 INTEGER REFERENCES files(id) ON DELETE CASCADE,
9   position                INTEGER,
10   thumbnail_content       BYTEA,
11   thumbnail_width         INTEGER,
12   thumbnail_height        INTEGER,
13   thumbnail_content_type  TEXT,
14   itime                   TIMESTAMP DEFAULT now(),
15   mtime                   TIMESTAMP
16 );
17
18 CREATE TRIGGER mtime_shop_images BEFORE UPDATE ON shop_images FOR EACH ROW EXECUTE PROCEDURE set_mtime();
19
20 ALTER TABLE defaults ADD COLUMN doc_storage_for_shopimages      text default 'Filesystem';
21
22 ALTER TABLE files
23   DROP CONSTRAINT valid_type;
24 ALTER TABLE files
25   ADD  CONSTRAINT valid_type CHECK (
26              (object_type = 'credit_note'     ) OR (object_type = 'invoice'                 ) OR (object_type = 'sales_order'       )
27           OR (object_type = 'sales_quotation' ) OR (object_type = 'sales_delivery_order'    ) OR (object_type = 'request_quotation' )
28           OR (object_type = 'purchase_order'  ) OR (object_type = 'purchase_delivery_order' ) OR (object_type = 'purchase_invoice'  )
29           OR (object_type = 'vendor'          ) OR (object_type = 'customer'                ) OR (object_type = 'part'              )
30           OR (object_type = 'gl_transaction'  ) OR (object_type = 'dunning'                 ) OR (object_type = 'dunning1'          )
31           OR (object_type = 'dunning2'        ) OR (object_type = 'dunning3'                ) OR (object_type = 'draft'             )
32           OR (object_type = 'statement'       ) OR (object_type = 'shop_image'              )
33   );