@fayz-ai/db 0.22.0 → 0.22.2
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.
|
@@ -69,6 +69,22 @@ SELECT u.tenant_id, 'unit', u.id, 'main',
|
|
|
69
69
|
AND (p.street <> '' OR p.city <> '');
|
|
70
70
|
|
|
71
71
|
-- ── 2. a view lê o endereço de onde ele mora ────────────────────────────────
|
|
72
|
+
-- Replay guard. 168 widened v_units with the company columns and rewrote its
|
|
73
|
+
-- writer. Re-running this file over that shape fails (CREATE OR REPLACE VIEW
|
|
74
|
+
-- cannot drop columns) and, if it did not, would put this file's older writer
|
|
75
|
+
-- back over 168's. So once the view carries `legal_entity_id`, the view and
|
|
76
|
+
-- the writer below are history and are skipped; what sits above this block is
|
|
77
|
+
-- idempotent and still runs.
|
|
78
|
+
DO $guard$
|
|
79
|
+
BEGIN
|
|
80
|
+
IF EXISTS (SELECT 1 FROM pg_attribute
|
|
81
|
+
WHERE attrelid = 'public.v_units'::regclass
|
|
82
|
+
AND attname = 'legal_entity_id' AND NOT attisdropped) THEN
|
|
83
|
+
RAISE NOTICE '141: v_units already has the 168 shape; view and writer left as they are';
|
|
84
|
+
RETURN;
|
|
85
|
+
END IF;
|
|
86
|
+
|
|
87
|
+
EXECUTE $s1$
|
|
72
88
|
CREATE OR REPLACE VIEW public.v_units WITH (security_invoker='true') AS
|
|
73
89
|
SELECT u.id,
|
|
74
90
|
u.tenant_id,
|
|
@@ -112,12 +128,16 @@ CREATE OR REPLACE VIEW public.v_units WITH (security_invoker='true') AS
|
|
|
112
128
|
WHERE x.owner_type = 'unit' AND x.owner_id = u.id
|
|
113
129
|
ORDER BY x.is_default DESC, x.created_at
|
|
114
130
|
LIMIT 1
|
|
115
|
-
) a ON true
|
|
131
|
+
) a ON true
|
|
132
|
+
$s1$;
|
|
116
133
|
|
|
134
|
+
EXECUTE $s2$
|
|
117
135
|
COMMENT ON VIEW public.v_units IS
|
|
118
|
-
'Units in the shape the units screen reads (#214), com o endereço vindo de public.addresses (141).'
|
|
136
|
+
'Units in the shape the units screen reads (#214), com o endereço vindo de public.addresses (141).'
|
|
137
|
+
$s2$;
|
|
119
138
|
|
|
120
|
-
-- ── 3. quem escreve o endereço é a tabela de endereços ──────────────────────
|
|
139
|
+
-- ── 3. quem escreve o endereço é a tabela de endereços ──────────────────────
|
|
140
|
+
EXECUTE $s3$
|
|
121
141
|
CREATE OR REPLACE FUNCTION app.trg_v_units_write() RETURNS trigger
|
|
122
142
|
LANGUAGE plpgsql
|
|
123
143
|
SET search_path TO ''
|
|
@@ -197,7 +217,11 @@ BEGIN
|
|
|
197
217
|
|
|
198
218
|
SELECT * INTO NEW FROM public.v_units WHERE id = v_id;
|
|
199
219
|
RETURN NEW;
|
|
200
|
-
END
|
|
220
|
+
END $$
|
|
221
|
+
$s3$;
|
|
201
222
|
|
|
223
|
+
EXECUTE $s4$
|
|
202
224
|
COMMENT ON FUNCTION app.trg_v_units_write() IS
|
|
203
|
-
'Escreve v_units em app.units; o endereço é de public.addresses e não passa por aqui (141).'
|
|
225
|
+
'Escreve v_units em app.units; o endereço é de public.addresses e não passa por aqui (141).'
|
|
226
|
+
$s4$;
|
|
227
|
+
END $guard$;
|
|
@@ -35,6 +35,22 @@ UPDATE app.units u
|
|
|
35
35
|
SET metadata = u.metadata - 'latitude' - 'longitude'
|
|
36
36
|
WHERE u.metadata ? 'latitude' OR u.metadata ? 'longitude';
|
|
37
37
|
|
|
38
|
+
-- Replay guard. 168 widened v_units with the company columns and rewrote its
|
|
39
|
+
-- writer. Re-running this file over that shape fails (CREATE OR REPLACE VIEW
|
|
40
|
+
-- cannot drop columns) and, if it did not, would put this file's older writer
|
|
41
|
+
-- back over 168's. So once the view carries `legal_entity_id`, the view and
|
|
42
|
+
-- the writer below are history and are skipped; what sits above this block is
|
|
43
|
+
-- idempotent and still runs.
|
|
44
|
+
DO $guard$
|
|
45
|
+
BEGIN
|
|
46
|
+
IF EXISTS (SELECT 1 FROM pg_attribute
|
|
47
|
+
WHERE attrelid = 'public.v_units'::regclass
|
|
48
|
+
AND attname = 'legal_entity_id' AND NOT attisdropped) THEN
|
|
49
|
+
RAISE NOTICE '142: v_units already has the 168 shape; view and writer left as they are';
|
|
50
|
+
RETURN;
|
|
51
|
+
END IF;
|
|
52
|
+
|
|
53
|
+
EXECUTE $s1$
|
|
38
54
|
CREATE OR REPLACE VIEW public.v_units WITH (security_invoker='true') AS
|
|
39
55
|
SELECT u.id,
|
|
40
56
|
u.tenant_id,
|
|
@@ -72,11 +88,15 @@ CREATE OR REPLACE VIEW public.v_units WITH (security_invoker='true') AS
|
|
|
72
88
|
WHERE x.owner_type = 'unit' AND x.owner_id = u.id
|
|
73
89
|
ORDER BY x.is_default DESC, x.created_at
|
|
74
90
|
LIMIT 1
|
|
75
|
-
) a ON true
|
|
91
|
+
) a ON true
|
|
92
|
+
$s1$;
|
|
76
93
|
|
|
94
|
+
EXECUTE $s2$
|
|
77
95
|
COMMENT ON VIEW public.v_units IS
|
|
78
|
-
'Units in the shape the units screen reads (#214); endereço e coordenada vêm de public.addresses (141, 142).'
|
|
96
|
+
'Units in the shape the units screen reads (#214); endereço e coordenada vêm de public.addresses (141, 142).'
|
|
97
|
+
$s2$;
|
|
79
98
|
|
|
99
|
+
EXECUTE $s3$
|
|
80
100
|
CREATE OR REPLACE FUNCTION app.trg_v_units_write() RETURNS trigger
|
|
81
101
|
LANGUAGE plpgsql
|
|
82
102
|
SET search_path TO ''
|
|
@@ -151,7 +171,11 @@ BEGIN
|
|
|
151
171
|
|
|
152
172
|
SELECT * INTO NEW FROM public.v_units WHERE id = v_id;
|
|
153
173
|
RETURN NEW;
|
|
154
|
-
END
|
|
174
|
+
END $$
|
|
175
|
+
$s3$;
|
|
155
176
|
|
|
177
|
+
EXECUTE $s4$
|
|
156
178
|
COMMENT ON FUNCTION app.trg_v_units_write() IS
|
|
157
|
-
'Escreve v_units em app.units; endereço e coordenada são de public.addresses (141, 142).'
|
|
179
|
+
'Escreve v_units em app.units; endereço e coordenada são de public.addresses (141, 142).'
|
|
180
|
+
$s4$;
|
|
181
|
+
END $guard$;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- ---------------------------------------------------------------------------
|
|
2
|
+
-- 172 — o pacote pode repetir o mesmo serviço em linhas diferentes.
|
|
3
|
+
--
|
|
4
|
+
-- `service_package_items_unique (package_id, product_id)` veio do porte e
|
|
5
|
+
-- barrava o que a grade do pacote precisa fazer: duplicar uma linha (o mesmo
|
|
6
|
+
-- serviço com outro valor no pacote — a primeira sessão cheia, as demais com
|
|
7
|
+
-- desconto) e trocar o serviço de uma linha para um que já está em outra.
|
|
8
|
+
-- O erro chegava cru na tela: «duplicate key value violates unique constraint».
|
|
9
|
+
--
|
|
10
|
+
-- Nada lia a unicidade: nenhum ON CONFLICT, e quem consome o pacote (venda,
|
|
11
|
+
-- saldo de sessões) itera as linhas. A soma da 166 já é por linha.
|
|
12
|
+
--
|
|
13
|
+
-- O índice da constraint era o único que começava por `package_id`; a lista
|
|
14
|
+
-- do pacote filtra por ele, então um índice simples entra no lugar.
|
|
15
|
+
--
|
|
16
|
+
-- Idempotente e sem tocar em dado.
|
|
17
|
+
-- ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
ALTER TABLE public.service_package_items
|
|
20
|
+
DROP CONSTRAINT IF EXISTS service_package_items_unique;
|
|
21
|
+
|
|
22
|
+
CREATE INDEX IF NOT EXISTS service_package_items_package_idx
|
|
23
|
+
ON public.service_package_items (tenant_id, package_id);
|
package/package.json
CHANGED