@flowselections/floriday-klanten-module 1.0.58 → 1.0.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/components/klanten/FloridayAutoPromoteCard.d.ts +1 -1
- package/dist-lib/components/klanten/FloridayAutoPromoteCard.d.ts.map +1 -1
- package/dist-lib/components/klanten/FloridayAutoPromoteCard.js +11 -31
- package/dist-lib/index.js +1 -1
- package/dist-lib/integrations/supabase/types.d.ts +108 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/accounting/twinfield/sandbox-guard.server.d.ts +9 -0
- package/dist-lib/lib/accounting/twinfield/sandbox-guard.server.d.ts.map +1 -0
- package/dist-lib/lib/accounting/twinfield/sandbox-guard.server.js +38 -0
- package/dist-lib/lib/accounting/twinfield/sandbox-rmw.server.d.ts.map +1 -1
- package/dist-lib/lib/accounting/twinfield/sandbox-rmw.server.js +2 -0
- package/dist-lib/lib/accounting/twinfield/worker.functions.d.ts.map +1 -1
- package/dist-lib/lib/accounting/twinfield/worker.functions.js +2 -0
- package/dist-lib/lib/accounting/twinfield/worker.server.d.ts.map +1 -1
- package/dist-lib/lib/accounting/twinfield/worker.server.js +12 -0
- package/dist-lib/lib/accounting/twinfield/write-gate.d.ts +6 -0
- package/dist-lib/lib/accounting/twinfield/write-gate.d.ts.map +1 -0
- package/dist-lib/lib/accounting/twinfield/write-gate.js +7 -0
- package/dist-lib/lib/auto-promote.d.ts +1 -0
- package/dist-lib/lib/auto-promote.d.ts.map +1 -1
- package/dist-lib/lib/auto-promote.functions.d.ts +1 -13
- package/dist-lib/lib/auto-promote.functions.d.ts.map +1 -1
- package/dist-lib/lib/auto-promote.functions.js +0 -13
- package/dist-lib/lib/customers.functions.d.ts.map +1 -1
- package/dist-lib/lib/customers.functions.js +9 -6
- package/dist-lib/lib/external-customers.functions.d.ts.map +1 -1
- package/dist-lib/lib/external-customers.functions.js +7 -1
- package/dist-lib/lib/twinfield-enqueue-rule.d.ts +13 -0
- package/dist-lib/lib/twinfield-enqueue-rule.d.ts.map +1 -0
- package/dist-lib/lib/twinfield-enqueue-rule.js +16 -0
- package/package.json +4 -3
- package/schema/klanten.sql +1895 -0
|
@@ -0,0 +1,1895 @@
|
|
|
1
|
+
-- Klanten-module: volledig, idempotent database-schema (gegenereerd uit de catalogus).
|
|
2
|
+
-- Veilig herhaalbaar. Wijzigt geen bestaande RLS-policies: policies worden alleen aangemaakt als ze ontbreken.
|
|
3
|
+
-- Floriday-kopers met een actieve inkooprelatie of een Floriday-order worden altijd automatisch klant
|
|
4
|
+
-- (elke 5 minuten, via promote_floriday_customer); ze gaan nooit vanzelf naar Twinfield.
|
|
5
|
+
-- Leest tabellen van Floriday-auth, Twinfield-auth en Verkoop (orders). Ontbreekt een onderdeel van een andere module,
|
|
6
|
+
-- dan wordt alleen dat stuk overgeslagen met een WARNING; de functies zelf blijven fail closed.
|
|
7
|
+
CREATE OR REPLACE FUNCTION pg_temp.klanten_try(p_sql text, p_label text) RETURNS void LANGUAGE plpgsql AS $f$
|
|
8
|
+
BEGIN
|
|
9
|
+
EXECUTE p_sql;
|
|
10
|
+
EXCEPTION WHEN undefined_table OR undefined_function OR undefined_object OR invalid_schema_name OR undefined_column THEN
|
|
11
|
+
RAISE WARNING 'Klanten: overgeslagen (onderdeel van een andere module ontbreekt: %): %', SQLERRM, p_label;
|
|
12
|
+
END $f$;
|
|
13
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE EXTENSION IF NOT EXISTS pgcrypto$klanten_stmt$, 'CREATE EXTENSION IF NOT EXISTS pgcrypto');
|
|
14
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_assortment_items ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_assortment_items ()');
|
|
15
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uui');
|
|
16
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS customer_key text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS customer_key text NOT NULL');
|
|
17
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS trade_item_key text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS trade_item_key text NOT NULL');
|
|
18
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS source text DEFAULT 'floriday'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS source text DEFAULT ''floriday''');
|
|
19
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS in_assortment boolean DEFAULT true NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS in_assortment boolean DEFAULT ');
|
|
20
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS manual_override boolean DEFAULT false NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS manual_override boolean DEFAUL');
|
|
21
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS synced_at timestamp with time zone$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS synced_at timestamp with time ');
|
|
22
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS created_at timestamp with time');
|
|
23
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ADD COLUMN IF NOT EXISTS updated_at timestamp with time');
|
|
24
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_audit_log ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_audit_log ()');
|
|
25
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT');
|
|
26
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL');
|
|
27
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS user_id uuid$klanten_stmt$, 'ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS user_id uuid');
|
|
28
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS action text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS action text NOT NULL');
|
|
29
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS changes jsonb DEFAULT '{}'::jsonb NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS changes jsonb DEFAULT ''{}''::jsonb NOT');
|
|
30
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_audit_log ADD COLUMN IF NOT EXISTS created_at timestamp with time zone D');
|
|
31
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_contacts ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_contacts ()');
|
|
32
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT ');
|
|
33
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL');
|
|
34
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS floriday_contact_id text$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS floriday_contact_id text');
|
|
35
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS full_name text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS full_name text NOT NULL');
|
|
36
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS job_title text$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS job_title text');
|
|
37
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS email text$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS email text');
|
|
38
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS phone text$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS phone text');
|
|
39
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS photo_url text$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS photo_url text');
|
|
40
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS is_active boolean DEFAULT true NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS is_active boolean DEFAULT true NOT NUL');
|
|
41
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS raw jsonb$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS raw jsonb');
|
|
42
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DE');
|
|
43
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_contacts ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DE');
|
|
44
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_delivery_locations ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_delivery_locations ()');
|
|
45
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_u');
|
|
46
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL');
|
|
47
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS floriday_location_id text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS floriday_location_id text');
|
|
48
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS name text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS name text');
|
|
49
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS address_line text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS address_line text');
|
|
50
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS postal_code text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS postal_code text');
|
|
51
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS city text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS city text');
|
|
52
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS country text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS country text');
|
|
53
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS gln text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS gln text');
|
|
54
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS is_primary boolean DEFAULT false NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS is_primary boolean DEFAULT f');
|
|
55
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS raw jsonb$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS raw jsonb');
|
|
56
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS created_at timestamp with ti');
|
|
57
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS updated_at timestamp with ti');
|
|
58
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS street text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS street text');
|
|
59
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS house_number text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS house_number text');
|
|
60
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS province text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS province text');
|
|
61
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS carrier_id uuid$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS carrier_id uuid');
|
|
62
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS carrier_assignment_source text DEFAULT 'auto'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS carrier_assignment_source te');
|
|
63
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS self_pickup boolean DEFAULT false NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS self_pickup boolean DEFAULT ');
|
|
64
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS external_provider text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS external_provider text');
|
|
65
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS external_key text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS external_key text');
|
|
66
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS group_key text$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ADD COLUMN IF NOT EXISTS group_key text');
|
|
67
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_logistics_strategy ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_logistics_strategy ()');
|
|
68
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_u');
|
|
69
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS scope text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS scope text NOT NULL');
|
|
70
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS ref_key text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS ref_key text NOT NULL');
|
|
71
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS strategy_id uuid$klanten_stmt$, 'ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS strategy_id uuid');
|
|
72
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS created_at timestamp with ti');
|
|
73
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_logistics_strategy ADD COLUMN IF NOT EXISTS updated_at timestamp with ti');
|
|
74
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_match_suggestions ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_match_suggestions ()');
|
|
75
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uu');
|
|
76
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS floriday_organization_id text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS floriday_organization_id text');
|
|
77
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL');
|
|
78
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS reason text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS reason text NOT NULL');
|
|
79
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS status text DEFAULT 'open'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS status text DEFAULT ''open''::t');
|
|
80
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS decided_at timestamp with time zone$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS decided_at timestamp with tim');
|
|
81
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS decided_by uuid$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS decided_by uuid');
|
|
82
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS created_at timestamp with tim');
|
|
83
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ADD COLUMN IF NOT EXISTS updated_at timestamp with tim');
|
|
84
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_notes ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_notes ()');
|
|
85
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NUL');
|
|
86
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS customer_id uuid$klanten_stmt$, 'ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS customer_id uuid');
|
|
87
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS group_key text$klanten_stmt$, 'ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS group_key text');
|
|
88
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS notes text$klanten_stmt$, 'ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS notes text');
|
|
89
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAU');
|
|
90
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_notes ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAU');
|
|
91
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_price_group_members ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_price_group_members ()');
|
|
92
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_');
|
|
93
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS price_group_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS price_group_id uuid NOT NUL');
|
|
94
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS customer_key text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS customer_key text NOT NULL');
|
|
95
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS owner_id uuid DEFAULT auth.uid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS owner_id uuid DEFAULT auth.');
|
|
96
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_group_members ADD COLUMN IF NOT EXISTS created_at timestamp with t');
|
|
97
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_price_groups ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_price_groups ()');
|
|
98
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() ');
|
|
99
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS owner_id uuid DEFAULT auth.uid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS owner_id uuid DEFAULT auth.uid() N');
|
|
100
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS name text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS name text NOT NULL');
|
|
101
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS currency text DEFAULT 'EUR'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS currency text DEFAULT ''EUR''::text ');
|
|
102
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS pricing_mode text DEFAULT 'manual'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS pricing_mode text DEFAULT ''manual''');
|
|
103
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS price_scope text DEFAULT 'incl_delivery'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS price_scope text DEFAULT ''incl_del');
|
|
104
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS include_stickers boolean DEFAULT false NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS include_stickers boolean DEFAULT f');
|
|
105
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS unit text DEFAULT 'per_fust'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS unit text DEFAULT ''per_fust''::text');
|
|
106
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS calc_type text$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS calc_type text');
|
|
107
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS calc_value_type text$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS calc_value_type text');
|
|
108
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS calc_value numeric(12,4)$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS calc_value numeric(12,4)');
|
|
109
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS handling_fee numeric(12,4)$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS handling_fee numeric(12,4)');
|
|
110
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS distribute_over text$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS distribute_over text');
|
|
111
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS rounding text DEFAULT 'none'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS rounding text DEFAULT ''none''::text');
|
|
112
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS sort_order integer DEFAULT 0 NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS sort_order integer DEFAULT 0 NOT N');
|
|
113
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS is_active boolean DEFAULT true NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS is_active boolean DEFAULT true NOT');
|
|
114
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS created_at timestamp with time zon');
|
|
115
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS updated_at timestamp with time zon');
|
|
116
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS group_type text DEFAULT 'customer_specific'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS group_type text DEFAULT ''customer_');
|
|
117
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS rounding_step numeric DEFAULT 0.05 NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS rounding_step numeric DEFAULT 0.05');
|
|
118
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS source text DEFAULT 'local'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS source text DEFAULT ''local''::text ');
|
|
119
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS external_id text$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS external_id text');
|
|
120
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS external_synced_at timestamp with time zone$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ADD COLUMN IF NOT EXISTS external_synced_at timestamp with ');
|
|
121
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_product_stickers ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_product_stickers ()');
|
|
122
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uui');
|
|
123
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS customer_key text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS customer_key text NOT NULL');
|
|
124
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS trade_item_key text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS trade_item_key text NOT NULL');
|
|
125
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS file_path text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS file_path text NOT NULL');
|
|
126
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS file_name text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS file_name text NOT NULL');
|
|
127
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS mime_type text$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS mime_type text');
|
|
128
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS file_size bigint$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS file_size bigint');
|
|
129
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS uploaded_by uuid$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS uploaded_by uuid');
|
|
130
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS created_at timestamp with time');
|
|
131
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS updated_at timestamp with time');
|
|
132
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS source text DEFAULT 'manual'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS source text DEFAULT ''manual''::');
|
|
133
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS floriday_sticker_id text$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS floriday_sticker_id text');
|
|
134
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS floriday_synced_at timestamp with time zone$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS floriday_synced_at timestamp w');
|
|
135
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS content_hash text$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS content_hash text');
|
|
136
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS width_mm numeric$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS width_mm numeric');
|
|
137
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS height_mm numeric$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ADD COLUMN IF NOT EXISTS height_mm numeric');
|
|
138
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_selected_assortment ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_selected_assortment ()');
|
|
139
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_');
|
|
140
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL');
|
|
141
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS floriday_item_id text$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS floriday_item_id text');
|
|
142
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS article_number text$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS article_number text');
|
|
143
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS product_name text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS product_name text NOT NULL');
|
|
144
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS product_group text$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS product_group text');
|
|
145
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS price numeric$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS price numeric');
|
|
146
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS unit text$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS unit text');
|
|
147
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS raw jsonb$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS raw jsonb');
|
|
148
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS created_at timestamp with t');
|
|
149
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ADD COLUMN IF NOT EXISTS updated_at timestamp with t');
|
|
150
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_sticker_settings ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_sticker_settings ()');
|
|
151
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS customer_key text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS customer_key text NOT NULL');
|
|
152
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS width_mm numeric DEFAULT 100 NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS width_mm numeric DEFAULT 100 N');
|
|
153
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS height_mm numeric DEFAULT 150 NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS height_mm numeric DEFAULT 150 ');
|
|
154
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS created_at timestamp with time');
|
|
155
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_sticker_settings ADD COLUMN IF NOT EXISTS updated_at timestamp with time');
|
|
156
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customer_trade_settings ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customer_trade_settings ()');
|
|
157
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid(');
|
|
158
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL');
|
|
159
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS category text DEFAULT 'general'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS category text DEFAULT ''general'':');
|
|
160
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS setting_key text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS setting_key text NOT NULL');
|
|
161
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS setting_label text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS setting_label text NOT NULL');
|
|
162
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS is_active boolean DEFAULT false NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS is_active boolean DEFAULT false ');
|
|
163
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS raw jsonb$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS raw jsonb');
|
|
164
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS created_at timestamp with time z');
|
|
165
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ADD COLUMN IF NOT EXISTS updated_at timestamp with time z');
|
|
166
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.customers ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.customers ()');
|
|
167
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL');
|
|
168
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS company_name text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS company_name text NOT NULL');
|
|
169
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS email text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS email text');
|
|
170
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS phone text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS phone text');
|
|
171
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address text');
|
|
172
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS city text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS city text');
|
|
173
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS postal_code text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS postal_code text');
|
|
174
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS country text DEFAULT 'Nederland'::text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS country text DEFAULT ''Nederland''::text');
|
|
175
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS notes text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS notes text');
|
|
176
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS custom_fields jsonb DEFAULT '{}'::jsonb NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS custom_fields jsonb DEFAULT ''{}''::jsonb NOT NU');
|
|
177
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT no');
|
|
178
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT no');
|
|
179
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS vat_number text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS vat_number text');
|
|
180
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS contact_person text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS contact_person text');
|
|
181
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS street text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS street text');
|
|
182
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS house_number text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS house_number text');
|
|
183
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS customer_class text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS customer_class text');
|
|
184
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS is_active boolean DEFAULT true NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS is_active boolean DEFAULT true NOT NULL');
|
|
185
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS source text DEFAULT 'local'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS source text DEFAULT ''local''::text NOT NULL');
|
|
186
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS floriday_organization_id text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS floriday_organization_id text');
|
|
187
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS floriday_connection_id uuid$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS floriday_connection_id uuid');
|
|
188
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS last_synced_at timestamp with time zone$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS last_synced_at timestamp with time zone');
|
|
189
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS sync_status text DEFAULT 'idle'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS sync_status text DEFAULT ''idle''::text NOT NULL');
|
|
190
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS sync_error text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS sync_error text');
|
|
191
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS gln text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS gln text');
|
|
192
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS commercial_name text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS commercial_name text');
|
|
193
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bio text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bio text');
|
|
194
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS segments text[] DEFAULT '{}'::text[] NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS segments text[] DEFAULT ''{}''::text[] NOT NULL');
|
|
195
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS trade_forms text[] DEFAULT '{}'::text[] NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS trade_forms text[] DEFAULT ''{}''::text[] NOT NU');
|
|
196
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS markets text[] DEFAULT '{}'::text[] NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS markets text[] DEFAULT ''{}''::text[] NOT NULL');
|
|
197
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS product_groups text[] DEFAULT '{}'::text[] NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS product_groups text[] DEFAULT ''{}''::text[] NOT');
|
|
198
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS payment_methods text[] DEFAULT '{}'::text[] NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS payment_methods text[] DEFAULT ''{}''::text[] NO');
|
|
199
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS organization_type text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS organization_type text');
|
|
200
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS website text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS website text');
|
|
201
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS logo_url text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS logo_url text');
|
|
202
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS floriday_raw jsonb$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS floriday_raw jsonb');
|
|
203
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS connection_status text DEFAULT 'none'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS connection_status text DEFAULT ''none''::text NO');
|
|
204
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS external_id text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS external_id text');
|
|
205
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS customer_number text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS customer_number text');
|
|
206
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS language text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS language text');
|
|
207
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS billing_email text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS billing_email text');
|
|
208
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address_type text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address_type text');
|
|
209
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address_line1 text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address_line1 text');
|
|
210
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address_line2 text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS address_line2 text');
|
|
211
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS icp_country_code text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS icp_country_code text');
|
|
212
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS attention_to text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS attention_to text');
|
|
213
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS fax text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS fax text');
|
|
214
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS coc_number text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS coc_number text');
|
|
215
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_name text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_name text');
|
|
216
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_account_holder text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_account_holder text');
|
|
217
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_account_number text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_account_number text');
|
|
218
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_iban text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_iban text');
|
|
219
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_bic text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_bic text');
|
|
220
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_national_code text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_national_code text');
|
|
221
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_address_line1 text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_address_line1 text');
|
|
222
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_address_line2 text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_address_line2 text');
|
|
223
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_house_number text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_house_number text');
|
|
224
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_postal_code text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_postal_code text');
|
|
225
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_city text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_city text');
|
|
226
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_state text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_state text');
|
|
227
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_country text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS bank_country text');
|
|
228
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS discount_percentage numeric(6,3)$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS discount_percentage numeric(6,3)');
|
|
229
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS discount_days integer$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS discount_days integer');
|
|
230
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS payment_term_days integer$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS payment_term_days integer');
|
|
231
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS vat_display text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS vat_display text');
|
|
232
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_code text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_code text');
|
|
233
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_synced_at timestamp with time zone$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_synced_at timestamp with time zone');
|
|
234
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_sync_error text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_sync_error text');
|
|
235
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_last_hash text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_last_hash text');
|
|
236
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS ledger_account text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS ledger_account text');
|
|
237
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS credit_limit numeric(14,2) DEFAULT 0 NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS credit_limit numeric(14,2) DEFAULT 0 NOT NULL');
|
|
238
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS send_reminder text DEFAULT 'file'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS send_reminder text DEFAULT ''file''::text NOT NU');
|
|
239
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS payment_spec_method text DEFAULT 'file'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS payment_spec_method text DEFAULT ''file''::text ');
|
|
240
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS invoice_send_as text DEFAULT 'link'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS invoice_send_as text DEFAULT ''link''::text NOT ');
|
|
241
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS e_invoicing boolean DEFAULT false NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS e_invoicing boolean DEFAULT false NOT NULL');
|
|
242
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked boolean DEFAULT false NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked boolean DEFAULT false NOT NULL');
|
|
243
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS discount_surcharge text DEFAULT 'none'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS discount_surcharge text DEFAULT ''none''::text N');
|
|
244
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_uid text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_uid text');
|
|
245
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_vat_code text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_vat_code text');
|
|
246
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_base_version integer$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_base_version integer');
|
|
247
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_base_snapshot jsonb$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_base_snapshot jsonb');
|
|
248
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_present boolean DEFAULT true NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_present boolean DEFAULT true NOT NUL');
|
|
249
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_missing_since timestamp with time zone$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_missing_since timestamp with time zo');
|
|
250
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS credit_manager text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS credit_manager text');
|
|
251
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS reminder_email text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS reminder_email text');
|
|
252
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS credit_manager_name text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS credit_manager_name text');
|
|
253
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS credit_manager_shortname text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS credit_manager_shortname text');
|
|
254
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked_locked boolean$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked_locked boolean');
|
|
255
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked_modified text$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS blocked_modified text');
|
|
256
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_create_on_insert boolean DEFAULT true NOT NULL$klanten_stmt$, 'ALTER TABLE public.customers ADD COLUMN IF NOT EXISTS twinfield_create_on_insert boolean DEFAULT tru');
|
|
257
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.external_customer_providers ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.external_customer_providers ()');
|
|
258
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS provider text NOT NULL$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS provider text NOT NULL');
|
|
259
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS label text NOT NULL$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS label text NOT NULL');
|
|
260
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS icon text$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS icon text');
|
|
261
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS color text$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS color text');
|
|
262
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS sort_order integer DEFAULT 100 NOT NULL$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS sort_order integer DEFAULT 1');
|
|
263
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS is_enabled boolean DEFAULT true NOT NULL$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS is_enabled boolean DEFAULT t');
|
|
264
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS last_synced_at timestamp with time zone$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS last_synced_at timestamp wit');
|
|
265
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS created_at timestamp with ti');
|
|
266
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ADD COLUMN IF NOT EXISTS updated_at timestamp with ti');
|
|
267
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.local_customer_agreements ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.local_customer_agreements ()');
|
|
268
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uui');
|
|
269
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL');
|
|
270
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS product_id uuid$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS product_id uuid');
|
|
271
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS product_category_id uuid$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS product_category_id uuid');
|
|
272
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS base_price numeric(12,4)$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS base_price numeric(12,4)');
|
|
273
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS net_price numeric(12,4) NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS net_price numeric(12,4) NOT NU');
|
|
274
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS currency text DEFAULT 'EUR'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS currency text DEFAULT ''EUR''::t');
|
|
275
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS valid_from date$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS valid_from date');
|
|
276
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS valid_until date$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS valid_until date');
|
|
277
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS min_quantity numeric(12,2) DEFAULT 0 NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS min_quantity numeric(12,2) DEF');
|
|
278
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS notes text$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS notes text');
|
|
279
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS created_at timestamp with time');
|
|
280
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ADD COLUMN IF NOT EXISTS updated_at timestamp with time');
|
|
281
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.local_customer_price_groups ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.local_customer_price_groups ()');
|
|
282
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_u');
|
|
283
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL');
|
|
284
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS product_id uuid$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS product_id uuid');
|
|
285
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS product_category_id uuid$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS product_category_id uuid');
|
|
286
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS min_quantity numeric(12,2) DEFAULT 0 NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS min_quantity numeric(12,2) D');
|
|
287
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS discount_type text NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS discount_type text NOT NULL');
|
|
288
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS discount_value numeric(12,4) NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS discount_value numeric(12,4)');
|
|
289
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS currency text DEFAULT 'EUR'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS currency text DEFAULT ''EUR'':');
|
|
290
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS valid_from date$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS valid_from date');
|
|
291
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS valid_until date$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS valid_until date');
|
|
292
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS notes text$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS notes text');
|
|
293
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS created_at timestamp with ti');
|
|
294
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ADD COLUMN IF NOT EXISTS updated_at timestamp with ti');
|
|
295
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.local_customer_sales_strategies ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.local_customer_sales_strategies ()');
|
|
296
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_rand');
|
|
297
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS customer_id uuid NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS customer_id uuid NOT NUL');
|
|
298
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS product_id uuid$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS product_id uuid');
|
|
299
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS product_category_id uuid$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS product_category_id uuid');
|
|
300
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS discount_type text NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS discount_type text NOT N');
|
|
301
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS discount_value numeric(12,4) NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS discount_value numeric(1');
|
|
302
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS currency text DEFAULT 'EUR'::text NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS currency text DEFAULT ''E');
|
|
303
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS valid_from date$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS valid_from date');
|
|
304
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS valid_until date$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS valid_until date');
|
|
305
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS min_quantity numeric(12,2) DEFAULT 0 NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS min_quantity numeric(12,');
|
|
306
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS notes text$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS notes text');
|
|
307
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS created_at timestamp wit');
|
|
308
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS updated_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ADD COLUMN IF NOT EXISTS updated_at timestamp wit');
|
|
309
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TABLE IF NOT EXISTS public.twinfield_push_log ()$klanten_stmt$, 'CREATE TABLE IF NOT EXISTS public.twinfield_push_log ()');
|
|
310
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT NULL$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS id uuid DEFAULT gen_random_uuid() NOT');
|
|
311
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS queue_id uuid$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS queue_id uuid');
|
|
312
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS customer_id uuid$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS customer_id uuid');
|
|
313
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS office_code text$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS office_code text');
|
|
314
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS twinfield_code text$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS twinfield_code text');
|
|
315
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS request_xml text$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS request_xml text');
|
|
316
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS response_raw text$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS response_raw text');
|
|
317
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS ok boolean DEFAULT false NOT NULL$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS ok boolean DEFAULT false NOT NULL');
|
|
318
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS message text$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS message text');
|
|
319
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS created_at timestamp with time zone DEFAULT now() NOT NULL$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ADD COLUMN IF NOT EXISTS created_at timestamp with time zone D');
|
|
320
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_selected_assortment_customer_id_floriday_item_id_key' AND conrelid='public.customer_selected_assortment'::regclass) THEN ALTER TABLE public.customer_selected_assortment ADD CONSTRAINT customer_selected_assortment_customer_id_floriday_item_id_key UNIQUE (customer_id, floriday_item_id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_selected_assortment_');
|
|
321
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_notes_unique_customer' AND conrelid='public.customer_notes'::regclass) THEN ALTER TABLE public.customer_notes ADD CONSTRAINT customer_notes_unique_customer UNIQUE (customer_id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_notes_unique_custome');
|
|
322
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_notes_unique_group' AND conrelid='public.customer_notes'::regclass) THEN ALTER TABLE public.customer_notes ADD CONSTRAINT customer_notes_unique_group UNIQUE (group_key); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_notes_unique_group'' ');
|
|
323
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_trade_settings_customer_id_setting_key_key' AND conrelid='public.customer_trade_settings'::regclass) THEN ALTER TABLE public.customer_trade_settings ADD CONSTRAINT customer_trade_settings_customer_id_setting_key_key UNIQUE (customer_id, setting_key); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_trade_settings_custo');
|
|
324
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_group_members_price_group_id_customer_key_key' AND conrelid='public.customer_price_group_members'::regclass) THEN ALTER TABLE public.customer_price_group_members ADD CONSTRAINT customer_price_group_members_price_group_id_customer_key_key UNIQUE (price_group_id, customer_key); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_group_members_');
|
|
325
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_product_stickers_customer_key_trade_item_key_key' AND conrelid='public.customer_product_stickers'::regclass) THEN ALTER TABLE public.customer_product_stickers ADD CONSTRAINT customer_product_stickers_customer_key_trade_item_key_key UNIQUE (customer_key, trade_item_key); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_product_stickers_cus');
|
|
326
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_logistics_strategy_scope_ref_key_key' AND conrelid='public.customer_logistics_strategy'::regclass) THEN ALTER TABLE public.customer_logistics_strategy ADD CONSTRAINT customer_logistics_strategy_scope_ref_key_key UNIQUE (scope, ref_key); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_logistics_strategy_s');
|
|
327
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_match_suggestions_floriday_organization_id_custome_key' AND conrelid='public.customer_match_suggestions'::regclass) THEN ALTER TABLE public.customer_match_suggestions ADD CONSTRAINT customer_match_suggestions_floriday_organization_id_custome_key UNIQUE (floriday_organization_id, customer_id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_match_suggestions_fl');
|
|
328
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_customer_id_floriday_location_i_key' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_customer_id_floriday_location_i_key UNIQUE (customer_id, floriday_location_id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_delivery_locations_c');
|
|
329
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_contacts_customer_id_floriday_contact_id_key' AND conrelid='public.customer_contacts'::regclass) THEN ALTER TABLE public.customer_contacts ADD CONSTRAINT customer_contacts_customer_id_floriday_contact_id_key UNIQUE (customer_id, floriday_contact_id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_contacts_customer_id');
|
|
330
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ DECLARE v_dups text; BEGIN
|
|
331
|
+
IF EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customers_floriday_org_unique' AND conrelid='public.customers'::regclass)
|
|
332
|
+
OR EXISTS (SELECT 1 FROM pg_indexes WHERE schemaname='public' AND indexname='customers_floriday_org_unique') THEN RETURN; END IF;
|
|
333
|
+
SELECT string_agg(floriday_organization_id::text || ' (' || n || 'x)', ', ') INTO v_dups FROM (
|
|
334
|
+
SELECT floriday_organization_id, count(*) n FROM public.customers WHERE floriday_organization_id IS NOT NULL GROUP BY 1 HAVING count(*) > 1) d;
|
|
335
|
+
IF v_dups IS NOT NULL THEN
|
|
336
|
+
RAISE WARNING 'Klanten: unieke regel customers_floriday_org_unique overgeslagen; dubbele Floriday-organisatienummers: %. Los deze eerst op en voer het schema opnieuw uit.', v_dups;
|
|
337
|
+
RETURN;
|
|
338
|
+
END IF;
|
|
339
|
+
ALTER TABLE public.customers ADD CONSTRAINT customers_floriday_org_unique UNIQUE (floriday_organization_id);
|
|
340
|
+
END $c$$klanten_stmt$, 'DO $c$ DECLARE v_dups text; BEGIN IF EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customers_fl');
|
|
341
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='external_customer_providers_pkey' AND conrelid='public.external_customer_providers'::regclass) THEN ALTER TABLE public.external_customer_providers ADD CONSTRAINT external_customer_providers_pkey PRIMARY KEY (provider); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''external_customer_providers_p');
|
|
342
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_notes_pkey' AND conrelid='public.customer_notes'::regclass) THEN ALTER TABLE public.customer_notes ADD CONSTRAINT customer_notes_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_notes_pkey'' AND conr');
|
|
343
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_group_members_pkey' AND conrelid='public.customer_price_group_members'::regclass) THEN ALTER TABLE public.customer_price_group_members ADD CONSTRAINT customer_price_group_members_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_group_members_');
|
|
344
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_contacts_pkey' AND conrelid='public.customer_contacts'::regclass) THEN ALTER TABLE public.customer_contacts ADD CONSTRAINT customer_contacts_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_contacts_pkey'' AND c');
|
|
345
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_match_suggestions_pkey' AND conrelid='public.customer_match_suggestions'::regclass) THEN ALTER TABLE public.customer_match_suggestions ADD CONSTRAINT customer_match_suggestions_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_match_suggestions_pk');
|
|
346
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_audit_log_pkey' AND conrelid='public.customer_audit_log'::regclass) THEN ALTER TABLE public.customer_audit_log ADD CONSTRAINT customer_audit_log_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_audit_log_pkey'' AND ');
|
|
347
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_groups_pkey' AND conrelid='public.customer_price_groups'::regclass) THEN ALTER TABLE public.customer_price_groups ADD CONSTRAINT customer_price_groups_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_groups_pkey'' A');
|
|
348
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_trade_settings_pkey' AND conrelid='public.customer_trade_settings'::regclass) THEN ALTER TABLE public.customer_trade_settings ADD CONSTRAINT customer_trade_settings_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_trade_settings_pkey''');
|
|
349
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_assortment_items_pkey' AND conrelid='public.customer_assortment_items'::regclass) THEN ALTER TABLE public.customer_assortment_items ADD CONSTRAINT customer_assortment_items_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_assortment_items_pke');
|
|
350
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_product_stickers_pkey' AND conrelid='public.customer_product_stickers'::regclass) THEN ALTER TABLE public.customer_product_stickers ADD CONSTRAINT customer_product_stickers_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_product_stickers_pke');
|
|
351
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_selected_assortment_pkey' AND conrelid='public.customer_selected_assortment'::regclass) THEN ALTER TABLE public.customer_selected_assortment ADD CONSTRAINT customer_selected_assortment_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_selected_assortment_');
|
|
352
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_sticker_settings_pkey' AND conrelid='public.customer_sticker_settings'::regclass) THEN ALTER TABLE public.customer_sticker_settings ADD CONSTRAINT customer_sticker_settings_pkey PRIMARY KEY (customer_key); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_sticker_settings_pke');
|
|
353
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='twinfield_push_log_pkey' AND conrelid='public.twinfield_push_log'::regclass) THEN ALTER TABLE public.twinfield_push_log ADD CONSTRAINT twinfield_push_log_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''twinfield_push_log_pkey'' AND ');
|
|
354
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_pkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_sales_strategi');
|
|
355
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_pkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_price_groups_p');
|
|
356
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_pkey' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_delivery_locations_p');
|
|
357
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_logistics_strategy_pkey' AND conrelid='public.customer_logistics_strategy'::regclass) THEN ALTER TABLE public.customer_logistics_strategy ADD CONSTRAINT customer_logistics_strategy_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_logistics_strategy_p');
|
|
358
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_pkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_agreements_pke');
|
|
359
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customers_pkey' AND conrelid='public.customers'::regclass) THEN ALTER TABLE public.customers ADD CONSTRAINT customers_pkey PRIMARY KEY (id); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customers_pkey'' AND conrelid=');
|
|
360
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_product_category_id_fkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_price_groups_p');
|
|
361
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_contacts_customer_id_fkey' AND conrelid='public.customer_contacts'::regclass) THEN ALTER TABLE public.customer_contacts ADD CONSTRAINT customer_contacts_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_contacts_customer_id');
|
|
362
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_carrier_id_fkey' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_carrier_id_fkey FOREIGN KEY (carrier_id) REFERENCES carriers(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_delivery_locations_c');
|
|
363
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_customer_id_fkey' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_delivery_locations_c');
|
|
364
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_logistics_strategy_strategy_id_fkey' AND conrelid='public.customer_logistics_strategy'::regclass) THEN ALTER TABLE public.customer_logistics_strategy ADD CONSTRAINT customer_logistics_strategy_strategy_id_fkey FOREIGN KEY (strategy_id) REFERENCES logistics_strategies(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_logistics_strategy_s');
|
|
365
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_notes_customer_id_fkey' AND conrelid='public.customer_notes'::regclass) THEN ALTER TABLE public.customer_notes ADD CONSTRAINT customer_notes_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_notes_customer_id_fk');
|
|
366
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_group_members_price_group_id_fkey' AND conrelid='public.customer_price_group_members'::regclass) THEN ALTER TABLE public.customer_price_group_members ADD CONSTRAINT customer_price_group_members_price_group_id_fkey FOREIGN KEY (price_group_id) REFERENCES customer_price_groups(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_group_members_');
|
|
367
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_selected_assortment_customer_id_fkey' AND conrelid='public.customer_selected_assortment'::regclass) THEN ALTER TABLE public.customer_selected_assortment ADD CONSTRAINT customer_selected_assortment_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_selected_assortment_');
|
|
368
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_trade_settings_customer_id_fkey' AND conrelid='public.customer_trade_settings'::regclass) THEN ALTER TABLE public.customer_trade_settings ADD CONSTRAINT customer_trade_settings_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_trade_settings_custo');
|
|
369
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_match_suggestions_customer_id_fkey' AND conrelid='public.customer_match_suggestions'::regclass) THEN ALTER TABLE public.customer_match_suggestions ADD CONSTRAINT customer_match_suggestions_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_match_suggestions_cu');
|
|
370
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_customer_id_fkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_agreements_cus');
|
|
371
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_product_category_id_fkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_agreements_pro');
|
|
372
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_agreements_product_id_fkey' AND conrelid='public.local_customer_agreements'::regclass) THEN ALTER TABLE public.local_customer_agreements ADD CONSTRAINT local_customer_agreements_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_agreements_pro');
|
|
373
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_customer_id_fkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_price_groups_c');
|
|
374
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_product_id_fkey' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_price_groups_p');
|
|
375
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_customer_id_fkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_sales_strategi');
|
|
376
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_product_category_id_fkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_product_category_id_fkey FOREIGN KEY (product_category_id) REFERENCES product_categories(id) ON DELETE SET NULL; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_sales_strategi');
|
|
377
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_product_id_fkey' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE; END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_sales_strategi');
|
|
378
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_logistics_strategy_scope_check' AND conrelid='public.customer_logistics_strategy'::regclass) THEN ALTER TABLE public.customer_logistics_strategy ADD CONSTRAINT customer_logistics_strategy_scope_check CHECK ((scope = ANY (ARRAY['customer'::text, 'group'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_logistics_strategy_s');
|
|
379
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customers_sync_status_check' AND conrelid='public.customers'::regclass) THEN ALTER TABLE public.customers ADD CONSTRAINT customers_sync_status_check CHECK ((sync_status = ANY (ARRAY['idle'::text, 'syncing'::text, 'synced'::text, 'error'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customers_sync_status_check'' ');
|
|
380
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customers_source_check' AND conrelid='public.customers'::regclass) THEN ALTER TABLE public.customers ADD CONSTRAINT customers_source_check CHECK ((source = ANY (ARRAY['local'::text, 'floriday'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customers_source_check'' AND c');
|
|
381
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_sales_strategies_discount_type_check' AND conrelid='public.local_customer_sales_strategies'::regclass) THEN ALTER TABLE public.local_customer_sales_strategies ADD CONSTRAINT local_customer_sales_strategies_discount_type_check CHECK ((discount_type = ANY (ARRAY['percentage'::text, 'amount'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_sales_strategi');
|
|
382
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='local_customer_price_groups_discount_type_check' AND conrelid='public.local_customer_price_groups'::regclass) THEN ALTER TABLE public.local_customer_price_groups ADD CONSTRAINT local_customer_price_groups_discount_type_check CHECK ((discount_type = ANY (ARRAY['percentage'::text, 'amount'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''local_customer_price_groups_d');
|
|
383
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_groups_pricing_mode_check' AND conrelid='public.customer_price_groups'::regclass) THEN ALTER TABLE public.customer_price_groups ADD CONSTRAINT customer_price_groups_pricing_mode_check CHECK ((pricing_mode = ANY (ARRAY['manual'::text, 'calculated'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_groups_pricing');
|
|
384
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_groups_price_scope_check' AND conrelid='public.customer_price_groups'::regclass) THEN ALTER TABLE public.customer_price_groups ADD CONSTRAINT customer_price_groups_price_scope_check CHECK ((price_scope = ANY (ARRAY['incl_delivery'::text, 'excl_delivery'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_groups_price_s');
|
|
385
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_audit_log_action_check' AND conrelid='public.customer_audit_log'::regclass) THEN ALTER TABLE public.customer_audit_log ADD CONSTRAINT customer_audit_log_action_check CHECK ((action = ANY (ARRAY['insert'::text, 'update'::text, 'delete'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_audit_log_action_che');
|
|
386
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_groups_group_type_check' AND conrelid='public.customer_price_groups'::regclass) THEN ALTER TABLE public.customer_price_groups ADD CONSTRAINT customer_price_groups_group_type_check CHECK ((group_type = ANY (ARRAY['general'::text, 'customer_specific'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_groups_group_t');
|
|
387
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_owner_check' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_owner_check CHECK (((customer_id IS NOT NULL) OR (group_key IS NOT NULL) OR ((external_provider IS NOT NULL) AND (external_key IS NOT NULL)))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_delivery_locations_o');
|
|
388
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_groups_calc_value_type_check' AND conrelid='public.customer_price_groups'::regclass) THEN ALTER TABLE public.customer_price_groups ADD CONSTRAINT customer_price_groups_calc_value_type_check CHECK ((calc_value_type = ANY (ARRAY['fixed'::text, 'percentage'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_groups_calc_va');
|
|
389
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_price_groups_calc_type_check' AND conrelid='public.customer_price_groups'::regclass) THEN ALTER TABLE public.customer_price_groups ADD CONSTRAINT customer_price_groups_calc_type_check CHECK ((calc_type = ANY (ARRAY['discount'::text, 'surcharge'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_price_groups_calc_ty');
|
|
390
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_notes_one_owner' AND conrelid='public.customer_notes'::regclass) THEN ALTER TABLE public.customer_notes ADD CONSTRAINT customer_notes_one_owner CHECK ((((customer_id IS NOT NULL) AND (group_key IS NULL)) OR ((customer_id IS NULL) AND (group_key IS NOT NULL)))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_notes_one_owner'' AND');
|
|
391
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='customer_delivery_locations_carrier_assignment_source_check' AND conrelid='public.customer_delivery_locations'::regclass) THEN ALTER TABLE public.customer_delivery_locations ADD CONSTRAINT customer_delivery_locations_carrier_assignment_source_check CHECK ((carrier_assignment_source = ANY (ARRAY['auto'::text, 'manual'::text, 'none'::text]))); END IF; END $c$$klanten_stmt$, 'DO $c$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname=''customer_delivery_locations_c');
|
|
392
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_delivery_locations_customer ON public.customer_delivery_locations USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_delivery_locations_customer ON public.customer_delivery_loca');
|
|
393
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS customers_twinfield_code_key ON public.customers USING btree (twinfield_code) WHERE (twinfield_code IS NOT NULL)$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS customers_twinfield_code_key ON public.customers USING btree (twin');
|
|
394
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_cdl_floriday_location ON public.customer_delivery_locations USING btree (floriday_location_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_cdl_floriday_location ON public.customer_delivery_locations USING btr');
|
|
395
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_active ON public.customers USING btree (is_active)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_active ON public.customers USING btree (is_active)');
|
|
396
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $c$ DECLARE v_dups text; BEGIN
|
|
397
|
+
IF EXISTS (SELECT 1 FROM pg_indexes WHERE schemaname='public' AND indexname='customers_floriday_unique') THEN RETURN; END IF;
|
|
398
|
+
SELECT string_agg(coalesce(floriday_connection_id::text,'-') || '/' || floriday_organization_id::text || ' (' || n || 'x)', ', ') INTO v_dups FROM (
|
|
399
|
+
SELECT floriday_connection_id, floriday_organization_id, count(*) n FROM public.customers
|
|
400
|
+
WHERE floriday_connection_id IS NOT NULL AND floriday_organization_id IS NOT NULL GROUP BY 1,2 HAVING count(*) > 1) d;
|
|
401
|
+
IF v_dups IS NOT NULL THEN
|
|
402
|
+
RAISE WARNING 'Klanten: unieke index customers_floriday_unique overgeslagen; dubbele koppeling/organisatie: %. Los deze eerst op en voer het schema opnieuw uit.', v_dups;
|
|
403
|
+
RETURN;
|
|
404
|
+
END IF;
|
|
405
|
+
CREATE UNIQUE INDEX customers_floriday_unique ON public.customers USING btree (floriday_connection_id, floriday_organization_id);
|
|
406
|
+
END $c$$klanten_stmt$, 'DO $c$ DECLARE v_dups text; BEGIN IF EXISTS (SELECT 1 FROM pg_indexes WHERE schemaname=''public'' AND ');
|
|
407
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS customer_product_stickers_key_uidx ON public.customer_product_stickers USING btree (customer_key, trade_item_key)$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS customer_product_stickers_key_uidx ON public.customer_product_stic');
|
|
408
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_selected_assortment_customer ON public.customer_selected_assortment USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_selected_assortment_customer ON public.customer_selected_ass');
|
|
409
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS customer_price_groups_owner_sort_idx ON public.customer_price_groups USING btree (owner_id, sort_order)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS customer_price_groups_owner_sort_idx ON public.customer_price_groups USIN');
|
|
410
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_notes_group_key ON public.customer_notes USING btree (group_key)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_notes_group_key ON public.customer_notes USING btree (group_');
|
|
411
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_delivery_locations_carrier ON public.customer_delivery_locations USING btree (carrier_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_delivery_locations_carrier ON public.customer_delivery_locat');
|
|
412
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS customer_price_group_members_customer_idx ON public.customer_price_group_members USING btree (customer_key)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS customer_price_group_members_customer_idx ON public.customer_price_group_');
|
|
413
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_cdl_external ON public.customer_delivery_locations USING btree (external_provider, external_key)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_cdl_external ON public.customer_delivery_locations USING btree (exter');
|
|
414
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_local_agreements_customer ON public.local_customer_agreements USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_local_agreements_customer ON public.local_customer_agreements USING b');
|
|
415
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS customers_twinfield_code_uidx ON public.customers USING btree (twinfield_code) WHERE ((twinfield_code IS NOT NULL) AND (btrim(twinfield_code) <> ''::text))$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS customers_twinfield_code_uidx ON public.customers USING btree (twi');
|
|
416
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS customers_updated_at_idx ON public.customers USING btree (updated_at)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS customers_updated_at_idx ON public.customers USING btree (updated_at)');
|
|
417
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_contacts_customer ON public.customer_contacts USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_contacts_customer ON public.customer_contacts USING btree (c');
|
|
418
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_trade_settings_customer ON public.customer_trade_settings USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_trade_settings_customer ON public.customer_trade_settings US');
|
|
419
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_company_trgm ON public.customers USING gin (company_name gin_trgm_ops)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_company_trgm ON public.customers USING gin (company_name gi');
|
|
420
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS customers_source_external_id_idx ON public.customers USING btree (source, external_id) WHERE (external_id IS NOT NULL)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS customers_source_external_id_idx ON public.customers USING btree (source,');
|
|
421
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS customers_customer_number_key ON public.customers USING btree (customer_number) WHERE ((customer_number IS NOT NULL) AND (source = 'local'::text))$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS customers_customer_number_key ON public.customers USING btree (cus');
|
|
422
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS customer_price_group_members_pg_idx ON public.customer_price_group_members USING btree (price_group_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS customer_price_group_members_pg_idx ON public.customer_price_group_member');
|
|
423
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_local_sales_strategies_customer ON public.local_customer_sales_strategies USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_local_sales_strategies_customer ON public.local_customer_sales_strate');
|
|
424
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_cdl_address_line ON public.customer_delivery_locations USING btree (address_line)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_cdl_address_line ON public.customer_delivery_locations USING btree (a');
|
|
425
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS customer_delivery_locations_group_key_idx ON public.customer_delivery_locations USING btree (group_key)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS customer_delivery_locations_group_key_idx ON public.customer_delivery_loc');
|
|
426
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_company_lower ON public.customers USING btree (lower(company_name))$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_company_lower ON public.customers USING btree (lower(compan');
|
|
427
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_local_price_groups_customer ON public.local_customer_price_groups USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_local_price_groups_customer ON public.local_customer_price_groups USI');
|
|
428
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_connection_status ON public.customers USING btree (floriday_connection_id, connection_status)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_connection_status ON public.customers USING btree (floriday');
|
|
429
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS customer_assortment_items_key_uidx ON public.customer_assortment_items USING btree (customer_key, trade_item_key)$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS customer_assortment_items_key_uidx ON public.customer_assortment_i');
|
|
430
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_company_name ON public.customers USING btree (company_name)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_company_name ON public.customers USING btree (company_name)');
|
|
431
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_audit_customer ON public.customer_audit_log USING btree (customer_id, created_at DESC)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_audit_customer ON public.customer_audit_log USING btree (cus');
|
|
432
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_vat ON public.customers USING btree (vat_number)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_vat ON public.customers USING btree (vat_number)');
|
|
433
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS customer_audit_log_customer_id_idx ON public.customer_audit_log USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS customer_audit_log_customer_id_idx ON public.customer_audit_log USING btr');
|
|
434
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS cdl_one_primary_per_group ON public.customer_delivery_locations USING btree (group_key) WHERE (is_primary AND (customer_id IS NULL) AND (group_key IS NOT NULL))$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS cdl_one_primary_per_group ON public.customer_delivery_locations US');
|
|
435
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_cdl_gln ON public.customer_delivery_locations USING btree (gln)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_cdl_gln ON public.customer_delivery_locations USING btree (gln)');
|
|
436
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS cdl_one_primary_per_customer ON public.customer_delivery_locations USING btree (customer_id) WHERE (is_primary AND (customer_id IS NOT NULL))$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS cdl_one_primary_per_customer ON public.customer_delivery_locations');
|
|
437
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_twinfield_push_log_customer ON public.twinfield_push_log USING btree (customer_id, created_at DESC)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_twinfield_push_log_customer ON public.twinfield_push_log USING btree ');
|
|
438
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE UNIQUE INDEX IF NOT EXISTS customer_price_groups_external_id_uidx ON public.customer_price_groups USING btree (external_id) WHERE ((source = 'floriday'::text) AND (external_id IS NOT NULL))$klanten_stmt$, 'CREATE UNIQUE INDEX IF NOT EXISTS customer_price_groups_external_id_uidx ON public.customer_price_gr');
|
|
439
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_email ON public.customers USING btree (email)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_email ON public.customers USING btree (email)');
|
|
440
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customers_class ON public.customers USING btree (customer_class)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customers_class ON public.customers USING btree (customer_class)');
|
|
441
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE INDEX IF NOT EXISTS idx_customer_notes_customer_id ON public.customer_notes USING btree (customer_id)$klanten_stmt$, 'CREATE INDEX IF NOT EXISTS idx_customer_notes_customer_id ON public.customer_notes USING btree (cust');
|
|
442
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.claim_twinfield_push_batch(_limit integer DEFAULT 25, _customer_id uuid DEFAULT NULL::uuid)
|
|
443
|
+
RETURNS SETOF twinfield_push_queue
|
|
444
|
+
LANGUAGE plpgsql
|
|
445
|
+
SECURITY DEFINER
|
|
446
|
+
SET search_path TO 'public'
|
|
447
|
+
AS $function$
|
|
448
|
+
BEGIN
|
|
449
|
+
UPDATE public.twinfield_push_queue
|
|
450
|
+
SET status = 'pending', next_attempt_at = now(), updated_at = now(),
|
|
451
|
+
last_error = COALESCE(last_error, 'Verwerking bleef hangen en is automatisch opnieuw ingepland.')
|
|
452
|
+
WHERE status = 'processing' AND updated_at < now() - interval '10 minutes';
|
|
453
|
+
|
|
454
|
+
RETURN QUERY
|
|
455
|
+
WITH claimed AS (
|
|
456
|
+
SELECT id FROM public.twinfield_push_queue
|
|
457
|
+
WHERE status = 'pending' AND next_attempt_at <= now()
|
|
458
|
+
AND (_customer_id IS NULL OR customer_id = _customer_id)
|
|
459
|
+
ORDER BY created_at FOR UPDATE SKIP LOCKED LIMIT _limit
|
|
460
|
+
)
|
|
461
|
+
UPDATE public.twinfield_push_queue q SET status = 'processing', updated_at = now()
|
|
462
|
+
FROM claimed WHERE q.id = claimed.id RETURNING q.*;
|
|
463
|
+
END$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.claim_twinfield_push_batch(_limit integer DEFAULT 25, _customer_id');
|
|
464
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.customer_soft_key(_email text, _postal text, _house text, _name text)
|
|
465
|
+
RETURNS text
|
|
466
|
+
LANGUAGE sql
|
|
467
|
+
IMMUTABLE
|
|
468
|
+
AS $function$ SELECT COALESCE( NULLIF(lower(btrim(COALESCE(_email,''))),''), NULLIF(regexp_replace(lower(COALESCE(_postal,'')||'|'||COALESCE(_house,'')||'|'||COALESCE(_name,'')),'[^a-z0-9|]','','g'),'||') ) $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.customer_soft_key(_email text, _postal text, _house text, _name te');
|
|
469
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.enqueue_twinfield_push()
|
|
470
|
+
RETURNS trigger
|
|
471
|
+
LANGUAGE plpgsql
|
|
472
|
+
SECURITY DEFINER
|
|
473
|
+
SET search_path TO 'public'
|
|
474
|
+
AS $function$
|
|
475
|
+
DECLARE
|
|
476
|
+
v_conn_id uuid; v_office text; v_relevant_changed boolean := false; v_payload jsonb;
|
|
477
|
+
BEGIN
|
|
478
|
+
BEGIN
|
|
479
|
+
IF COALESCE(NEW.source, 'local') <> 'local' AND NOT (COALESCE(NEW.twinfield_create_on_insert, false)
|
|
480
|
+
AND NULLIF(NEW.custom_fields->>'twinfield_requested_at','') IS NOT NULL) THEN RETURN NEW; END IF;
|
|
481
|
+
IF COALESCE(current_setting('app.skip_twinfield_push', true), '') = 'on' THEN RETURN NEW; END IF;
|
|
482
|
+
IF TG_OP = 'INSERT' AND NEW.twinfield_create_on_insert = false THEN RETURN NEW; END IF;
|
|
483
|
+
IF TG_OP = 'UPDATE' THEN
|
|
484
|
+
IF NEW.twinfield_code IS NULL AND NEW.twinfield_create_on_insert = false
|
|
485
|
+
AND OLD.twinfield_create_on_insert = false THEN RETURN NEW; END IF;
|
|
486
|
+
v_relevant_changed :=
|
|
487
|
+
(OLD.twinfield_create_on_insert = false AND NEW.twinfield_create_on_insert = true)
|
|
488
|
+
OR (NEW.custom_fields->>'twinfield_requested_at') IS DISTINCT FROM (OLD.custom_fields->>'twinfield_requested_at')
|
|
489
|
+
OR NEW.company_name IS DISTINCT FROM OLD.company_name
|
|
490
|
+
OR NEW.email IS DISTINCT FROM OLD.email
|
|
491
|
+
OR NEW.phone IS DISTINCT FROM OLD.phone
|
|
492
|
+
OR NEW.street IS DISTINCT FROM OLD.street
|
|
493
|
+
OR NEW.house_number IS DISTINCT FROM OLD.house_number
|
|
494
|
+
OR NEW.postal_code IS DISTINCT FROM OLD.postal_code
|
|
495
|
+
OR NEW.city IS DISTINCT FROM OLD.city
|
|
496
|
+
OR NEW.country IS DISTINCT FROM OLD.country
|
|
497
|
+
OR NEW.vat_number IS DISTINCT FROM OLD.vat_number
|
|
498
|
+
OR NEW.coc_number IS DISTINCT FROM OLD.coc_number
|
|
499
|
+
OR NEW.website IS DISTINCT FROM OLD.website
|
|
500
|
+
OR NEW.billing_email IS DISTINCT FROM OLD.billing_email
|
|
501
|
+
OR NEW.payment_term_days IS DISTINCT FROM OLD.payment_term_days
|
|
502
|
+
OR NEW.discount_days IS DISTINCT FROM OLD.discount_days
|
|
503
|
+
OR NEW.discount_percentage IS DISTINCT FROM OLD.discount_percentage
|
|
504
|
+
OR NEW.bank_iban IS DISTINCT FROM OLD.bank_iban
|
|
505
|
+
OR NEW.bank_bic IS DISTINCT FROM OLD.bank_bic
|
|
506
|
+
OR NEW.bank_account_holder IS DISTINCT FROM OLD.bank_account_holder
|
|
507
|
+
OR NEW.bank_account_number IS DISTINCT FROM OLD.bank_account_number
|
|
508
|
+
OR NEW.bank_name IS DISTINCT FROM OLD.bank_name
|
|
509
|
+
OR NEW.is_active IS DISTINCT FROM OLD.is_active
|
|
510
|
+
OR NEW.contact_person IS DISTINCT FROM OLD.contact_person
|
|
511
|
+
OR NEW.language IS DISTINCT FROM OLD.language
|
|
512
|
+
OR NEW.ledger_account IS DISTINCT FROM OLD.ledger_account
|
|
513
|
+
OR NEW.credit_limit IS DISTINCT FROM OLD.credit_limit
|
|
514
|
+
OR NEW.send_reminder IS DISTINCT FROM OLD.send_reminder
|
|
515
|
+
OR NEW.e_invoicing IS DISTINCT FROM OLD.e_invoicing
|
|
516
|
+
OR NEW.blocked IS DISTINCT FROM OLD.blocked
|
|
517
|
+
OR NEW.address_type IS DISTINCT FROM OLD.address_type
|
|
518
|
+
OR NEW.address_line1 IS DISTINCT FROM OLD.address_line1
|
|
519
|
+
OR NEW.address_line2 IS DISTINCT FROM OLD.address_line2
|
|
520
|
+
OR NEW.fax IS DISTINCT FROM OLD.fax
|
|
521
|
+
OR NEW.attention_to IS DISTINCT FROM OLD.attention_to
|
|
522
|
+
OR NEW.bank_city IS DISTINCT FROM OLD.bank_city
|
|
523
|
+
OR NEW.bank_postal_code IS DISTINCT FROM OLD.bank_postal_code
|
|
524
|
+
OR NEW.bank_country IS DISTINCT FROM OLD.bank_country
|
|
525
|
+
OR NEW.bank_address_line1 IS DISTINCT FROM OLD.bank_address_line1
|
|
526
|
+
OR NEW.bank_house_number IS DISTINCT FROM OLD.bank_house_number
|
|
527
|
+
OR NEW.twinfield_vat_code IS DISTINCT FROM OLD.twinfield_vat_code;
|
|
528
|
+
IF NOT v_relevant_changed THEN RETURN NEW; END IF;
|
|
529
|
+
END IF;
|
|
530
|
+
|
|
531
|
+
SELECT id, COALESCE(office_code, company_code) INTO v_conn_id, v_office
|
|
532
|
+
FROM public.twinfield_connections WHERE is_active = true
|
|
533
|
+
ORDER BY connected_at DESC NULLS LAST, created_at DESC LIMIT 1;
|
|
534
|
+
|
|
535
|
+
v_payload := jsonb_build_object('customer_id', NEW.id,
|
|
536
|
+
'action', CASE WHEN TG_OP = 'INSERT' OR NEW.twinfield_code IS NULL THEN 'create' ELSE 'update' END);
|
|
537
|
+
|
|
538
|
+
INSERT INTO public.twinfield_push_queue (connection_id, office_code, payload, status, attempts,
|
|
539
|
+
next_attempt_at, idempotency_key, action, customer_id)
|
|
540
|
+
VALUES (v_conn_id, v_office, v_payload, 'pending', 0, now(),
|
|
541
|
+
NEW.id::text || ':' || (CASE WHEN TG_OP = 'INSERT' OR NEW.twinfield_code IS NULL THEN 'create' ELSE 'update:' || md5(NEW::text) END),
|
|
542
|
+
CASE WHEN TG_OP = 'INSERT' OR NEW.twinfield_code IS NULL THEN 'create' ELSE 'update' END, NEW.id)
|
|
543
|
+
ON CONFLICT (idempotency_key) DO NOTHING;
|
|
544
|
+
RETURN NEW;
|
|
545
|
+
EXCEPTION WHEN OTHERS THEN
|
|
546
|
+
RAISE WARNING 'enqueue_twinfield_push overgeslagen voor klant %: %', NEW.id, SQLERRM;
|
|
547
|
+
BEGIN
|
|
548
|
+
UPDATE public.customers SET twinfield_sync_error = 'Synchronisatie met Twinfield kon niet worden ingepland: ' || SQLERRM WHERE id = NEW.id;
|
|
549
|
+
EXCEPTION WHEN OTHERS THEN NULL; END;
|
|
550
|
+
RETURN NEW;
|
|
551
|
+
END;
|
|
552
|
+
END$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.enqueue_twinfield_push() RETURNS trigger LANGUAGE plpgsql SECURITY');
|
|
553
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.floriday_effective_price(_buyer_id text, _trade_item_id text, _on_date date DEFAULT CURRENT_DATE, _quantity numeric DEFAULT 1)
|
|
554
|
+
RETURNS TABLE(source text, net_price numeric, base_price numeric, discount_type text, discount_value numeric, currency text, source_id text)
|
|
555
|
+
LANGUAGE sql
|
|
556
|
+
STABLE SECURITY DEFINER
|
|
557
|
+
SET search_path TO 'public'
|
|
558
|
+
AS $function$
|
|
559
|
+
SELECT d.source, d.net_price, d.base_price, d.discount_type, d.discount_value, d.currency, d.source_id
|
|
560
|
+
FROM public.floriday_customer_discounts d
|
|
561
|
+
WHERE d.buyer_organization_id = _buyer_id
|
|
562
|
+
AND d.trade_item_id = _trade_item_id
|
|
563
|
+
AND (d.valid_from IS NULL OR d.valid_from <= _on_date)
|
|
564
|
+
AND (d.valid_until IS NULL OR d.valid_until >= _on_date)
|
|
565
|
+
AND COALESCE(d.min_quantity, 0) <= _quantity
|
|
566
|
+
ORDER BY CASE d.source
|
|
567
|
+
WHEN 'agreement' THEN 1
|
|
568
|
+
WHEN 'sales_strategy' THEN 2
|
|
569
|
+
WHEN 'price_group' THEN 3
|
|
570
|
+
ELSE 4
|
|
571
|
+
END, d.net_price NULLS LAST
|
|
572
|
+
LIMIT 1;
|
|
573
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.floriday_effective_price(_buyer_id text, _trade_item_id text, _on_');
|
|
574
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.has_twinfield_link()
|
|
575
|
+
RETURNS boolean
|
|
576
|
+
LANGUAGE sql
|
|
577
|
+
STABLE SECURITY DEFINER
|
|
578
|
+
SET search_path TO 'public'
|
|
579
|
+
AS $function$
|
|
580
|
+
SELECT EXISTS (SELECT 1 FROM public.twinfield_connections WHERE is_active = true);
|
|
581
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.has_twinfield_link() RETURNS boolean LANGUAGE sql STABLE SECURITY ');
|
|
582
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.import_floriday_delivery_locations(_org_id text)
|
|
583
|
+
RETURNS integer
|
|
584
|
+
LANGUAGE plpgsql
|
|
585
|
+
SECURITY DEFINER
|
|
586
|
+
SET search_path TO 'public'
|
|
587
|
+
AS $function$
|
|
588
|
+
DECLARE _cid uuid; _n integer := 0; _l record; _a jsonb; _lid text;
|
|
589
|
+
BEGIN
|
|
590
|
+
SELECT id INTO _cid FROM customers WHERE floriday_organization_id = _org_id;
|
|
591
|
+
IF _cid IS NULL THEN RETURN 0; END IF;
|
|
592
|
+
FOR _l IN SELECT * FROM floriday_delivery_locations_cache
|
|
593
|
+
WHERE organization_id = _org_id AND COALESCE(is_deleted,false) = false LOOP
|
|
594
|
+
_a := COALESCE(_l.data->'address', _l.data->'physicalAddress', _l.data);
|
|
595
|
+
_lid := COALESCE(NULLIF(_l.floriday_id,''), _l.data->>'locationId', _l.id::text);
|
|
596
|
+
IF EXISTS (SELECT 1 FROM customer_delivery_locations WHERE customer_id=_cid AND floriday_location_id=_lid) THEN
|
|
597
|
+
UPDATE customer_delivery_locations SET
|
|
598
|
+
gln = COALESCE(NULLIF(_l.gln_code,''), gln),
|
|
599
|
+
raw = _l.data, updated_at = now()
|
|
600
|
+
WHERE customer_id=_cid AND floriday_location_id=_lid;
|
|
601
|
+
ELSE
|
|
602
|
+
INSERT INTO customer_delivery_locations (customer_id, floriday_location_id, name, address_line, postal_code, city, country, gln, raw, external_provider, external_key)
|
|
603
|
+
VALUES (_cid, _lid,
|
|
604
|
+
COALESCE(NULLIF(_l.name,''), _l.data->>'name'),
|
|
605
|
+
NULLIF(_a->>'addressLine',''), NULLIF(_a->>'postalCode',''), NULLIF(_a->>'city',''),
|
|
606
|
+
NULLIF(_a->>'countryCode',''), NULLIF(_l.gln_code,''), _l.data, 'floriday', _lid);
|
|
607
|
+
_n := _n + 1;
|
|
608
|
+
END IF;
|
|
609
|
+
END LOOP;
|
|
610
|
+
RETURN _n;
|
|
611
|
+
END; $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.import_floriday_delivery_locations(_org_id text) RETURNS integer L');
|
|
612
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_install_check()
|
|
613
|
+
RETURNS jsonb
|
|
614
|
+
LANGUAGE plpgsql
|
|
615
|
+
STABLE SECURITY DEFINER
|
|
616
|
+
SET search_path TO 'public'
|
|
617
|
+
AS $function$
|
|
618
|
+
DECLARE _missing text[] := '{}'; _o text; _res jsonb := '{}'::jsonb;
|
|
619
|
+
BEGIN
|
|
620
|
+
FOREACH _o IN ARRAY ARRAY['customers','customer_delivery_locations','customer_match_suggestions','floriday_customers_cache',
|
|
621
|
+
'floriday_connections','floriday_connections_cache','orders','app_settings','external_customers_grouped'] LOOP
|
|
622
|
+
IF to_regclass('public.'||_o) IS NULL THEN _missing := _missing || _o; END IF;
|
|
623
|
+
END LOOP;
|
|
624
|
+
FOREACH _o IN ARRAY ARRAY['promote_floriday_customer','floriday_customer_candidates','promote_floriday_order_customers',
|
|
625
|
+
'import_floriday_delivery_locations','refresh_external_customers_grouped','enqueue_twinfield_push'] LOOP
|
|
626
|
+
IF NOT EXISTS (SELECT 1 FROM pg_proc WHERE proname=_o AND pronamespace='public'::regnamespace) THEN _missing := _missing || (_o||'()'); END IF;
|
|
627
|
+
END LOOP;
|
|
628
|
+
_res := jsonb_build_object('ontbreekt', to_jsonb(_missing),
|
|
629
|
+
'cron_promote', EXISTS (SELECT 1 FROM pg_extension WHERE extname='pg_cron'));
|
|
630
|
+
IF array_length(_missing,1) IS NULL THEN
|
|
631
|
+
_res := _res || jsonb_build_object(
|
|
632
|
+
'klanten', (SELECT count(*) FROM customers),
|
|
633
|
+
'actieve_koppelingen', (SELECT count(*) FROM floriday_connections WHERE is_active),
|
|
634
|
+
'inkooprelaties_actief', (SELECT count(*) FROM floriday_connections_cache cc JOIN floriday_connections fc ON fc.id=cc.connection_id AND fc.is_active
|
|
635
|
+
WHERE COALESCE(cc.data->>'isDeleted','false')='false'),
|
|
636
|
+
'floriday_organisaties', (SELECT count(*) FROM floriday_customers_cache WHERE COALESCE(is_deleted,false)=false),
|
|
637
|
+
'floriday_orders_zonder_klant', (SELECT count(*) FROM orders WHERE customer_id IS NULL AND NULLIF(custom_fields->>'floriday_customer_id','') IS NOT NULL),
|
|
638
|
+
'droog', floriday_customer_promotion_preview());
|
|
639
|
+
END IF;
|
|
640
|
+
RETURN _res;
|
|
641
|
+
END;
|
|
642
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_install_check() RETURNS jsonb LANGUAGE plpgsql STABLE SECU');
|
|
643
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.local_effective_price(_customer_id uuid, _product_id uuid, _on_date date DEFAULT CURRENT_DATE, _quantity numeric DEFAULT 1)
|
|
644
|
+
RETURNS TABLE(source text, source_id uuid, net_price numeric, discount_type text, discount_value numeric, currency text)
|
|
645
|
+
LANGUAGE sql
|
|
646
|
+
STABLE SECURITY DEFINER
|
|
647
|
+
SET search_path TO 'public'
|
|
648
|
+
AS $function$
|
|
649
|
+
WITH candidates AS (
|
|
650
|
+
SELECT 1 AS prio, d.source, d.source_id, d.net_price, d.discount_type, d.discount_value, d.currency, d.min_quantity
|
|
651
|
+
FROM public.local_customer_discounts d
|
|
652
|
+
WHERE d.customer_id = _customer_id AND d.source = 'agreement'
|
|
653
|
+
AND d.product_id = _product_id
|
|
654
|
+
AND (d.valid_from IS NULL OR d.valid_from <= _on_date)
|
|
655
|
+
AND (d.valid_until IS NULL OR d.valid_until >= _on_date)
|
|
656
|
+
AND _quantity >= d.min_quantity
|
|
657
|
+
UNION ALL
|
|
658
|
+
SELECT 2, d.source, d.source_id, d.net_price, d.discount_type, d.discount_value, d.currency, d.min_quantity
|
|
659
|
+
FROM public.local_customer_discounts d
|
|
660
|
+
WHERE d.customer_id = _customer_id AND d.source = 'sales_strategy'
|
|
661
|
+
AND d.product_id = _product_id
|
|
662
|
+
AND (d.valid_from IS NULL OR d.valid_from <= _on_date)
|
|
663
|
+
AND (d.valid_until IS NULL OR d.valid_until >= _on_date)
|
|
664
|
+
AND _quantity >= d.min_quantity
|
|
665
|
+
UNION ALL
|
|
666
|
+
SELECT 3, d.source, d.source_id, d.net_price, d.discount_type, d.discount_value, d.currency, d.min_quantity
|
|
667
|
+
FROM public.local_customer_discounts d
|
|
668
|
+
WHERE d.customer_id = _customer_id AND d.source = 'price_group'
|
|
669
|
+
AND d.product_id = _product_id
|
|
670
|
+
AND (d.valid_from IS NULL OR d.valid_from <= _on_date)
|
|
671
|
+
AND (d.valid_until IS NULL OR d.valid_until >= _on_date)
|
|
672
|
+
AND _quantity >= d.min_quantity
|
|
673
|
+
)
|
|
674
|
+
SELECT c.source, c.source_id, c.net_price, c.discount_type, c.discount_value, c.currency
|
|
675
|
+
FROM candidates c
|
|
676
|
+
ORDER BY c.prio ASC, c.min_quantity DESC
|
|
677
|
+
LIMIT 1;
|
|
678
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.local_effective_price(_customer_id uuid, _product_id uuid, _on_dat');
|
|
679
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.log_customer_changes()
|
|
680
|
+
RETURNS trigger
|
|
681
|
+
LANGUAGE plpgsql
|
|
682
|
+
SECURITY DEFINER
|
|
683
|
+
SET search_path TO 'public'
|
|
684
|
+
AS $function$
|
|
685
|
+
DECLARE
|
|
686
|
+
v_user uuid;
|
|
687
|
+
v_changes jsonb := '{}'::jsonb;
|
|
688
|
+
v_key text;
|
|
689
|
+
BEGIN
|
|
690
|
+
v_user := auth.uid();
|
|
691
|
+
|
|
692
|
+
IF TG_OP = 'INSERT' THEN
|
|
693
|
+
INSERT INTO public.customer_audit_log (customer_id, user_id, action, changes)
|
|
694
|
+
VALUES (NEW.id, v_user, 'insert', to_jsonb(NEW));
|
|
695
|
+
RETURN NEW;
|
|
696
|
+
ELSIF TG_OP = 'UPDATE' THEN
|
|
697
|
+
FOR v_key IN
|
|
698
|
+
SELECT key FROM jsonb_each(to_jsonb(NEW))
|
|
699
|
+
WHERE to_jsonb(NEW) -> key IS DISTINCT FROM to_jsonb(OLD) -> key
|
|
700
|
+
LOOP
|
|
701
|
+
v_changes := v_changes || jsonb_build_object(
|
|
702
|
+
v_key,
|
|
703
|
+
jsonb_build_object('old', to_jsonb(OLD) -> v_key, 'new', to_jsonb(NEW) -> v_key)
|
|
704
|
+
);
|
|
705
|
+
END LOOP;
|
|
706
|
+
IF v_changes <> '{}'::jsonb THEN
|
|
707
|
+
INSERT INTO public.customer_audit_log (customer_id, user_id, action, changes)
|
|
708
|
+
VALUES (NEW.id, v_user, 'update', v_changes);
|
|
709
|
+
END IF;
|
|
710
|
+
RETURN NEW;
|
|
711
|
+
ELSIF TG_OP = 'DELETE' THEN
|
|
712
|
+
INSERT INTO public.customer_audit_log (customer_id, user_id, action, changes)
|
|
713
|
+
VALUES (OLD.id, v_user, 'delete', to_jsonb(OLD));
|
|
714
|
+
RETURN OLD;
|
|
715
|
+
END IF;
|
|
716
|
+
RETURN NULL;
|
|
717
|
+
END;
|
|
718
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.log_customer_changes() RETURNS trigger LANGUAGE plpgsql SECURITY D');
|
|
719
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.next_twinfield_code()
|
|
720
|
+
RETURNS text
|
|
721
|
+
LANGUAGE plpgsql
|
|
722
|
+
SECURITY DEFINER
|
|
723
|
+
SET search_path TO 'public'
|
|
724
|
+
AS $function$
|
|
725
|
+
DECLARE
|
|
726
|
+
n bigint;
|
|
727
|
+
BEGIN
|
|
728
|
+
n := nextval('public.twinfield_customer_code_seq');
|
|
729
|
+
RETURN 'KL' || lpad(n::text, 5, '0');
|
|
730
|
+
END$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.next_twinfield_code() RETURNS text LANGUAGE plpgsql SECURITY DEFIN');
|
|
731
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.promote_floriday_customer(_org_id text)
|
|
732
|
+
RETURNS uuid
|
|
733
|
+
LANGUAGE plpgsql
|
|
734
|
+
SECURITY DEFINER
|
|
735
|
+
SET search_path TO 'public'
|
|
736
|
+
AS $function$
|
|
737
|
+
DECLARE _id uuid; _c record; _addr jsonb; _gln text; _hits int;
|
|
738
|
+
BEGIN
|
|
739
|
+
IF _org_id IS NULL OR btrim(_org_id) = '' THEN
|
|
740
|
+
RAISE EXCEPTION 'Geen Floriday-organisatienummer opgegeven';
|
|
741
|
+
END IF;
|
|
742
|
+
SELECT id INTO _id FROM customers WHERE floriday_organization_id = _org_id;
|
|
743
|
+
IF _id IS NOT NULL THEN
|
|
744
|
+
SELECT * INTO _c FROM floriday_customers_cache
|
|
745
|
+
WHERE organization_id = _org_id AND COALESCE(is_deleted, false) = false
|
|
746
|
+
ORDER BY fetched_at DESC NULLS LAST LIMIT 1;
|
|
747
|
+
IF FOUND THEN
|
|
748
|
+
_addr := COALESCE(_c.data->'physicalAddress', _c.data->'mailingAddress', '{}'::jsonb);
|
|
749
|
+
_gln := COALESCE(NULLIF(btrim(_c.gln_code),''), NULLIF(btrim(_c.data->>'companyGln'),''));
|
|
750
|
+
PERFORM set_config('app.skip_twinfield_push', 'on', true);
|
|
751
|
+
UPDATE customers SET
|
|
752
|
+
commercial_name = COALESCE(NULLIF(commercial_name,''), NULLIF(_c.data->>'commercialName','')),
|
|
753
|
+
street = COALESCE(NULLIF(street,''), NULLIF(_addr->>'addressLine','')),
|
|
754
|
+
postal_code = COALESCE(NULLIF(postal_code,''), NULLIF(_addr->>'postalCode','')),
|
|
755
|
+
city = COALESCE(NULLIF(city,''), NULLIF(_addr->>'city','')),
|
|
756
|
+
country = COALESCE(NULLIF(country,''), NULLIF(_addr->>'countryCode','')),
|
|
757
|
+
gln = COALESCE(NULLIF(gln,''), _gln),
|
|
758
|
+
logo_url = COALESCE(NULLIF(logo_url,''), NULLIF(_c.data->>'logoUrl','')),
|
|
759
|
+
website = COALESCE(NULLIF(website,''), NULLIF(_c.data->>'website','')),
|
|
760
|
+
floriday_connection_id = COALESCE(floriday_connection_id, _c.connection_id),
|
|
761
|
+
floriday_raw = COALESCE(floriday_raw, _c.data)
|
|
762
|
+
WHERE id = _id
|
|
763
|
+
AND (NULLIF(commercial_name,'') IS NULL OR NULLIF(street,'') IS NULL OR NULLIF(postal_code,'') IS NULL
|
|
764
|
+
OR NULLIF(city,'') IS NULL OR NULLIF(country,'') IS NULL OR NULLIF(gln,'') IS NULL
|
|
765
|
+
OR NULLIF(logo_url,'') IS NULL OR NULLIF(website,'') IS NULL
|
|
766
|
+
OR floriday_connection_id IS NULL OR floriday_raw IS NULL);
|
|
767
|
+
PERFORM set_config('app.skip_twinfield_push', '', true);
|
|
768
|
+
IF NOT EXISTS (SELECT 1 FROM customer_delivery_locations WHERE customer_id = _id) THEN
|
|
769
|
+
PERFORM public.import_floriday_delivery_locations(_org_id);
|
|
770
|
+
END IF;
|
|
771
|
+
END IF;
|
|
772
|
+
RETURN _id;
|
|
773
|
+
END IF;
|
|
774
|
+
SELECT * INTO _c FROM floriday_customers_cache
|
|
775
|
+
WHERE organization_id = _org_id AND COALESCE(is_deleted, false) = false
|
|
776
|
+
ORDER BY fetched_at DESC NULLS LAST LIMIT 1;
|
|
777
|
+
IF NOT FOUND THEN
|
|
778
|
+
RAISE EXCEPTION 'Floriday-organisatie % staat niet in de Floriday-gegevens; geen klant aangemaakt', _org_id;
|
|
779
|
+
END IF;
|
|
780
|
+
_gln := COALESCE(NULLIF(btrim(_c.gln_code),''), NULLIF(btrim(_c.data->>'companyGln'),''));
|
|
781
|
+
IF _gln IS NOT NULL THEN
|
|
782
|
+
SELECT count(*) INTO _hits FROM customers WHERE btrim(gln) = _gln AND floriday_organization_id IS NULL;
|
|
783
|
+
IF _hits = 1 THEN
|
|
784
|
+
UPDATE customers SET floriday_organization_id = _org_id,
|
|
785
|
+
floriday_connection_id = COALESCE(floriday_connection_id, _c.connection_id),
|
|
786
|
+
floriday_raw = COALESCE(floriday_raw, _c.data),
|
|
787
|
+
custom_fields = COALESCE(custom_fields,'{}'::jsonb) || jsonb_build_object('floriday_linked_by','gln','floriday_linked_at', now())
|
|
788
|
+
WHERE btrim(gln) = _gln AND floriday_organization_id IS NULL
|
|
789
|
+
RETURNING id INTO _id;
|
|
790
|
+
RETURN _id;
|
|
791
|
+
ELSIF _hits > 1 THEN
|
|
792
|
+
INSERT INTO customer_match_suggestions(floriday_organization_id, customer_id, reason)
|
|
793
|
+
SELECT _org_id, id, 'gln' FROM customers WHERE btrim(gln) = _gln AND floriday_organization_id IS NULL
|
|
794
|
+
ON CONFLICT DO NOTHING;
|
|
795
|
+
END IF;
|
|
796
|
+
END IF;
|
|
797
|
+
_addr := COALESCE(_c.data->'physicalAddress', _c.data->'mailingAddress', '{}'::jsonb);
|
|
798
|
+
INSERT INTO customers (
|
|
799
|
+
company_name, commercial_name, street, postal_code, city, country, gln, logo_url, website,
|
|
800
|
+
floriday_organization_id, floriday_connection_id, floriday_raw, custom_fields, source, twinfield_create_on_insert
|
|
801
|
+
) VALUES (
|
|
802
|
+
COALESCE(NULLIF(_c.data->>'name',''), NULLIF(_c.name,''), NULLIF(_c.data->>'commercialName',''), 'Floriday-organisatie ' || left(_org_id, 8)),
|
|
803
|
+
NULLIF(_c.data->>'commercialName',''),
|
|
804
|
+
NULLIF(_addr->>'addressLine',''), NULLIF(_addr->>'postalCode',''), NULLIF(_addr->>'city',''),
|
|
805
|
+
NULLIF(_addr->>'countryCode',''),
|
|
806
|
+
_gln, NULLIF(_c.data->>'logoUrl',''), NULLIF(_c.data->>'website',''),
|
|
807
|
+
_org_id, _c.connection_id, _c.data,
|
|
808
|
+
jsonb_strip_nulls(jsonb_build_object(
|
|
809
|
+
'rfh_relation_id', _c.data->>'rfhRelationId',
|
|
810
|
+
'rfh_company_account_id', _c.data->>'rfhCompanyAccountId',
|
|
811
|
+
'plantion_registration_number', _c.data->>'plantionRegistrationNumber',
|
|
812
|
+
'floriday_payment_providers', _c.data->'paymentProviders',
|
|
813
|
+
'promoted_from_floriday_at', now(),
|
|
814
|
+
'promoted_reason', NULLIF(current_setting('app.promote_reason', true), '')
|
|
815
|
+
)),
|
|
816
|
+
'floriday', false
|
|
817
|
+
)
|
|
818
|
+
ON CONFLICT (floriday_organization_id) DO NOTHING
|
|
819
|
+
RETURNING id INTO _id;
|
|
820
|
+
IF _id IS NULL THEN
|
|
821
|
+
SELECT id INTO _id FROM customers WHERE floriday_organization_id = _org_id;
|
|
822
|
+
ELSE
|
|
823
|
+
PERFORM public.import_floriday_delivery_locations(_org_id);
|
|
824
|
+
END IF;
|
|
825
|
+
RETURN _id;
|
|
826
|
+
END;
|
|
827
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.promote_floriday_customer(_org_id text) RETURNS uuid LANGUAGE plpg');
|
|
828
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.refresh_external_customers_grouped()
|
|
829
|
+
RETURNS void
|
|
830
|
+
LANGUAGE sql
|
|
831
|
+
SECURITY DEFINER
|
|
832
|
+
SET search_path TO 'public'
|
|
833
|
+
AS $function$
|
|
834
|
+
REFRESH MATERIALIZED VIEW CONCURRENTLY public.external_customers_grouped;
|
|
835
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.refresh_external_customers_grouped() RETURNS void LANGUAGE sql SEC');
|
|
836
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.refresh_floriday_delivery_locations()
|
|
837
|
+
RETURNS integer
|
|
838
|
+
LANGUAGE plpgsql
|
|
839
|
+
SECURITY DEFINER
|
|
840
|
+
SET search_path TO 'public'
|
|
841
|
+
AS $function$
|
|
842
|
+
DECLARE _o text; _t integer := 0;
|
|
843
|
+
BEGIN
|
|
844
|
+
FOR _o IN SELECT floriday_organization_id FROM customers WHERE floriday_organization_id IS NOT NULL LOOP
|
|
845
|
+
BEGIN _t := _t + public.import_floriday_delivery_locations(_o);
|
|
846
|
+
EXCEPTION WHEN OTHERS THEN RAISE WARNING 'locaties % mislukt: %', _o, SQLERRM; END;
|
|
847
|
+
END LOOP;
|
|
848
|
+
RETURN _t;
|
|
849
|
+
END; $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.refresh_floriday_delivery_locations() RETURNS integer LANGUAGE plp');
|
|
850
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.reorder_customer_price_groups(_ids uuid[])
|
|
851
|
+
RETURNS void
|
|
852
|
+
LANGUAGE plpgsql
|
|
853
|
+
SECURITY DEFINER
|
|
854
|
+
SET search_path TO 'public'
|
|
855
|
+
AS $function$
|
|
856
|
+
DECLARE
|
|
857
|
+
_uid UUID := auth.uid();
|
|
858
|
+
_id UUID;
|
|
859
|
+
_idx INT := 0;
|
|
860
|
+
BEGIN
|
|
861
|
+
IF _uid IS NULL THEN
|
|
862
|
+
RAISE EXCEPTION 'Not authenticated';
|
|
863
|
+
END IF;
|
|
864
|
+
FOREACH _id IN ARRAY _ids LOOP
|
|
865
|
+
_idx := _idx + 1;
|
|
866
|
+
UPDATE public.customer_price_groups
|
|
867
|
+
SET sort_order = _idx, updated_at = now()
|
|
868
|
+
WHERE id = _id AND owner_id = _uid;
|
|
869
|
+
END LOOP;
|
|
870
|
+
END;
|
|
871
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.reorder_customer_price_groups(_ids uuid[]) RETURNS void LANGUAGE p');
|
|
872
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.retry_twinfield_push(_customer_id uuid)
|
|
873
|
+
RETURNS integer
|
|
874
|
+
LANGUAGE plpgsql
|
|
875
|
+
SECURITY DEFINER
|
|
876
|
+
SET search_path TO 'public'
|
|
877
|
+
AS $function$
|
|
878
|
+
DECLARE
|
|
879
|
+
n int;
|
|
880
|
+
BEGIN
|
|
881
|
+
UPDATE public.twinfield_push_queue
|
|
882
|
+
SET status = 'pending',
|
|
883
|
+
attempts = 0,
|
|
884
|
+
next_attempt_at = now(),
|
|
885
|
+
last_error = NULL,
|
|
886
|
+
updated_at = now()
|
|
887
|
+
WHERE customer_id = _customer_id
|
|
888
|
+
AND status IN ('failed', 'dead');
|
|
889
|
+
GET DIAGNOSTICS n = ROW_COUNT;
|
|
890
|
+
RETURN n;
|
|
891
|
+
END$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.retry_twinfield_push(_customer_id uuid) RETURNS integer LANGUAGE p');
|
|
892
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.run_twinfield_queue_tick()
|
|
893
|
+
RETURNS void
|
|
894
|
+
LANGUAGE plpgsql
|
|
895
|
+
SECURITY DEFINER
|
|
896
|
+
SET search_path TO 'public'
|
|
897
|
+
AS $function$
|
|
898
|
+
DECLARE
|
|
899
|
+
v_url text;
|
|
900
|
+
v_apikey text;
|
|
901
|
+
BEGIN
|
|
902
|
+
SELECT value INTO v_url FROM public.app_settings WHERE key = 'twinfield_queue_url';
|
|
903
|
+
SELECT value INTO v_apikey FROM public.app_settings WHERE key = 'twinfield_queue_apikey';
|
|
904
|
+
|
|
905
|
+
IF v_url IS NULL OR btrim(v_url) = '' OR v_apikey IS NULL OR btrim(v_apikey) = '' THEN
|
|
906
|
+
RETURN;
|
|
907
|
+
END IF;
|
|
908
|
+
|
|
909
|
+
IF NOT EXISTS (
|
|
910
|
+
SELECT 1 FROM public.twinfield_push_queue
|
|
911
|
+
WHERE status = 'pending' AND next_attempt_at <= now()
|
|
912
|
+
) THEN
|
|
913
|
+
RETURN;
|
|
914
|
+
END IF;
|
|
915
|
+
|
|
916
|
+
PERFORM net.http_post(
|
|
917
|
+
url := v_url,
|
|
918
|
+
headers := jsonb_build_object('Content-Type', 'application/json', 'apikey', v_apikey),
|
|
919
|
+
body := '{}'::jsonb
|
|
920
|
+
);
|
|
921
|
+
END$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.run_twinfield_queue_tick() RETURNS void LANGUAGE plpgsql SECURITY ');
|
|
922
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.schedule_floriday_network_sync(p_url text, p_apikey text)
|
|
923
|
+
RETURNS bigint
|
|
924
|
+
LANGUAGE plpgsql
|
|
925
|
+
SECURITY DEFINER
|
|
926
|
+
SET search_path TO 'public'
|
|
927
|
+
AS $function$
|
|
928
|
+
DECLARE
|
|
929
|
+
v_jobname constant text := 'floriday-network-nightly-sync';
|
|
930
|
+
v_jobid bigint;
|
|
931
|
+
v_command text;
|
|
932
|
+
BEGIN
|
|
933
|
+
IF NOT public.has_role(auth.uid(), 'admin'::public.app_role) THEN
|
|
934
|
+
RAISE EXCEPTION 'Alleen admins mogen de Floriday-netwerk-cron instellen';
|
|
935
|
+
END IF;
|
|
936
|
+
|
|
937
|
+
IF p_url IS NULL OR length(p_url) = 0 OR p_apikey IS NULL OR length(p_apikey) = 0 THEN
|
|
938
|
+
RAISE EXCEPTION 'p_url en p_apikey zijn verplicht';
|
|
939
|
+
END IF;
|
|
940
|
+
|
|
941
|
+
PERFORM pg_advisory_xact_lock(hashtext('floriday-network-cron-schedule'));
|
|
942
|
+
|
|
943
|
+
BEGIN
|
|
944
|
+
PERFORM cron.unschedule(v_jobname);
|
|
945
|
+
EXCEPTION WHEN OTHERS THEN
|
|
946
|
+
NULL;
|
|
947
|
+
END;
|
|
948
|
+
|
|
949
|
+
v_command := format(
|
|
950
|
+
$cmd$SELECT net.http_post(url := %L, headers := %L::jsonb, body := '{}'::jsonb);$cmd$,
|
|
951
|
+
p_url,
|
|
952
|
+
json_build_object(
|
|
953
|
+
'Content-Type', 'application/json',
|
|
954
|
+
'apikey', p_apikey
|
|
955
|
+
)::text
|
|
956
|
+
);
|
|
957
|
+
|
|
958
|
+
v_jobid := cron.schedule(v_jobname, '0 3 * * *', v_command);
|
|
959
|
+
RETURN v_jobid;
|
|
960
|
+
END;
|
|
961
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.schedule_floriday_network_sync(p_url text, p_apikey text) RETURNS ');
|
|
962
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.server_now()
|
|
963
|
+
RETURNS timestamp with time zone
|
|
964
|
+
LANGUAGE sql
|
|
965
|
+
STABLE
|
|
966
|
+
SET search_path TO 'public'
|
|
967
|
+
AS $function$ SELECT now() $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.server_now() RETURNS timestamp with time zone LANGUAGE sql STABLE ');
|
|
968
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.set_primary_delivery_location(p_location_id uuid)
|
|
969
|
+
RETURNS void
|
|
970
|
+
LANGUAGE plpgsql
|
|
971
|
+
SET search_path TO 'public'
|
|
972
|
+
AS $function$
|
|
973
|
+
DECLARE v_cust uuid; v_group text;
|
|
974
|
+
BEGIN
|
|
975
|
+
SELECT customer_id, group_key INTO v_cust, v_group FROM customer_delivery_locations WHERE id = p_location_id;
|
|
976
|
+
IF NOT FOUND THEN RAISE EXCEPTION 'Locatie niet gevonden'; END IF;
|
|
977
|
+
IF v_cust IS NOT NULL THEN
|
|
978
|
+
UPDATE customer_delivery_locations SET is_primary = false WHERE customer_id = v_cust AND is_primary AND id <> p_location_id;
|
|
979
|
+
ELSIF v_group IS NOT NULL THEN
|
|
980
|
+
UPDATE customer_delivery_locations SET is_primary = false WHERE customer_id IS NULL AND group_key = v_group AND is_primary AND id <> p_location_id;
|
|
981
|
+
END IF;
|
|
982
|
+
UPDATE customer_delivery_locations SET is_primary = true WHERE id = p_location_id;
|
|
983
|
+
END $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.set_primary_delivery_location(p_location_id uuid) RETURNS void LAN');
|
|
984
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.sync_floriday_prices_into_price_groups()
|
|
985
|
+
RETURNS integer
|
|
986
|
+
LANGUAGE plpgsql
|
|
987
|
+
SECURITY DEFINER
|
|
988
|
+
SET search_path TO 'public'
|
|
989
|
+
AS $function$
|
|
990
|
+
DECLARE
|
|
991
|
+
v_count integer := 0;
|
|
992
|
+
BEGIN
|
|
993
|
+
WITH fd AS (
|
|
994
|
+
SELECT
|
|
995
|
+
c.floriday_id::text AS fd_price_group_id,
|
|
996
|
+
COALESCE(c.data->>'currency', 'EUR') AS currency,
|
|
997
|
+
COALESCE(cust.value #>> '{}', NULL) AS fd_customer_id,
|
|
998
|
+
line
|
|
999
|
+
FROM public.floriday_price_groups_cache c
|
|
1000
|
+
LEFT JOIN LATERAL jsonb_array_elements(
|
|
1001
|
+
COALESCE(c.data->'customers', '[]'::jsonb)
|
|
1002
|
+
) AS cust ON true
|
|
1003
|
+
CROSS JOIN LATERAL jsonb_array_elements(
|
|
1004
|
+
COALESCE(
|
|
1005
|
+
c.data->'priceGroupLines',
|
|
1006
|
+
c.data->'tradeItemPrices',
|
|
1007
|
+
c.data->'lines',
|
|
1008
|
+
c.data->'priceLines',
|
|
1009
|
+
'[]'::jsonb
|
|
1010
|
+
)
|
|
1011
|
+
) AS line
|
|
1012
|
+
WHERE COALESCE(c.is_deleted, false) = false
|
|
1013
|
+
),
|
|
1014
|
+
resolved AS (
|
|
1015
|
+
SELECT
|
|
1016
|
+
g.id AS price_group_id,
|
|
1017
|
+
g.owner_id,
|
|
1018
|
+
COALESCE(NULLIF(fd.currency, ''), g.currency, 'EUR') AS currency,
|
|
1019
|
+
'product:' || COALESCE(
|
|
1020
|
+
fd.line->>'tradeItemId',
|
|
1021
|
+
fd.line#>>'{tradeItem,tradeItemId}',
|
|
1022
|
+
fd.line->>'id'
|
|
1023
|
+
) AS trade_item_key,
|
|
1024
|
+
COALESCE(
|
|
1025
|
+
(fd.line->>'price')::numeric,
|
|
1026
|
+
(fd.line->>'amount')::numeric,
|
|
1027
|
+
(fd.line->>'unitPrice')::numeric
|
|
1028
|
+
) AS price_per_piece
|
|
1029
|
+
FROM fd
|
|
1030
|
+
JOIN public.customer_price_groups g
|
|
1031
|
+
ON (g.source = 'floriday' AND g.external_id = fd.fd_price_group_id)
|
|
1032
|
+
OR EXISTS (
|
|
1033
|
+
SELECT 1
|
|
1034
|
+
FROM public.customer_price_group_members m
|
|
1035
|
+
JOIN public.external_customers_grouped ecg
|
|
1036
|
+
ON ecg.group_key = m.customer_key
|
|
1037
|
+
WHERE m.price_group_id = g.id
|
|
1038
|
+
AND fd.fd_customer_id IS NOT NULL
|
|
1039
|
+
AND EXISTS (
|
|
1040
|
+
SELECT 1
|
|
1041
|
+
FROM jsonb_array_elements(COALESCE(to_jsonb(ecg.sources), '[]'::jsonb)) s
|
|
1042
|
+
WHERE s->>'provider' = 'floriday'
|
|
1043
|
+
AND s->>'external_id' = fd.fd_customer_id
|
|
1044
|
+
)
|
|
1045
|
+
)
|
|
1046
|
+
WHERE COALESCE(g.is_active, true) = true
|
|
1047
|
+
AND g.owner_id IS NOT NULL
|
|
1048
|
+
),
|
|
1049
|
+
clean AS (
|
|
1050
|
+
SELECT DISTINCT ON (price_group_id, trade_item_key)
|
|
1051
|
+
price_group_id, owner_id, currency, trade_item_key, price_per_piece
|
|
1052
|
+
FROM resolved
|
|
1053
|
+
WHERE price_per_piece IS NOT NULL
|
|
1054
|
+
AND trade_item_key <> 'product:'
|
|
1055
|
+
ORDER BY price_group_id, trade_item_key, price_per_piece
|
|
1056
|
+
),
|
|
1057
|
+
upserted AS (
|
|
1058
|
+
INSERT INTO public.trade_item_prices
|
|
1059
|
+
(user_id, price_group_id, trade_item_key, price_per_piece, currency)
|
|
1060
|
+
SELECT owner_id, price_group_id, trade_item_key, price_per_piece, currency
|
|
1061
|
+
FROM clean
|
|
1062
|
+
ON CONFLICT (price_group_id, trade_item_key) WHERE price_group_id IS NOT NULL
|
|
1063
|
+
DO UPDATE SET
|
|
1064
|
+
price_per_piece = EXCLUDED.price_per_piece,
|
|
1065
|
+
currency = EXCLUDED.currency,
|
|
1066
|
+
updated_at = now()
|
|
1067
|
+
WHERE public.trade_item_prices.price_per_piece IS DISTINCT FROM EXCLUDED.price_per_piece
|
|
1068
|
+
OR public.trade_item_prices.currency IS DISTINCT FROM EXCLUDED.currency
|
|
1069
|
+
RETURNING 1
|
|
1070
|
+
)
|
|
1071
|
+
SELECT count(*) INTO v_count FROM upserted;
|
|
1072
|
+
|
|
1073
|
+
RETURN v_count;
|
|
1074
|
+
END;
|
|
1075
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.sync_floriday_prices_into_price_groups() RETURNS integer LANGUAGE ');
|
|
1076
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.tg_customer_price_groups_touch()
|
|
1077
|
+
RETURNS trigger
|
|
1078
|
+
LANGUAGE plpgsql
|
|
1079
|
+
SET search_path TO 'public'
|
|
1080
|
+
AS $function$
|
|
1081
|
+
BEGIN
|
|
1082
|
+
NEW.updated_at = now();
|
|
1083
|
+
RETURN NEW;
|
|
1084
|
+
END;
|
|
1085
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.tg_customer_price_groups_touch() RETURNS trigger LANGUAGE plpgsql ');
|
|
1086
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.trg_floriday_delivery_location_import()
|
|
1087
|
+
RETURNS trigger
|
|
1088
|
+
LANGUAGE plpgsql
|
|
1089
|
+
SECURITY DEFINER
|
|
1090
|
+
SET search_path TO 'public'
|
|
1091
|
+
AS $function$
|
|
1092
|
+
BEGIN
|
|
1093
|
+
IF NEW.organization_id IS NOT NULL THEN
|
|
1094
|
+
BEGIN PERFORM public.import_floriday_delivery_locations(NEW.organization_id);
|
|
1095
|
+
EXCEPTION WHEN OTHERS THEN RAISE WARNING 'locatie-import mislukt: %', SQLERRM; END;
|
|
1096
|
+
END IF;
|
|
1097
|
+
RETURN NEW;
|
|
1098
|
+
END; $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.trg_floriday_delivery_location_import() RETURNS trigger LANGUAGE p');
|
|
1099
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.trg_refresh_external_customers_grouped()
|
|
1100
|
+
RETURNS trigger
|
|
1101
|
+
LANGUAGE plpgsql
|
|
1102
|
+
SECURITY DEFINER
|
|
1103
|
+
SET search_path TO 'public'
|
|
1104
|
+
AS $function$
|
|
1105
|
+
BEGIN
|
|
1106
|
+
IF pg_try_advisory_xact_lock(hashtext('refresh_external_customers_grouped')) THEN
|
|
1107
|
+
BEGIN
|
|
1108
|
+
REFRESH MATERIALIZED VIEW CONCURRENTLY public.external_customers_grouped;
|
|
1109
|
+
EXCEPTION WHEN OTHERS THEN
|
|
1110
|
+
REFRESH MATERIALIZED VIEW public.external_customers_grouped;
|
|
1111
|
+
END;
|
|
1112
|
+
PERFORM pg_notify('external_customers_changed', '');
|
|
1113
|
+
END IF;
|
|
1114
|
+
RETURN NULL;
|
|
1115
|
+
END;
|
|
1116
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.trg_refresh_external_customers_grouped() RETURNS trigger LANGUAGE ');
|
|
1117
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.twinfield_sync_apply(_customer_id uuid, _patch jsonb, _base jsonb, _version integer, _uid text)
|
|
1118
|
+
RETURNS void
|
|
1119
|
+
LANGUAGE plpgsql
|
|
1120
|
+
SECURITY DEFINER
|
|
1121
|
+
SET search_path TO 'public'
|
|
1122
|
+
AS $function$
|
|
1123
|
+
DECLARE k text; v jsonb; sets text := '';
|
|
1124
|
+
BEGIN
|
|
1125
|
+
PERFORM set_config('app.skip_twinfield_push', 'on', true);
|
|
1126
|
+
FOR k, v IN SELECT * FROM jsonb_each(coalesce(_patch, '{}'::jsonb)) LOOP
|
|
1127
|
+
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema='public' AND table_name='customers' AND column_name=k) THEN CONTINUE; END IF;
|
|
1128
|
+
sets := sets || format('%I = (jsonb_populate_record(NULL::public.customers, jsonb_build_object(%L, $1->%L))).%I, ', k, k, k, k);
|
|
1129
|
+
END LOOP;
|
|
1130
|
+
EXECUTE format('UPDATE public.customers SET %s twinfield_base_snapshot = $2, twinfield_base_version = $3, twinfield_uid = coalesce($4, twinfield_uid), twinfield_synced_at = now(), twinfield_present = true, twinfield_missing_since = NULL WHERE id = $5', sets)
|
|
1131
|
+
USING _patch, _base, _version, _uid, _customer_id;
|
|
1132
|
+
END $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.twinfield_sync_apply(_customer_id uuid, _patch jsonb, _base jsonb,');
|
|
1133
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.twinfield_sync_insert(_row jsonb)
|
|
1134
|
+
RETURNS uuid
|
|
1135
|
+
LANGUAGE plpgsql
|
|
1136
|
+
SECURITY DEFINER
|
|
1137
|
+
SET search_path TO 'public'
|
|
1138
|
+
AS $function$
|
|
1139
|
+
DECLARE new_id uuid; cols text; vals text;
|
|
1140
|
+
BEGIN
|
|
1141
|
+
PERFORM set_config('app.skip_twinfield_push', 'on', true);
|
|
1142
|
+
SELECT string_agg(format('%I', c.column_name), ', '),
|
|
1143
|
+
string_agg(format('(jsonb_populate_record(NULL::public.customers, $1)).%I', c.column_name), ', ')
|
|
1144
|
+
INTO cols, vals
|
|
1145
|
+
FROM information_schema.columns c
|
|
1146
|
+
WHERE c.table_schema='public' AND c.table_name='customers'
|
|
1147
|
+
AND _row ? c.column_name AND jsonb_typeof(_row->c.column_name) <> 'null';
|
|
1148
|
+
EXECUTE format('INSERT INTO public.customers (%s) VALUES (%s) RETURNING id', cols, vals) USING _row INTO new_id;
|
|
1149
|
+
RETURN new_id;
|
|
1150
|
+
END $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.twinfield_sync_insert(_row jsonb) RETURNS uuid LANGUAGE plpgsql SE');
|
|
1151
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.twinfield_sync_mark_missing(_ids uuid[])
|
|
1152
|
+
RETURNS void
|
|
1153
|
+
LANGUAGE plpgsql
|
|
1154
|
+
SECURITY DEFINER
|
|
1155
|
+
SET search_path TO 'public'
|
|
1156
|
+
AS $function$
|
|
1157
|
+
BEGIN
|
|
1158
|
+
PERFORM set_config('app.skip_twinfield_push', 'on', true);
|
|
1159
|
+
UPDATE public.customers SET twinfield_present = false, twinfield_missing_since = coalesce(twinfield_missing_since, now())
|
|
1160
|
+
WHERE id = ANY(_ids);
|
|
1161
|
+
END $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.twinfield_sync_mark_missing(_ids uuid[]) RETURNS void LANGUAGE plp');
|
|
1162
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.update_updated_at_column()
|
|
1163
|
+
RETURNS trigger
|
|
1164
|
+
LANGUAGE plpgsql
|
|
1165
|
+
SET search_path TO 'public'
|
|
1166
|
+
AS $function$ BEGIN NEW.updated_at = now(); RETURN NEW; END; $function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.update_updated_at_column() RETURNS trigger LANGUAGE plpgsql SET se');
|
|
1167
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.validate_twinfield_required_fields()
|
|
1168
|
+
RETURNS trigger
|
|
1169
|
+
LANGUAGE plpgsql
|
|
1170
|
+
SET search_path TO 'public'
|
|
1171
|
+
AS $function$
|
|
1172
|
+
BEGIN
|
|
1173
|
+
IF COALESCE(NEW.source, 'local') <> 'local' THEN
|
|
1174
|
+
RETURN NEW;
|
|
1175
|
+
END IF;
|
|
1176
|
+
IF NULLIF(btrim(COALESCE(NEW.company_name, '')), '') IS NULL THEN
|
|
1177
|
+
RAISE EXCEPTION 'Verplicht voor Twinfield: Bedrijfsnaam' USING ERRCODE = '23514';
|
|
1178
|
+
END IF;
|
|
1179
|
+
RETURN NEW;
|
|
1180
|
+
END$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.validate_twinfield_required_fields() RETURNS trigger LANGUAGE plpg');
|
|
1181
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE VIEW public.external_customers_unified AS
|
|
1182
|
+
SELECT v_external_customers_floriday.provider,
|
|
1183
|
+
v_external_customers_floriday.connection_id,
|
|
1184
|
+
v_external_customers_floriday.external_id,
|
|
1185
|
+
v_external_customers_floriday.company_name,
|
|
1186
|
+
v_external_customers_floriday.commercial_name,
|
|
1187
|
+
v_external_customers_floriday.contact_person,
|
|
1188
|
+
v_external_customers_floriday.email,
|
|
1189
|
+
v_external_customers_floriday.phone,
|
|
1190
|
+
v_external_customers_floriday.street,
|
|
1191
|
+
v_external_customers_floriday.house_number,
|
|
1192
|
+
v_external_customers_floriday.postal_code,
|
|
1193
|
+
v_external_customers_floriday.city,
|
|
1194
|
+
v_external_customers_floriday.country,
|
|
1195
|
+
v_external_customers_floriday.vat_number,
|
|
1196
|
+
v_external_customers_floriday.gln,
|
|
1197
|
+
v_external_customers_floriday.website,
|
|
1198
|
+
v_external_customers_floriday.logo_url,
|
|
1199
|
+
v_external_customers_floriday.status,
|
|
1200
|
+
v_external_customers_floriday.is_active,
|
|
1201
|
+
v_external_customers_floriday.is_deleted,
|
|
1202
|
+
v_external_customers_floriday.fetched_at,
|
|
1203
|
+
v_external_customers_floriday.raw,
|
|
1204
|
+
v_external_customers_floriday.changed_at
|
|
1205
|
+
FROM v_external_customers_floriday
|
|
1206
|
+
UNION ALL
|
|
1207
|
+
SELECT v_external_customers_twinfield.provider,
|
|
1208
|
+
v_external_customers_twinfield.connection_id,
|
|
1209
|
+
v_external_customers_twinfield.external_id,
|
|
1210
|
+
v_external_customers_twinfield.company_name,
|
|
1211
|
+
v_external_customers_twinfield.commercial_name,
|
|
1212
|
+
v_external_customers_twinfield.contact_person,
|
|
1213
|
+
v_external_customers_twinfield.email,
|
|
1214
|
+
v_external_customers_twinfield.phone,
|
|
1215
|
+
v_external_customers_twinfield.street,
|
|
1216
|
+
v_external_customers_twinfield.house_number,
|
|
1217
|
+
v_external_customers_twinfield.postal_code,
|
|
1218
|
+
v_external_customers_twinfield.city,
|
|
1219
|
+
v_external_customers_twinfield.country,
|
|
1220
|
+
v_external_customers_twinfield.vat_number,
|
|
1221
|
+
v_external_customers_twinfield.gln,
|
|
1222
|
+
v_external_customers_twinfield.website,
|
|
1223
|
+
v_external_customers_twinfield.logo_url,
|
|
1224
|
+
v_external_customers_twinfield.status,
|
|
1225
|
+
v_external_customers_twinfield.is_active,
|
|
1226
|
+
v_external_customers_twinfield.is_deleted,
|
|
1227
|
+
v_external_customers_twinfield.fetched_at,
|
|
1228
|
+
v_external_customers_twinfield.raw,
|
|
1229
|
+
v_external_customers_twinfield.changed_at
|
|
1230
|
+
FROM v_external_customers_twinfield
|
|
1231
|
+
UNION ALL
|
|
1232
|
+
SELECT v_external_customers_local.provider,
|
|
1233
|
+
v_external_customers_local.connection_id,
|
|
1234
|
+
v_external_customers_local.external_id,
|
|
1235
|
+
v_external_customers_local.company_name,
|
|
1236
|
+
v_external_customers_local.commercial_name,
|
|
1237
|
+
v_external_customers_local.contact_person,
|
|
1238
|
+
v_external_customers_local.email,
|
|
1239
|
+
v_external_customers_local.phone,
|
|
1240
|
+
v_external_customers_local.street,
|
|
1241
|
+
v_external_customers_local.house_number,
|
|
1242
|
+
v_external_customers_local.postal_code,
|
|
1243
|
+
v_external_customers_local.city,
|
|
1244
|
+
v_external_customers_local.country,
|
|
1245
|
+
v_external_customers_local.vat_number,
|
|
1246
|
+
v_external_customers_local.gln,
|
|
1247
|
+
v_external_customers_local.website,
|
|
1248
|
+
v_external_customers_local.logo_url,
|
|
1249
|
+
v_external_customers_local.status,
|
|
1250
|
+
v_external_customers_local.is_active,
|
|
1251
|
+
v_external_customers_local.is_deleted,
|
|
1252
|
+
v_external_customers_local.fetched_at,
|
|
1253
|
+
v_external_customers_local.raw,
|
|
1254
|
+
v_external_customers_local.changed_at
|
|
1255
|
+
FROM v_external_customers_local$klanten_stmt$, 'CREATE OR REPLACE VIEW public.external_customers_unified AS SELECT v_external_customers_floriday.pro');
|
|
1256
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE VIEW public.v_external_customers_floriday AS
|
|
1257
|
+
SELECT 'floriday'::text AS provider,
|
|
1258
|
+
c.connection_id,
|
|
1259
|
+
c.organization_id AS external_id,
|
|
1260
|
+
COALESCE(NULLIF(conn.buyer_organization_name, ''::text), NULLIF((c.data ->> 'company_name'::text), ''::text), NULLIF((c.data ->> 'organizationName'::text), ''::text), NULLIF((c.data ->> 'name'::text), ''::text), NULLIF((c.data ->> 'commercialName'::text), ''::text), ('Floriday-organisatie '::text || "left"(c.organization_id, 8))) AS company_name,
|
|
1261
|
+
COALESCE(NULLIF((c.data ->> 'commercial_name'::text), ''::text), NULLIF((c.data ->> 'commercialName'::text), ''::text)) AS commercial_name,
|
|
1262
|
+
COALESCE(NULLIF((c.data ->> 'contact_person'::text), ''::text), NULLIF((c.data #>> '{contactPerson,fullName}'::text[]), ''::text), NULLIF(TRIM(BOTH FROM ((COALESCE((c.data #>> '{contactPerson,firstName}'::text[]), ''::text) || ' '::text) || COALESCE((c.data #>> '{contactPerson,lastName}'::text[]), ''::text))), ''::text)) AS contact_person,
|
|
1263
|
+
COALESCE(NULLIF((c.data ->> 'email'::text), ''::text), NULLIF((c.data ->> 'emailAddress'::text), ''::text), NULLIF((c.data #>> '{contactInformation,email}'::text[]), ''::text), NULLIF((c.data #>> '{primaryContact,email}'::text[]), ''::text)) AS email,
|
|
1264
|
+
COALESCE(NULLIF((c.data ->> 'phone'::text), ''::text), NULLIF((c.data ->> 'phoneNumber'::text), ''::text), NULLIF((c.data #>> '{contactInformation,phoneNumber}'::text[]), ''::text)) AS phone,
|
|
1265
|
+
COALESCE(NULLIF((c.data ->> 'street'::text), ''::text), NULLIF((c.data #>> '{physicalAddress,streetName}'::text[]), ''::text), NULLIF((c.data #>> '{mailingAddress,streetName}'::text[]), ''::text)) AS street,
|
|
1266
|
+
COALESCE(NULLIF((c.data ->> 'house_number'::text), ''::text), NULLIF((c.data #>> '{physicalAddress,houseNumber}'::text[]), ''::text), NULLIF((c.data #>> '{mailingAddress,houseNumber}'::text[]), ''::text)) AS house_number,
|
|
1267
|
+
COALESCE(NULLIF((c.data ->> 'postal_code'::text), ''::text), NULLIF((c.data #>> '{physicalAddress,postalCode}'::text[]), ''::text), NULLIF((c.data #>> '{mailingAddress,postalCode}'::text[]), ''::text)) AS postal_code,
|
|
1268
|
+
COALESCE(NULLIF((c.data ->> 'city'::text), ''::text), NULLIF((c.data #>> '{physicalAddress,city}'::text[]), ''::text), NULLIF((c.data #>> '{mailingAddress,city}'::text[]), ''::text)) AS city,
|
|
1269
|
+
COALESCE(NULLIF((c.data ->> 'country'::text), ''::text), NULLIF((c.data #>> '{physicalAddress,countryCode}'::text[]), ''::text), NULLIF((c.data #>> '{mailingAddress,countryCode}'::text[]), ''::text)) AS country,
|
|
1270
|
+
COALESCE(NULLIF((c.data ->> 'vat_number'::text), ''::text), NULLIF((c.data ->> 'vatNumber'::text), ''::text), NULLIF((c.data ->> 'taxNumber'::text), ''::text)) AS vat_number,
|
|
1271
|
+
COALESCE(NULLIF((c.data ->> 'gln'::text), ''::text), NULLIF((c.data ->> 'companyGln'::text), ''::text)) AS gln,
|
|
1272
|
+
COALESCE(NULLIF((c.data ->> 'website'::text), ''::text), NULLIF((c.data ->> 'websiteUrl'::text), ''::text)) AS website,
|
|
1273
|
+
COALESCE(NULLIF((c.data ->> 'logo_url'::text), ''::text), NULLIF((c.data ->> 'logoUrl'::text), ''::text)) AS logo_url,
|
|
1274
|
+
conn.status,
|
|
1275
|
+
((COALESCE(conn.is_deleted, false) = false) AND (COALESCE(c.is_deleted, false) = false)) AS is_active,
|
|
1276
|
+
COALESCE(conn.is_deleted, false) AS is_deleted,
|
|
1277
|
+
c.fetched_at,
|
|
1278
|
+
c.data AS raw,
|
|
1279
|
+
COALESCE(c.updated_at, c.fetched_at) AS changed_at
|
|
1280
|
+
FROM ((floriday_customers_cache c
|
|
1281
|
+
JOIN get_active_floriday_connection_public() a(id, label, environment, organization_name, gln_code, preferred_warehouse_id, preferred_warehouse_name, active_environment) ON ((a.id = c.connection_id)))
|
|
1282
|
+
JOIN floriday_connections_cache conn ON (((conn.connection_id = c.connection_id) AND (conn.buyer_organization_id = c.organization_id))))$klanten_stmt$, 'CREATE OR REPLACE VIEW public.v_external_customers_floriday AS SELECT ''floriday''::text AS provider, ');
|
|
1283
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE VIEW public.v_external_customers_local AS
|
|
1284
|
+
SELECT 'local'::text AS provider,
|
|
1285
|
+
NULL::uuid AS connection_id,
|
|
1286
|
+
(id)::text AS external_id,
|
|
1287
|
+
company_name,
|
|
1288
|
+
commercial_name,
|
|
1289
|
+
contact_person,
|
|
1290
|
+
email,
|
|
1291
|
+
phone,
|
|
1292
|
+
street,
|
|
1293
|
+
house_number,
|
|
1294
|
+
postal_code,
|
|
1295
|
+
city,
|
|
1296
|
+
country,
|
|
1297
|
+
vat_number,
|
|
1298
|
+
gln,
|
|
1299
|
+
website,
|
|
1300
|
+
logo_url,
|
|
1301
|
+
sync_status AS status,
|
|
1302
|
+
COALESCE(is_active, true) AS is_active,
|
|
1303
|
+
false AS is_deleted,
|
|
1304
|
+
COALESCE(last_synced_at, updated_at, created_at) AS fetched_at,
|
|
1305
|
+
to_jsonb(c.*) AS raw,
|
|
1306
|
+
COALESCE(updated_at, created_at) AS changed_at
|
|
1307
|
+
FROM customers c$klanten_stmt$, 'CREATE OR REPLACE VIEW public.v_external_customers_local AS SELECT ''local''::text AS provider, NULL::');
|
|
1308
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE VIEW public.v_external_customers_twinfield AS
|
|
1309
|
+
WITH base AS (
|
|
1310
|
+
SELECT c.connection_id,
|
|
1311
|
+
c.twinfield_code,
|
|
1312
|
+
c.name,
|
|
1313
|
+
c.vat_number,
|
|
1314
|
+
c.country,
|
|
1315
|
+
c.email,
|
|
1316
|
+
c.modified_at,
|
|
1317
|
+
c.data,
|
|
1318
|
+
c.fetched_at,
|
|
1319
|
+
c.seen_at,
|
|
1320
|
+
c.is_active AS cache_active,
|
|
1321
|
+
c.deactivated_at,
|
|
1322
|
+
NULLIF(TRIM(BOTH FROM COALESCE(NULLIF((c.data ->> 'street'::text), ''::text), (((c.data -> 'addresses'::text) -> 0) ->> 'field2'::text), (c.data ->> 'address'::text))), ''::text) AS addr_line
|
|
1323
|
+
FROM (twinfield_customers_cache c
|
|
1324
|
+
JOIN get_active_twinfield_public() a(connection_id, environment, company_code, company_name, office_code, active_environment) ON ((a.connection_id = c.connection_id)))
|
|
1325
|
+
)
|
|
1326
|
+
SELECT 'twinfield'::text AS provider,
|
|
1327
|
+
connection_id,
|
|
1328
|
+
twinfield_code AS external_id,
|
|
1329
|
+
COALESCE(NULLIF(name, ''::text), twinfield_code) AS company_name,
|
|
1330
|
+
NULL::text AS commercial_name,
|
|
1331
|
+
NULLIF((data ->> 'contact_person'::text), ''::text) AS contact_person,
|
|
1332
|
+
COALESCE(NULLIF(email, ''::text), NULLIF((data ->> 'email'::text), ''::text)) AS email,
|
|
1333
|
+
NULLIF((data ->> 'phone'::text), ''::text) AS phone,
|
|
1334
|
+
COALESCE(NULLIF((data ->> 'street'::text), ''::text), NULLIF(TRIM(BOTH FROM (regexp_match(addr_line, '^(.*?)[\s,]+(\d+\s*[A-Za-z-]*)$'::text))[1]), ''::text), addr_line) AS street,
|
|
1335
|
+
COALESCE(NULLIF((data ->> 'house_number'::text), ''::text), NULLIF(replace((regexp_match(addr_line, '^(.*?)[\s,]+(\d+\s*[A-Za-z-]*)$'::text))[2], ' '::text, ''::text), ''::text)) AS house_number,
|
|
1336
|
+
COALESCE(NULLIF((data ->> 'postal_code'::text), ''::text), NULLIF((data ->> 'postcode'::text), ''::text)) AS postal_code,
|
|
1337
|
+
NULLIF((data ->> 'city'::text), ''::text) AS city,
|
|
1338
|
+
COALESCE(NULLIF(country, ''::text), NULLIF((data ->> 'country'::text), ''::text)) AS country,
|
|
1339
|
+
COALESCE(NULLIF(vat_number, ''::text), NULLIF((data ->> 'vat_number'::text), ''::text)) AS vat_number,
|
|
1340
|
+
NULL::text AS gln,
|
|
1341
|
+
NULLIF((data ->> 'website'::text), ''::text) AS website,
|
|
1342
|
+
NULLIF((data ->> 'logo_url'::text), ''::text) AS logo_url,
|
|
1343
|
+
CASE
|
|
1344
|
+
WHEN ((cache_active = false) OR (deactivated_at IS NOT NULL)) THEN 'missing'::text
|
|
1345
|
+
ELSE COALESCE(NULLIF((data ->> 'status'::text), ''::text), 'active'::text)
|
|
1346
|
+
END AS status,
|
|
1347
|
+
(COALESCE(cache_active, true) AND (deactivated_at IS NULL) AND (COALESCE(lower((data ->> 'status'::text)), 'active'::text) <> ALL (ARRAY['inactive'::text, 'hide'::text, 'hidden'::text, 'deleted'::text]))) AS is_active,
|
|
1348
|
+
false AS is_deleted,
|
|
1349
|
+
fetched_at,
|
|
1350
|
+
data AS raw,
|
|
1351
|
+
GREATEST(COALESCE(modified_at, fetched_at), COALESCE(seen_at, fetched_at), COALESCE(deactivated_at, fetched_at), fetched_at) AS changed_at
|
|
1352
|
+
FROM base b$klanten_stmt$, 'CREATE OR REPLACE VIEW public.v_external_customers_twinfield AS WITH base AS ( SELECT c.connection_i');
|
|
1353
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE MATERIALIZED VIEW IF NOT EXISTS public.external_customers_grouped AS
|
|
1354
|
+
WITH base AS (
|
|
1355
|
+
SELECT u.provider,
|
|
1356
|
+
u.connection_id,
|
|
1357
|
+
u.external_id,
|
|
1358
|
+
u.company_name,
|
|
1359
|
+
u.commercial_name,
|
|
1360
|
+
u.contact_person,
|
|
1361
|
+
u.email,
|
|
1362
|
+
u.phone,
|
|
1363
|
+
u.street,
|
|
1364
|
+
u.house_number,
|
|
1365
|
+
u.postal_code,
|
|
1366
|
+
u.city,
|
|
1367
|
+
u.country,
|
|
1368
|
+
u.vat_number,
|
|
1369
|
+
u.gln,
|
|
1370
|
+
u.website,
|
|
1371
|
+
u.logo_url,
|
|
1372
|
+
u.status,
|
|
1373
|
+
u.is_active,
|
|
1374
|
+
u.is_deleted,
|
|
1375
|
+
u.fetched_at,
|
|
1376
|
+
u.raw,
|
|
1377
|
+
u.changed_at,
|
|
1378
|
+
normalize_vat(u.vat_number) AS match_key,
|
|
1379
|
+
CASE u.provider
|
|
1380
|
+
WHEN 'twinfield'::text THEN 0
|
|
1381
|
+
WHEN 'floriday'::text THEN 1
|
|
1382
|
+
WHEN 'local'::text THEN 3
|
|
1383
|
+
ELSE 2
|
|
1384
|
+
END AS provider_priority,
|
|
1385
|
+
CASE u.provider
|
|
1386
|
+
WHEN 'twinfield'::text THEN NULLIF(btrim(u.external_id), ''::text)
|
|
1387
|
+
WHEN 'local'::text THEN ( SELECT NULLIF(btrim(c.twinfield_code), ''::text) AS "nullif"
|
|
1388
|
+
FROM customers c
|
|
1389
|
+
WHERE ((c.id)::text = u.external_id))
|
|
1390
|
+
ELSE NULL::text
|
|
1391
|
+
END AS tf_code,
|
|
1392
|
+
CASE u.provider
|
|
1393
|
+
WHEN 'floriday'::text THEN NULLIF(btrim(u.external_id), ''::text)
|
|
1394
|
+
WHEN 'local'::text THEN NULLIF(btrim((u.raw ->> 'floriday_organization_id'::text)), ''::text)
|
|
1395
|
+
ELSE NULL::text
|
|
1396
|
+
END AS fd_org,
|
|
1397
|
+
customer_soft_key(u.email, u.postal_code, u.house_number, u.company_name) AS soft_key
|
|
1398
|
+
FROM external_customers_unified u
|
|
1399
|
+
WHERE (u.is_deleted = false)
|
|
1400
|
+
), k0 AS (
|
|
1401
|
+
SELECT b.provider,
|
|
1402
|
+
b.connection_id,
|
|
1403
|
+
b.external_id,
|
|
1404
|
+
b.company_name,
|
|
1405
|
+
b.commercial_name,
|
|
1406
|
+
b.contact_person,
|
|
1407
|
+
b.email,
|
|
1408
|
+
b.phone,
|
|
1409
|
+
b.street,
|
|
1410
|
+
b.house_number,
|
|
1411
|
+
b.postal_code,
|
|
1412
|
+
b.city,
|
|
1413
|
+
b.country,
|
|
1414
|
+
b.vat_number,
|
|
1415
|
+
b.gln,
|
|
1416
|
+
b.website,
|
|
1417
|
+
b.logo_url,
|
|
1418
|
+
b.status,
|
|
1419
|
+
b.is_active,
|
|
1420
|
+
b.is_deleted,
|
|
1421
|
+
b.fetched_at,
|
|
1422
|
+
b.raw,
|
|
1423
|
+
b.changed_at,
|
|
1424
|
+
b.match_key,
|
|
1425
|
+
b.provider_priority,
|
|
1426
|
+
b.tf_code,
|
|
1427
|
+
b.fd_org,
|
|
1428
|
+
b.soft_key,
|
|
1429
|
+
((('row:'::text || b.provider) || '::'::text) || b.external_id) AS self_key,
|
|
1430
|
+
CASE
|
|
1431
|
+
WHEN (b.fd_org IS NOT NULL) THEN ('fd:'::text || b.fd_org)
|
|
1432
|
+
ELSE NULL::text
|
|
1433
|
+
END AS fd_key,
|
|
1434
|
+
CASE
|
|
1435
|
+
WHEN (b.tf_code IS NOT NULL) THEN ('tf:'::text || b.tf_code)
|
|
1436
|
+
ELSE NULL::text
|
|
1437
|
+
END AS tf_key,
|
|
1438
|
+
CASE
|
|
1439
|
+
WHEN (b.match_key IS NOT NULL) THEN ('vat:'::text || b.match_key)
|
|
1440
|
+
ELSE NULL::text
|
|
1441
|
+
END AS vat_key,
|
|
1442
|
+
CASE
|
|
1443
|
+
WHEN ((b.soft_key IS NOT NULL) AND (b.fd_org IS NULL) AND (b.tf_code IS NULL)) THEN ('soft:'::text || b.soft_key)
|
|
1444
|
+
ELSE NULL::text
|
|
1445
|
+
END AS sft_key,
|
|
1446
|
+
COALESCE(
|
|
1447
|
+
CASE
|
|
1448
|
+
WHEN (b.fd_org IS NOT NULL) THEN ('fd:'::text || b.fd_org)
|
|
1449
|
+
ELSE NULL::text
|
|
1450
|
+
END,
|
|
1451
|
+
CASE
|
|
1452
|
+
WHEN (b.tf_code IS NOT NULL) THEN ('tf:'::text || b.tf_code)
|
|
1453
|
+
ELSE NULL::text
|
|
1454
|
+
END,
|
|
1455
|
+
CASE
|
|
1456
|
+
WHEN (b.match_key IS NOT NULL) THEN ('vat:'::text || b.match_key)
|
|
1457
|
+
ELSE NULL::text
|
|
1458
|
+
END,
|
|
1459
|
+
CASE
|
|
1460
|
+
WHEN (b.soft_key IS NOT NULL) THEN ('soft:'::text || b.soft_key)
|
|
1461
|
+
ELSE NULL::text
|
|
1462
|
+
END, ((('solo__'::text || b.provider) || '__'::text) || b.external_id)) AS k0
|
|
1463
|
+
FROM base b
|
|
1464
|
+
), r1 AS (
|
|
1465
|
+
SELECT k0.provider,
|
|
1466
|
+
k0.connection_id,
|
|
1467
|
+
k0.external_id,
|
|
1468
|
+
k0.company_name,
|
|
1469
|
+
k0.commercial_name,
|
|
1470
|
+
k0.contact_person,
|
|
1471
|
+
k0.email,
|
|
1472
|
+
k0.phone,
|
|
1473
|
+
k0.street,
|
|
1474
|
+
k0.house_number,
|
|
1475
|
+
k0.postal_code,
|
|
1476
|
+
k0.city,
|
|
1477
|
+
k0.country,
|
|
1478
|
+
k0.vat_number,
|
|
1479
|
+
k0.gln,
|
|
1480
|
+
k0.website,
|
|
1481
|
+
k0.logo_url,
|
|
1482
|
+
k0.status,
|
|
1483
|
+
k0.is_active,
|
|
1484
|
+
k0.is_deleted,
|
|
1485
|
+
k0.fetched_at,
|
|
1486
|
+
k0.raw,
|
|
1487
|
+
k0.changed_at,
|
|
1488
|
+
k0.match_key,
|
|
1489
|
+
k0.provider_priority,
|
|
1490
|
+
k0.tf_code,
|
|
1491
|
+
k0.fd_org,
|
|
1492
|
+
k0.soft_key,
|
|
1493
|
+
k0.self_key,
|
|
1494
|
+
k0.fd_key,
|
|
1495
|
+
k0.tf_key,
|
|
1496
|
+
k0.vat_key,
|
|
1497
|
+
k0.sft_key,
|
|
1498
|
+
k0.k0,
|
|
1499
|
+
LEAST(min(k0.k0) OVER (PARTITION BY COALESCE(k0.fd_key, k0.self_key)), min(k0.k0) OVER (PARTITION BY COALESCE(k0.tf_key, k0.self_key)), min(k0.k0) OVER (PARTITION BY COALESCE(k0.vat_key, k0.self_key)), min(k0.k0) OVER (PARTITION BY COALESCE(k0.sft_key, k0.self_key))) AS k1
|
|
1500
|
+
FROM k0
|
|
1501
|
+
), r2 AS (
|
|
1502
|
+
SELECT r1.provider,
|
|
1503
|
+
r1.connection_id,
|
|
1504
|
+
r1.external_id,
|
|
1505
|
+
r1.company_name,
|
|
1506
|
+
r1.commercial_name,
|
|
1507
|
+
r1.contact_person,
|
|
1508
|
+
r1.email,
|
|
1509
|
+
r1.phone,
|
|
1510
|
+
r1.street,
|
|
1511
|
+
r1.house_number,
|
|
1512
|
+
r1.postal_code,
|
|
1513
|
+
r1.city,
|
|
1514
|
+
r1.country,
|
|
1515
|
+
r1.vat_number,
|
|
1516
|
+
r1.gln,
|
|
1517
|
+
r1.website,
|
|
1518
|
+
r1.logo_url,
|
|
1519
|
+
r1.status,
|
|
1520
|
+
r1.is_active,
|
|
1521
|
+
r1.is_deleted,
|
|
1522
|
+
r1.fetched_at,
|
|
1523
|
+
r1.raw,
|
|
1524
|
+
r1.changed_at,
|
|
1525
|
+
r1.match_key,
|
|
1526
|
+
r1.provider_priority,
|
|
1527
|
+
r1.tf_code,
|
|
1528
|
+
r1.fd_org,
|
|
1529
|
+
r1.soft_key,
|
|
1530
|
+
r1.self_key,
|
|
1531
|
+
r1.fd_key,
|
|
1532
|
+
r1.tf_key,
|
|
1533
|
+
r1.vat_key,
|
|
1534
|
+
r1.sft_key,
|
|
1535
|
+
r1.k0,
|
|
1536
|
+
r1.k1,
|
|
1537
|
+
LEAST(min(r1.k1) OVER (PARTITION BY COALESCE(r1.fd_key, r1.self_key)), min(r1.k1) OVER (PARTITION BY COALESCE(r1.tf_key, r1.self_key)), min(r1.k1) OVER (PARTITION BY COALESCE(r1.vat_key, r1.self_key)), min(r1.k1) OVER (PARTITION BY COALESCE(r1.sft_key, r1.self_key))) AS group_key
|
|
1538
|
+
FROM r1
|
|
1539
|
+
), ranked AS (
|
|
1540
|
+
SELECT r2.provider,
|
|
1541
|
+
r2.connection_id,
|
|
1542
|
+
r2.external_id,
|
|
1543
|
+
r2.company_name,
|
|
1544
|
+
r2.commercial_name,
|
|
1545
|
+
r2.contact_person,
|
|
1546
|
+
r2.email,
|
|
1547
|
+
r2.phone,
|
|
1548
|
+
r2.street,
|
|
1549
|
+
r2.house_number,
|
|
1550
|
+
r2.postal_code,
|
|
1551
|
+
r2.city,
|
|
1552
|
+
r2.country,
|
|
1553
|
+
r2.vat_number,
|
|
1554
|
+
r2.gln,
|
|
1555
|
+
r2.website,
|
|
1556
|
+
r2.logo_url,
|
|
1557
|
+
r2.status,
|
|
1558
|
+
r2.is_active,
|
|
1559
|
+
r2.is_deleted,
|
|
1560
|
+
r2.fetched_at,
|
|
1561
|
+
r2.raw,
|
|
1562
|
+
r2.changed_at,
|
|
1563
|
+
r2.match_key,
|
|
1564
|
+
r2.provider_priority,
|
|
1565
|
+
r2.tf_code,
|
|
1566
|
+
r2.fd_org,
|
|
1567
|
+
r2.soft_key,
|
|
1568
|
+
r2.self_key,
|
|
1569
|
+
r2.fd_key,
|
|
1570
|
+
r2.tf_key,
|
|
1571
|
+
r2.vat_key,
|
|
1572
|
+
r2.sft_key,
|
|
1573
|
+
r2.k0,
|
|
1574
|
+
r2.k1,
|
|
1575
|
+
r2.group_key,
|
|
1576
|
+
row_number() OVER (PARTITION BY r2.group_key ORDER BY r2.provider_priority, r2.fetched_at DESC NULLS LAST, r2.company_name) AS rn
|
|
1577
|
+
FROM r2
|
|
1578
|
+
)
|
|
1579
|
+
SELECT group_key,
|
|
1580
|
+
(array_agg(company_name ORDER BY rn))[1] AS display_name,
|
|
1581
|
+
(array_agg(commercial_name ORDER BY rn) FILTER (WHERE (commercial_name IS NOT NULL)))[1] AS commercial_name,
|
|
1582
|
+
(array_agg(contact_person ORDER BY rn) FILTER (WHERE (contact_person IS NOT NULL)))[1] AS contact_person,
|
|
1583
|
+
(array_agg(email ORDER BY rn) FILTER (WHERE (email IS NOT NULL)))[1] AS email,
|
|
1584
|
+
(array_agg(phone ORDER BY rn) FILTER (WHERE (phone IS NOT NULL)))[1] AS phone,
|
|
1585
|
+
(array_agg(city ORDER BY rn) FILTER (WHERE (city IS NOT NULL)))[1] AS city,
|
|
1586
|
+
(array_agg(country ORDER BY rn) FILTER (WHERE (country IS NOT NULL)))[1] AS country,
|
|
1587
|
+
(array_agg(website ORDER BY rn) FILTER (WHERE (website IS NOT NULL)))[1] AS website,
|
|
1588
|
+
(array_agg(logo_url ORDER BY rn) FILTER (WHERE (logo_url IS NOT NULL)))[1] AS logo_url,
|
|
1589
|
+
(array_agg(vat_number ORDER BY rn) FILTER (WHERE (vat_number IS NOT NULL)))[1] AS vat_number,
|
|
1590
|
+
(array_agg(gln ORDER BY rn) FILTER (WHERE (gln IS NOT NULL)))[1] AS gln,
|
|
1591
|
+
bool_or(is_active) AS is_active,
|
|
1592
|
+
max(fetched_at) AS fetched_at,
|
|
1593
|
+
max(changed_at) AS last_changed_at,
|
|
1594
|
+
array_agg(DISTINCT provider ORDER BY provider) AS providers,
|
|
1595
|
+
(count(*))::integer AS source_count,
|
|
1596
|
+
(count(*) > 1) AS is_merged,
|
|
1597
|
+
max(match_key) AS match_key,
|
|
1598
|
+
jsonb_agg(jsonb_build_object('provider', provider, 'connection_id', connection_id, 'external_id', external_id, 'company_name', company_name, 'commercial_name', commercial_name, 'contact_person', contact_person, 'email', email, 'phone', phone, 'street', street, 'house_number', house_number, 'postal_code', postal_code, 'city', city, 'country', country, 'vat_number', vat_number, 'gln', gln, 'website', website, 'logo_url', logo_url, 'status', status, 'is_active', is_active, 'is_deleted', is_deleted, 'fetched_at', fetched_at, 'raw', raw) ORDER BY rn) AS sources
|
|
1599
|
+
FROM ranked
|
|
1600
|
+
GROUP BY group_key$klanten_stmt$, 'CREATE MATERIALIZED VIEW IF NOT EXISTS public.external_customers_grouped AS WITH base AS ( SELECT u.');
|
|
1601
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS customers_enqueue_twinfield_push ON public.customers$klanten_stmt$, 'DROP TRIGGER IF EXISTS customers_enqueue_twinfield_push ON public.customers');
|
|
1602
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER customers_enqueue_twinfield_push AFTER INSERT OR UPDATE ON public.customers FOR EACH ROW EXECUTE FUNCTION enqueue_twinfield_push()$klanten_stmt$, 'CREATE TRIGGER customers_enqueue_twinfield_push AFTER INSERT OR UPDATE ON public.customers FOR EACH ');
|
|
1603
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS customers_validate_twinfield_required ON public.customers$klanten_stmt$, 'DROP TRIGGER IF EXISTS customers_validate_twinfield_required ON public.customers');
|
|
1604
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER customers_validate_twinfield_required BEFORE INSERT OR UPDATE ON public.customers FOR EACH ROW EXECUTE FUNCTION validate_twinfield_required_fields()$klanten_stmt$, 'CREATE TRIGGER customers_validate_twinfield_required BEFORE INSERT OR UPDATE ON public.customers FOR');
|
|
1605
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS trg_customers_refresh_external_grouped ON public.customers$klanten_stmt$, 'DROP TRIGGER IF EXISTS trg_customers_refresh_external_grouped ON public.customers');
|
|
1606
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER trg_customers_refresh_external_grouped AFTER INSERT OR DELETE OR UPDATE ON public.customers FOR EACH STATEMENT EXECUTE FUNCTION trg_refresh_external_customers_grouped()$klanten_stmt$, 'CREATE TRIGGER trg_customers_refresh_external_grouped AFTER INSERT OR DELETE OR UPDATE ON public.cus');
|
|
1607
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $ecg$
|
|
1608
|
+
BEGIN
|
|
1609
|
+
IF to_regclass('public.floriday_customers_cache') IS NOT NULL THEN
|
|
1610
|
+
DROP TRIGGER IF EXISTS trg_floriday_cache_refresh_ecg ON public.floriday_customers_cache;
|
|
1611
|
+
CREATE TRIGGER trg_floriday_cache_refresh_ecg AFTER INSERT OR DELETE OR UPDATE ON public.floriday_customers_cache FOR EACH STATEMENT EXECUTE FUNCTION public.trg_refresh_external_customers_grouped();
|
|
1612
|
+
ELSE
|
|
1613
|
+
RAISE NOTICE 'Klanten: tabel public.floriday_customers_cache ontbreekt; trigger trg_floriday_cache_refresh_ecg niet aangemaakt.';
|
|
1614
|
+
END IF;
|
|
1615
|
+
IF to_regclass('public.twinfield_customers_cache') IS NOT NULL THEN
|
|
1616
|
+
DROP TRIGGER IF EXISTS trg_twinfield_cache_refresh_ecg ON public.twinfield_customers_cache;
|
|
1617
|
+
CREATE TRIGGER trg_twinfield_cache_refresh_ecg AFTER INSERT OR DELETE OR UPDATE ON public.twinfield_customers_cache FOR EACH STATEMENT EXECUTE FUNCTION public.trg_refresh_external_customers_grouped();
|
|
1618
|
+
ELSE
|
|
1619
|
+
RAISE NOTICE 'Klanten: tabel public.twinfield_customers_cache ontbreekt; trigger trg_twinfield_cache_refresh_ecg niet aangemaakt.';
|
|
1620
|
+
END IF;
|
|
1621
|
+
END $ecg$$klanten_stmt$, 'DO $ecg$ BEGIN IF to_regclass(''public.floriday_customers_cache'') IS NOT NULL THEN DROP TRIGGER IF EX');
|
|
1622
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS trg_log_customer_changes ON public.customers$klanten_stmt$, 'DROP TRIGGER IF EXISTS trg_log_customer_changes ON public.customers');
|
|
1623
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER trg_log_customer_changes AFTER INSERT OR DELETE OR UPDATE ON public.customers FOR EACH ROW EXECUTE FUNCTION log_customer_changes()$klanten_stmt$, 'CREATE TRIGGER trg_log_customer_changes AFTER INSERT OR DELETE OR UPDATE ON public.customers FOR EAC');
|
|
1624
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS update_customers_updated_at ON public.customers$klanten_stmt$, 'DROP TRIGGER IF EXISTS update_customers_updated_at ON public.customers');
|
|
1625
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER update_customers_updated_at BEFORE UPDATE ON public.customers FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER update_customers_updated_at BEFORE UPDATE ON public.customers FOR EACH ROW EXECUTE FU');
|
|
1626
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS trg_customer_notes_updated ON public.customer_notes$klanten_stmt$, 'DROP TRIGGER IF EXISTS trg_customer_notes_updated ON public.customer_notes');
|
|
1627
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER trg_customer_notes_updated BEFORE UPDATE ON public.customer_notes FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER trg_customer_notes_updated BEFORE UPDATE ON public.customer_notes FOR EACH ROW EXECUT');
|
|
1628
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS trg_customer_price_groups_touch ON public.customer_price_groups$klanten_stmt$, 'DROP TRIGGER IF EXISTS trg_customer_price_groups_touch ON public.customer_price_groups');
|
|
1629
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER trg_customer_price_groups_touch BEFORE UPDATE ON public.customer_price_groups FOR EACH ROW EXECUTE FUNCTION tg_customer_price_groups_touch()$klanten_stmt$, 'CREATE TRIGGER trg_customer_price_groups_touch BEFORE UPDATE ON public.customer_price_groups FOR EAC');
|
|
1630
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS update_customer_product_stickers_updated_at ON public.customer_product_stickers$klanten_stmt$, 'DROP TRIGGER IF EXISTS update_customer_product_stickers_updated_at ON public.customer_product_sticke');
|
|
1631
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER update_customer_product_stickers_updated_at BEFORE UPDATE ON public.customer_product_stickers FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER update_customer_product_stickers_updated_at BEFORE UPDATE ON public.customer_product_');
|
|
1632
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS update_customer_sticker_settings_updated_at ON public.customer_sticker_settings$klanten_stmt$, 'DROP TRIGGER IF EXISTS update_customer_sticker_settings_updated_at ON public.customer_sticker_settin');
|
|
1633
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER update_customer_sticker_settings_updated_at BEFORE UPDATE ON public.customer_sticker_settings FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER update_customer_sticker_settings_updated_at BEFORE UPDATE ON public.customer_sticker_');
|
|
1634
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS update_customer_assortment_items_updated_at ON public.customer_assortment_items$klanten_stmt$, 'DROP TRIGGER IF EXISTS update_customer_assortment_items_updated_at ON public.customer_assortment_ite');
|
|
1635
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER update_customer_assortment_items_updated_at BEFORE UPDATE ON public.customer_assortment_items FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER update_customer_assortment_items_updated_at BEFORE UPDATE ON public.customer_assortme');
|
|
1636
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS trg_cms_updated_at ON public.customer_match_suggestions$klanten_stmt$, 'DROP TRIGGER IF EXISTS trg_cms_updated_at ON public.customer_match_suggestions');
|
|
1637
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER trg_cms_updated_at BEFORE UPDATE ON public.customer_match_suggestions FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER trg_cms_updated_at BEFORE UPDATE ON public.customer_match_suggestions FOR EACH ROW EX');
|
|
1638
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS update_external_customer_providers_updated_at ON public.external_customer_providers$klanten_stmt$, 'DROP TRIGGER IF EXISTS update_external_customer_providers_updated_at ON public.external_customer_pro');
|
|
1639
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER update_external_customer_providers_updated_at BEFORE UPDATE ON public.external_customer_providers FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER update_external_customer_providers_updated_at BEFORE UPDATE ON public.external_custom');
|
|
1640
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS trg_local_agreements_updated ON public.local_customer_agreements$klanten_stmt$, 'DROP TRIGGER IF EXISTS trg_local_agreements_updated ON public.local_customer_agreements');
|
|
1641
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER trg_local_agreements_updated BEFORE UPDATE ON public.local_customer_agreements FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER trg_local_agreements_updated BEFORE UPDATE ON public.local_customer_agreements FOR EA');
|
|
1642
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS trg_local_price_groups_updated ON public.local_customer_price_groups$klanten_stmt$, 'DROP TRIGGER IF EXISTS trg_local_price_groups_updated ON public.local_customer_price_groups');
|
|
1643
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER trg_local_price_groups_updated BEFORE UPDATE ON public.local_customer_price_groups FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER trg_local_price_groups_updated BEFORE UPDATE ON public.local_customer_price_groups FO');
|
|
1644
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DROP TRIGGER IF EXISTS trg_local_sales_strategies_updated ON public.local_customer_sales_strategies$klanten_stmt$, 'DROP TRIGGER IF EXISTS trg_local_sales_strategies_updated ON public.local_customer_sales_strategies');
|
|
1645
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE TRIGGER trg_local_sales_strategies_updated BEFORE UPDATE ON public.local_customer_sales_strategies FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()$klanten_stmt$, 'CREATE TRIGGER trg_local_sales_strategies_updated BEFORE UPDATE ON public.local_customer_sales_strat');
|
|
1646
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customers ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customers ENABLE ROW LEVEL SECURITY');
|
|
1647
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_contacts ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_contacts ENABLE ROW LEVEL SECURITY');
|
|
1648
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_delivery_locations ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_delivery_locations ENABLE ROW LEVEL SECURITY');
|
|
1649
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_logistics_strategy ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_logistics_strategy ENABLE ROW LEVEL SECURITY');
|
|
1650
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_notes ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_notes ENABLE ROW LEVEL SECURITY');
|
|
1651
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_group_members ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_price_group_members ENABLE ROW LEVEL SECURITY');
|
|
1652
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_price_groups ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_price_groups ENABLE ROW LEVEL SECURITY');
|
|
1653
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_product_stickers ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_product_stickers ENABLE ROW LEVEL SECURITY');
|
|
1654
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_selected_assortment ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_selected_assortment ENABLE ROW LEVEL SECURITY');
|
|
1655
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_sticker_settings ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_sticker_settings ENABLE ROW LEVEL SECURITY');
|
|
1656
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_trade_settings ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_trade_settings ENABLE ROW LEVEL SECURITY');
|
|
1657
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_assortment_items ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_assortment_items ENABLE ROW LEVEL SECURITY');
|
|
1658
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_audit_log ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_audit_log ENABLE ROW LEVEL SECURITY');
|
|
1659
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.customer_match_suggestions ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.customer_match_suggestions ENABLE ROW LEVEL SECURITY');
|
|
1660
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.external_customer_providers ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.external_customer_providers ENABLE ROW LEVEL SECURITY');
|
|
1661
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_agreements ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.local_customer_agreements ENABLE ROW LEVEL SECURITY');
|
|
1662
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_price_groups ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.local_customer_price_groups ENABLE ROW LEVEL SECURITY');
|
|
1663
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.local_customer_sales_strategies ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.local_customer_sales_strategies ENABLE ROW LEVEL SECURITY');
|
|
1664
|
+
SELECT pg_temp.klanten_try($klanten_stmt$ALTER TABLE public.twinfield_push_log ENABLE ROW LEVEL SECURITY$klanten_stmt$, 'ALTER TABLE public.twinfield_push_log ENABLE ROW LEVEL SECURITY');
|
|
1665
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customers' AND policyname='Authenticated users can delete customers') THEN CREATE POLICY "Authenticated users can delete customers" ON public.customers AS PERMISSIVE FOR DELETE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1666
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customers' AND policyname='Authenticated users can insert customers') THEN CREATE POLICY "Authenticated users can insert customers" ON public.customers AS PERMISSIVE FOR INSERT TO authenticated WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1667
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customers' AND policyname='Authenticated users can read customers') THEN CREATE POLICY "Authenticated users can read customers" ON public.customers AS PERMISSIVE FOR SELECT TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1668
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customers' AND policyname='Authenticated users can update customers') THEN CREATE POLICY "Authenticated users can update customers" ON public.customers AS PERMISSIVE FOR UPDATE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1669
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_contacts' AND policyname='Authenticated can delete customer_contacts') THEN CREATE POLICY "Authenticated can delete customer_contacts" ON public.customer_contacts AS PERMISSIVE FOR DELETE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1670
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_contacts' AND policyname='Authenticated can insert customer_contacts') THEN CREATE POLICY "Authenticated can insert customer_contacts" ON public.customer_contacts AS PERMISSIVE FOR INSERT TO authenticated WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1671
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_contacts' AND policyname='Authenticated can read customer_contacts') THEN CREATE POLICY "Authenticated can read customer_contacts" ON public.customer_contacts AS PERMISSIVE FOR SELECT TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1672
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_contacts' AND policyname='Authenticated can update customer_contacts') THEN CREATE POLICY "Authenticated can update customer_contacts" ON public.customer_contacts AS PERMISSIVE FOR UPDATE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1673
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_delivery_locations' AND policyname='Authenticated can delete customer_delivery_locations') THEN CREATE POLICY "Authenticated can delete customer_delivery_locations" ON public.customer_delivery_locations AS PERMISSIVE FOR DELETE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1674
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_delivery_locations' AND policyname='Authenticated can insert customer_delivery_locations') THEN CREATE POLICY "Authenticated can insert customer_delivery_locations" ON public.customer_delivery_locations AS PERMISSIVE FOR INSERT TO authenticated WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1675
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_delivery_locations' AND policyname='Authenticated can read customer_delivery_locations') THEN CREATE POLICY "Authenticated can read customer_delivery_locations" ON public.customer_delivery_locations AS PERMISSIVE FOR SELECT TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1676
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_delivery_locations' AND policyname='Authenticated can update customer_delivery_locations') THEN CREATE POLICY "Authenticated can update customer_delivery_locations" ON public.customer_delivery_locations AS PERMISSIVE FOR UPDATE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1677
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_logistics_strategy' AND policyname='auth can read cls') THEN CREATE POLICY "auth can read cls" ON public.customer_logistics_strategy AS PERMISSIVE FOR SELECT TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1678
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_logistics_strategy' AND policyname='auth can write cls') THEN CREATE POLICY "auth can write cls" ON public.customer_logistics_strategy AS PERMISSIVE FOR ALL TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1679
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_notes' AND policyname='auth manage customer notes') THEN CREATE POLICY "auth manage customer notes" ON public.customer_notes AS PERMISSIVE FOR ALL TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1680
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_price_group_members' AND policyname='own pg members - delete') THEN CREATE POLICY "own pg members - delete" ON public.customer_price_group_members AS PERMISSIVE FOR DELETE TO authenticated USING ((owner_id = auth.uid())); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1681
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_price_group_members' AND policyname='own pg members - insert') THEN CREATE POLICY "own pg members - insert" ON public.customer_price_group_members AS PERMISSIVE FOR INSERT TO authenticated WITH CHECK ((owner_id = auth.uid())); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1682
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_price_group_members' AND policyname='own pg members - select') THEN CREATE POLICY "own pg members - select" ON public.customer_price_group_members AS PERMISSIVE FOR SELECT TO authenticated USING ((owner_id = auth.uid())); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1683
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_price_group_members' AND policyname='own pg members - update') THEN CREATE POLICY "own pg members - update" ON public.customer_price_group_members AS PERMISSIVE FOR UPDATE TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid())); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1684
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_price_groups' AND policyname='own price groups - delete') THEN CREATE POLICY "own price groups - delete" ON public.customer_price_groups AS PERMISSIVE FOR DELETE TO authenticated USING ((owner_id = auth.uid())); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1685
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_price_groups' AND policyname='own price groups - insert') THEN CREATE POLICY "own price groups - insert" ON public.customer_price_groups AS PERMISSIVE FOR INSERT TO authenticated WITH CHECK ((owner_id = auth.uid())); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1686
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_price_groups' AND policyname='own price groups - select') THEN CREATE POLICY "own price groups - select" ON public.customer_price_groups AS PERMISSIVE FOR SELECT TO authenticated USING ((owner_id = auth.uid())); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1687
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_price_groups' AND policyname='own price groups - update') THEN CREATE POLICY "own price groups - update" ON public.customer_price_groups AS PERMISSIVE FOR UPDATE TO authenticated USING ((owner_id = auth.uid())) WITH CHECK ((owner_id = auth.uid())); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1688
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_product_stickers' AND policyname='Ingelogde gebruikers beheren klantstickers') THEN CREATE POLICY "Ingelogde gebruikers beheren klantstickers" ON public.customer_product_stickers AS PERMISSIVE FOR ALL TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1689
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_selected_assortment' AND policyname='Authenticated can delete customer_selected_assortment') THEN CREATE POLICY "Authenticated can delete customer_selected_assortment" ON public.customer_selected_assortment AS PERMISSIVE FOR DELETE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1690
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_selected_assortment' AND policyname='Authenticated can insert customer_selected_assortment') THEN CREATE POLICY "Authenticated can insert customer_selected_assortment" ON public.customer_selected_assortment AS PERMISSIVE FOR INSERT TO authenticated WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1691
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_selected_assortment' AND policyname='Authenticated can read customer_selected_assortment') THEN CREATE POLICY "Authenticated can read customer_selected_assortment" ON public.customer_selected_assortment AS PERMISSIVE FOR SELECT TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1692
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_selected_assortment' AND policyname='Authenticated can update customer_selected_assortment') THEN CREATE POLICY "Authenticated can update customer_selected_assortment" ON public.customer_selected_assortment AS PERMISSIVE FOR UPDATE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1693
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_sticker_settings' AND policyname='Ingelogde gebruikers beheren stickerinstellingen') THEN CREATE POLICY "Ingelogde gebruikers beheren stickerinstellingen" ON public.customer_sticker_settings AS PERMISSIVE FOR ALL TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1694
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_trade_settings' AND policyname='Authenticated can delete customer_trade_settings') THEN CREATE POLICY "Authenticated can delete customer_trade_settings" ON public.customer_trade_settings AS PERMISSIVE FOR DELETE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1695
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_trade_settings' AND policyname='Authenticated can insert customer_trade_settings') THEN CREATE POLICY "Authenticated can insert customer_trade_settings" ON public.customer_trade_settings AS PERMISSIVE FOR INSERT TO authenticated WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1696
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_trade_settings' AND policyname='Authenticated can read customer_trade_settings') THEN CREATE POLICY "Authenticated can read customer_trade_settings" ON public.customer_trade_settings AS PERMISSIVE FOR SELECT TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1697
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_trade_settings' AND policyname='Authenticated can update customer_trade_settings') THEN CREATE POLICY "Authenticated can update customer_trade_settings" ON public.customer_trade_settings AS PERMISSIVE FOR UPDATE TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1698
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_assortment_items' AND policyname='Authenticated can manage customer assortment') THEN CREATE POLICY "Authenticated can manage customer assortment" ON public.customer_assortment_items AS PERMISSIVE FOR ALL TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1699
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_match_suggestions' AND policyname='Ingelogd beoordelen voorstellen') THEN CREATE POLICY "Ingelogd beoordelen voorstellen" ON public.customer_match_suggestions AS PERMISSIVE FOR UPDATE TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1700
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='customer_match_suggestions' AND policyname='Ingelogd lezen voorstellen') THEN CREATE POLICY "Ingelogd lezen voorstellen" ON public.customer_match_suggestions AS PERMISSIVE FOR SELECT TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''custo');
|
|
1701
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='external_customer_providers' AND policyname='External customer providers are readable by authenticated users') THEN CREATE POLICY "External customer providers are readable by authenticated users" ON public.external_customer_providers AS PERMISSIVE FOR SELECT TO authenticated USING (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''exter');
|
|
1702
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='local_customer_agreements' AND policyname='auth manage local agreements') THEN CREATE POLICY "auth manage local agreements" ON public.local_customer_agreements AS PERMISSIVE FOR ALL TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''local');
|
|
1703
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='local_customer_price_groups' AND policyname='auth manage local price groups') THEN CREATE POLICY "auth manage local price groups" ON public.local_customer_price_groups AS PERMISSIVE FOR ALL TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''local');
|
|
1704
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='local_customer_sales_strategies' AND policyname='auth manage local sales strategies') THEN CREATE POLICY "auth manage local sales strategies" ON public.local_customer_sales_strategies AS PERMISSIVE FOR ALL TO authenticated USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''local');
|
|
1705
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='twinfield_push_log' AND policyname='service role only') THEN CREATE POLICY "service role only" ON public.twinfield_push_log AS PERMISSIVE FOR ALL TO service_role USING (true) WITH CHECK (true); END IF; END $p$$klanten_stmt$, 'DO $p$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname=''public'' AND tablename=''twinf');
|
|
1706
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.floriday_customer_candidates()
|
|
1707
|
+
RETURNS TABLE(organization_id text, reason text, in_cache boolean)
|
|
1708
|
+
LANGUAGE sql STABLE SECURITY DEFINER SET search_path TO 'public'
|
|
1709
|
+
AS $function$
|
|
1710
|
+
WITH rel AS (
|
|
1711
|
+
SELECT DISTINCT cc.data->>'customerOrganizationId' AS org, 'inkooprelatie'::text AS reason
|
|
1712
|
+
FROM floriday_connections_cache cc
|
|
1713
|
+
JOIN floriday_connections fc ON fc.id = cc.connection_id AND fc.is_active = true
|
|
1714
|
+
WHERE NULLIF(cc.data->>'customerOrganizationId','') IS NOT NULL
|
|
1715
|
+
AND COALESCE(cc.data->>'isDeleted', 'false') = 'false'
|
|
1716
|
+
), ord AS (
|
|
1717
|
+
SELECT DISTINCT o.custom_fields->>'floriday_customer_id' AS org, 'order'::text
|
|
1718
|
+
FROM orders o
|
|
1719
|
+
WHERE o.customer_id IS NULL AND NULLIF(o.custom_fields->>'floriday_customer_id','') IS NOT NULL
|
|
1720
|
+
), al AS (SELECT * FROM rel UNION SELECT * FROM ord)
|
|
1721
|
+
SELECT al.org, al.reason,
|
|
1722
|
+
EXISTS (SELECT 1 FROM floriday_customers_cache f WHERE f.organization_id = al.org AND COALESCE(f.is_deleted,false)=false)
|
|
1723
|
+
FROM al
|
|
1724
|
+
WHERE NOT EXISTS (SELECT 1 FROM customers c WHERE c.floriday_organization_id = al.org);
|
|
1725
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.floriday_customer_candidates() RETURNS TABLE(organization_id text,');
|
|
1726
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.floriday_customer_promotion_preview()
|
|
1727
|
+
RETURNS jsonb LANGUAGE sql STABLE SECURITY DEFINER SET search_path TO 'public'
|
|
1728
|
+
AS $function$
|
|
1729
|
+
WITH k AS (SELECT * FROM floriday_customer_candidates())
|
|
1730
|
+
SELECT jsonb_build_object(
|
|
1731
|
+
'nieuw_via_inkooprelatie', (SELECT count(*) FROM k WHERE reason='inkooprelatie' AND in_cache),
|
|
1732
|
+
'nieuw_via_order', (SELECT count(*) FROM k WHERE reason='order' AND in_cache),
|
|
1733
|
+
'zonder_floriday_gegevens', (SELECT count(DISTINCT organization_id) FROM k WHERE NOT in_cache),
|
|
1734
|
+
'koppelen_op_gln', (SELECT count(DISTINCT k.organization_id) FROM k
|
|
1735
|
+
JOIN floriday_customers_cache f ON f.organization_id = k.organization_id AND COALESCE(f.is_deleted,false)=false
|
|
1736
|
+
WHERE (SELECT count(*) FROM customers c WHERE c.floriday_organization_id IS NULL
|
|
1737
|
+
AND btrim(c.gln) = COALESCE(NULLIF(btrim(f.gln_code),''), NULLIF(btrim(f.data->>'companyGln'),''))) = 1));
|
|
1738
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.floriday_customer_promotion_preview() RETURNS jsonb LANGUAGE sql S');
|
|
1739
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_promote_round()
|
|
1740
|
+
RETURNS jsonb LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public'
|
|
1741
|
+
AS $function$
|
|
1742
|
+
DECLARE _r record; _made int := 0; _linked int := 0; _skip int := 0; _fail int := 0; _filled int := 0;
|
|
1743
|
+
_before int; _id uuid; _res jsonb;
|
|
1744
|
+
BEGIN
|
|
1745
|
+
FOR _r IN
|
|
1746
|
+
SELECT organization_id, bool_or(in_cache) AS in_cache,
|
|
1747
|
+
CASE WHEN bool_or(reason='inkooprelatie') THEN 'inkooprelatie' ELSE 'order' END AS reason
|
|
1748
|
+
FROM floriday_customer_candidates()
|
|
1749
|
+
GROUP BY organization_id
|
|
1750
|
+
LOOP
|
|
1751
|
+
IF NOT _r.in_cache THEN _skip := _skip + 1; CONTINUE; END IF;
|
|
1752
|
+
BEGIN
|
|
1753
|
+
SELECT count(*) INTO _before FROM customers;
|
|
1754
|
+
PERFORM set_config('app.promote_reason', _r.reason, true);
|
|
1755
|
+
_id := promote_floriday_customer(_r.organization_id);
|
|
1756
|
+
IF _id IS NULL THEN _skip := _skip + 1;
|
|
1757
|
+
ELSIF (SELECT count(*) FROM customers) > _before THEN _made := _made + 1;
|
|
1758
|
+
ELSE _linked := _linked + 1; END IF;
|
|
1759
|
+
EXCEPTION WHEN OTHERS THEN
|
|
1760
|
+
_fail := _fail + 1;
|
|
1761
|
+
RAISE WARNING 'promote_floriday_customer(%) mislukt: %', _r.organization_id, SQLERRM;
|
|
1762
|
+
END;
|
|
1763
|
+
END LOOP;
|
|
1764
|
+
PERFORM set_config('app.promote_reason', '', true);
|
|
1765
|
+
FOR _r IN
|
|
1766
|
+
SELECT c.floriday_organization_id AS org FROM customers c
|
|
1767
|
+
WHERE c.floriday_organization_id IS NOT NULL
|
|
1768
|
+
AND EXISTS (SELECT 1 FROM floriday_customers_cache f WHERE f.organization_id = c.floriday_organization_id AND COALESCE(f.is_deleted,false)=false)
|
|
1769
|
+
AND (NULLIF(c.street,'') IS NULL OR NULLIF(c.city,'') IS NULL OR NULLIF(c.country,'') IS NULL
|
|
1770
|
+
OR c.floriday_raw IS NULL OR c.floriday_connection_id IS NULL
|
|
1771
|
+
OR NOT EXISTS (SELECT 1 FROM customer_delivery_locations l WHERE l.customer_id = c.id))
|
|
1772
|
+
LIMIT 200
|
|
1773
|
+
LOOP
|
|
1774
|
+
BEGIN
|
|
1775
|
+
PERFORM promote_floriday_customer(_r.org);
|
|
1776
|
+
_filled := _filled + 1;
|
|
1777
|
+
EXCEPTION WHEN OTHERS THEN
|
|
1778
|
+
RAISE WARNING 'aanvullen Floriday-klant % mislukt: %', _r.org, SQLERRM;
|
|
1779
|
+
END;
|
|
1780
|
+
END LOOP;
|
|
1781
|
+
_res := jsonb_build_object('aangemaakt', _made, 'gekoppeld', _linked, 'overgeslagen', _skip + _fail,
|
|
1782
|
+
'overgeslagen_zonder_gegevens', _skip, 'mislukt', _fail, 'nagelopen', _filled, 'op', now());
|
|
1783
|
+
BEGIN
|
|
1784
|
+
UPDATE app_settings SET value = _res::text, updated_at = now() WHERE key = 'klanten_last_promote_round';
|
|
1785
|
+
IF NOT FOUND THEN INSERT INTO app_settings(key, value) VALUES ('klanten_last_promote_round', _res::text); END IF;
|
|
1786
|
+
EXCEPTION WHEN OTHERS THEN RAISE WARNING 'laatste ronde niet bewaard: %', SQLERRM; END;
|
|
1787
|
+
RETURN _res;
|
|
1788
|
+
END;
|
|
1789
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_promote_round() RETURNS jsonb LANGUAGE plpgsql SECURITY DE');
|
|
1790
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.promote_floriday_order_customers()
|
|
1791
|
+
RETURNS integer LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public'
|
|
1792
|
+
AS $function$
|
|
1793
|
+
DECLARE _res jsonb;
|
|
1794
|
+
BEGIN
|
|
1795
|
+
_res := klanten_promote_round();
|
|
1796
|
+
RETURN COALESCE((_res->>'aangemaakt')::int,0) + COALESCE((_res->>'gekoppeld')::int,0);
|
|
1797
|
+
END;
|
|
1798
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.promote_floriday_order_customers() RETURNS integer LANGUAGE plpgsq');
|
|
1799
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_auto_promote_status()
|
|
1800
|
+
RETURNS jsonb LANGUAGE plpgsql STABLE SECURITY DEFINER SET search_path TO 'public'
|
|
1801
|
+
AS $function$
|
|
1802
|
+
DECLARE _res jsonb;
|
|
1803
|
+
BEGIN
|
|
1804
|
+
IF NOT public.has_role(auth.uid(), 'admin') THEN
|
|
1805
|
+
RAISE EXCEPTION 'Alleen voor beheerders';
|
|
1806
|
+
END IF;
|
|
1807
|
+
WITH k AS (SELECT * FROM floriday_customer_candidates()),
|
|
1808
|
+
g AS (
|
|
1809
|
+
SELECT k.organization_id, k.reason, k.in_cache,
|
|
1810
|
+
(SELECT count(*) FROM customers c JOIN floriday_customers_cache f ON f.organization_id = k.organization_id
|
|
1811
|
+
WHERE c.floriday_organization_id IS NULL AND COALESCE(f.is_deleted,false)=false
|
|
1812
|
+
AND btrim(c.gln) = COALESCE(NULLIF(btrim(f.gln_code),''), NULLIF(btrim(f.data->>'companyGln'),''))) AS gln_hits
|
|
1813
|
+
FROM k
|
|
1814
|
+
),
|
|
1815
|
+
per AS (
|
|
1816
|
+
SELECT reason, jsonb_build_object(
|
|
1817
|
+
'nieuw', count(*) FILTER (WHERE in_cache AND gln_hits = 0),
|
|
1818
|
+
'koppelen_op_gln', count(*) FILTER (WHERE in_cache AND gln_hits = 1),
|
|
1819
|
+
'gln_meerdere', count(*) FILTER (WHERE in_cache AND gln_hits > 1),
|
|
1820
|
+
'zonder_gegevens', count(*) FILTER (WHERE NOT in_cache),
|
|
1821
|
+
'zonder_gegevens_wel_in_netwerk', count(*) FILTER (WHERE NOT in_cache AND EXISTS (SELECT 1 FROM floriday_network_cache n WHERE n.organization_id = g.organization_id))
|
|
1822
|
+
) AS t FROM g GROUP BY reason
|
|
1823
|
+
),
|
|
1824
|
+
steek AS (
|
|
1825
|
+
SELECT jsonb_agg(jsonb_build_object(
|
|
1826
|
+
'id', s.organization_id, 'reden', s.reason,
|
|
1827
|
+
'in_klantorganisaties', EXISTS (SELECT 1 FROM floriday_customers_cache f WHERE f.organization_id = s.organization_id),
|
|
1828
|
+
'in_klantorganisaties_lower_trim', EXISTS (SELECT 1 FROM floriday_customers_cache f WHERE lower(btrim(f.organization_id)) = lower(btrim(s.organization_id))),
|
|
1829
|
+
'in_netwerk', EXISTS (SELECT 1 FROM floriday_network_cache n WHERE n.organization_id = s.organization_id),
|
|
1830
|
+
'als_buyer_organization_id', EXISTS (SELECT 1 FROM floriday_connections_cache cc WHERE cc.buyer_organization_id = s.organization_id),
|
|
1831
|
+
'als_floriday_connection_id', EXISTS (SELECT 1 FROM floriday_connections_cache cc WHERE cc.floriday_connection_id = s.organization_id),
|
|
1832
|
+
'buyer_organization_id', (SELECT cc.buyer_organization_id FROM floriday_connections_cache cc WHERE cc.data->>'customerOrganizationId' = s.organization_id LIMIT 1),
|
|
1833
|
+
'buyer_in_klantorganisaties', EXISTS (SELECT 1 FROM floriday_connections_cache cc JOIN floriday_customers_cache f ON f.organization_id = cc.buyer_organization_id WHERE cc.data->>'customerOrganizationId' = s.organization_id),
|
|
1834
|
+
'omgeving', (SELECT fc.environment FROM floriday_connections_cache cc JOIN floriday_connections fc ON fc.id = cc.connection_id WHERE cc.data->>'customerOrganizationId' = s.organization_id LIMIT 1),
|
|
1835
|
+
'omgeving_klantorganisaties', (SELECT string_agg(DISTINCT fc.environment, ',') FROM floriday_customers_cache f JOIN floriday_connections fc ON fc.id = f.connection_id)
|
|
1836
|
+
)) AS v
|
|
1837
|
+
FROM (SELECT organization_id, reason FROM g WHERE NOT in_cache ORDER BY organization_id LIMIT 5) s
|
|
1838
|
+
)
|
|
1839
|
+
SELECT jsonb_build_object(
|
|
1840
|
+
'laatste_ronde', (SELECT value::jsonb FROM app_settings WHERE key='klanten_last_promote_round'),
|
|
1841
|
+
'inkooprelatie', COALESCE((SELECT t FROM per WHERE reason='inkooprelatie'), '{}'::jsonb),
|
|
1842
|
+
'order', COALESCE((SELECT t FROM per WHERE reason='order'), '{}'::jsonb),
|
|
1843
|
+
'order_ook_inkooprelatie', (SELECT count(*) FROM (SELECT organization_id FROM g GROUP BY organization_id HAVING count(DISTINCT reason) = 2) x),
|
|
1844
|
+
'steekproef', COALESCE((SELECT v FROM steek), '[]'::jsonb)
|
|
1845
|
+
) INTO _res;
|
|
1846
|
+
RETURN _res;
|
|
1847
|
+
END;
|
|
1848
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_auto_promote_status() RETURNS jsonb LANGUAGE plpgsql STABL');
|
|
1849
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_set_auto_promote(p_kind text, p_on boolean)
|
|
1850
|
+
RETURNS jsonb LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public'
|
|
1851
|
+
AS $function$
|
|
1852
|
+
DECLARE _key text;
|
|
1853
|
+
BEGIN
|
|
1854
|
+
IF NOT public.has_role(auth.uid(), 'admin') THEN
|
|
1855
|
+
RAISE EXCEPTION 'Alleen voor beheerders';
|
|
1856
|
+
END IF;
|
|
1857
|
+
_key := CASE p_kind WHEN 'relations' THEN 'klanten_auto_promote_relations'
|
|
1858
|
+
WHEN 'orders' THEN 'klanten_auto_promote_orders' END;
|
|
1859
|
+
IF _key IS NULL THEN RAISE EXCEPTION 'Onbekende schakelaar %', p_kind; END IF;
|
|
1860
|
+
UPDATE app_settings SET value = CASE WHEN p_on THEN 'true' ELSE 'false' END, updated_at = now() WHERE key = _key;
|
|
1861
|
+
IF NOT FOUND THEN
|
|
1862
|
+
INSERT INTO app_settings(key, value) VALUES (_key, CASE WHEN p_on THEN 'true' ELSE 'false' END);
|
|
1863
|
+
END IF;
|
|
1864
|
+
IF p_on THEN RETURN klanten_promote_round(); END IF;
|
|
1865
|
+
RETURN jsonb_build_object('aangemaakt',0,'gekoppeld',0,'overgeslagen',0);
|
|
1866
|
+
END;
|
|
1867
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_set_auto_promote(p_kind text, p_on boolean) RETURNS jsonb ');
|
|
1868
|
+
SELECT pg_temp.klanten_try($klanten_stmt$REVOKE ALL ON FUNCTION public.klanten_promote_round() FROM PUBLIC, anon, authenticated$klanten_stmt$, 'REVOKE ALL ON FUNCTION public.klanten_promote_round() FROM PUBLIC, anon, authenticated');
|
|
1869
|
+
SELECT pg_temp.klanten_try($klanten_stmt$GRANT EXECUTE ON FUNCTION public.klanten_promote_round() TO service_role$klanten_stmt$, 'GRANT EXECUTE ON FUNCTION public.klanten_promote_round() TO service_role');
|
|
1870
|
+
SELECT pg_temp.klanten_try($klanten_stmt$REVOKE ALL ON FUNCTION public.klanten_auto_promote_status() FROM PUBLIC, anon$klanten_stmt$, 'REVOKE ALL ON FUNCTION public.klanten_auto_promote_status() FROM PUBLIC, anon');
|
|
1871
|
+
SELECT pg_temp.klanten_try($klanten_stmt$GRANT EXECUTE ON FUNCTION public.klanten_auto_promote_status() TO authenticated, service_role$klanten_stmt$, 'GRANT EXECUTE ON FUNCTION public.klanten_auto_promote_status() TO authenticated, service_role');
|
|
1872
|
+
SELECT pg_temp.klanten_try($klanten_stmt$REVOKE ALL ON FUNCTION public.klanten_set_auto_promote(text, boolean) FROM PUBLIC, anon$klanten_stmt$, 'REVOKE ALL ON FUNCTION public.klanten_set_auto_promote(text, boolean) FROM PUBLIC, anon');
|
|
1873
|
+
SELECT pg_temp.klanten_try($klanten_stmt$GRANT EXECUTE ON FUNCTION public.klanten_set_auto_promote(text, boolean) TO authenticated, service_role$klanten_stmt$, 'GRANT EXECUTE ON FUNCTION public.klanten_set_auto_promote(text, boolean) TO authenticated, service_r');
|
|
1874
|
+
SELECT pg_temp.klanten_try($klanten_stmt$CREATE OR REPLACE FUNCTION public.klanten_refresh_grouped_if_stale()
|
|
1875
|
+
RETURNS boolean LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public'
|
|
1876
|
+
AS $function$
|
|
1877
|
+
BEGIN
|
|
1878
|
+
IF auth.uid() IS NULL THEN RETURN false; END IF;
|
|
1879
|
+
IF EXISTS (SELECT 1 FROM customers c WHERE NOT EXISTS (
|
|
1880
|
+
SELECT 1 FROM external_customers_grouped g
|
|
1881
|
+
WHERE g.sources @> jsonb_build_array(jsonb_build_object('provider','local','external_id',c.id::text)))) THEN
|
|
1882
|
+
PERFORM public.refresh_external_customers_grouped();
|
|
1883
|
+
RETURN true;
|
|
1884
|
+
END IF;
|
|
1885
|
+
RETURN false;
|
|
1886
|
+
END;
|
|
1887
|
+
$function$$klanten_stmt$, 'CREATE OR REPLACE FUNCTION public.klanten_refresh_grouped_if_stale() RETURNS boolean LANGUAGE plpgsq');
|
|
1888
|
+
SELECT pg_temp.klanten_try($klanten_stmt$REVOKE ALL ON FUNCTION public.klanten_refresh_grouped_if_stale() FROM PUBLIC, anon$klanten_stmt$, 'REVOKE ALL ON FUNCTION public.klanten_refresh_grouped_if_stale() FROM PUBLIC, anon');
|
|
1889
|
+
SELECT pg_temp.klanten_try($klanten_stmt$GRANT EXECUTE ON FUNCTION public.klanten_refresh_grouped_if_stale() TO authenticated, service_role$klanten_stmt$, 'GRANT EXECUTE ON FUNCTION public.klanten_refresh_grouped_if_stale() TO authenticated, service_role');
|
|
1890
|
+
SELECT pg_temp.klanten_try($klanten_stmt$DO $cron$ BEGIN
|
|
1891
|
+
IF EXISTS (SELECT 1 FROM pg_extension WHERE extname='pg_cron')
|
|
1892
|
+
AND NOT EXISTS (SELECT 1 FROM cron.job WHERE jobname='promote-floriday-order-customers') THEN
|
|
1893
|
+
PERFORM cron.schedule('promote-floriday-order-customers','*/5 * * * *','SELECT public.promote_floriday_order_customers();');
|
|
1894
|
+
END IF;
|
|
1895
|
+
END $cron$$klanten_stmt$, 'DO $cron$ BEGIN IF EXISTS (SELECT 1 FROM pg_extension WHERE extname=''pg_cron'') AND NOT EXISTS (SELEC');
|