@greatapps/greatagents 0.1.10 → 0.1.11
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/package.json +1 -1
- package/src/modules/objectives/index.js +1 -1
- package/src/modules/objectives/properties.js +8 -7
- package/src/product.js +1 -25
- package/docs/ERD_GAGents_Database.mmd +0 -331
- package/scripts/MIGRATION_COMPLETE_DOCUMENTATION.md +0 -672
- package/scripts/README.md +0 -165
- package/scripts/constraints.sql +0 -585
- package/scripts/indexes.sql +0 -661
- package/scripts/migrate_v1.sql +0 -1225
- package/scripts/tables/001_accounts.sql +0 -51
- package/scripts/tables/002_users.sql +0 -69
- package/scripts/tables/003_people.sql +0 -70
- package/scripts/tables/004_tags.sql +0 -62
- package/scripts/tables/005_credentials.sql +0 -79
- package/scripts/tables/006_agents.sql +0 -70
- package/scripts/tables/007_tools.sql +0 -68
- package/scripts/tables/008_channels.sql +0 -75
- package/scripts/tables/009_leads.sql +0 -85
- package/scripts/tables/010_missions.sql +0 -62
- package/scripts/tables/011_objectives.sql +0 -68
- package/scripts/tables/012_conversations.sql +0 -80
- package/scripts/tables/013_objectives_tools.sql +0 -66
- package/scripts/tables/014_messages.sql +0 -78
- package/scripts/tables/015_companies.sql +0 -77
- package/scripts/tables/016_conversations_tags.sql +0 -64
- package/scripts/tables/017_leads_tags.sql +0 -64
- package/scripts/triggers.sql +0 -497
- package/src/modules/channels/index.js +0 -10
- package/src/modules/channels/properties.js +0 -150
- package/src/modules/companies/index.js +0 -10
- package/src/modules/companies/properties.js +0 -168
- package/src/modules/conversations/index.js +0 -10
- package/src/modules/conversations/properties.js +0 -163
- package/src/modules/conversations_tags/index.js +0 -10
- package/src/modules/conversations_tags/properties.js +0 -84
- package/src/modules/credentials/index.js +0 -10
- package/src/modules/credentials/properties.js +0 -271
- package/src/modules/leads/index.js +0 -10
- package/src/modules/leads/properties.js +0 -193
- package/src/modules/leads_tags/index.js +0 -10
- package/src/modules/leads_tags/properties.js +0 -84
- package/src/modules/messages/index.js +0 -10
- package/src/modules/messages/properties.js +0 -152
- package/src/modules/missions/index.js +0 -10
- package/src/modules/missions/properties.js +0 -101
- package/src/modules/objectives_tools/index.js +0 -10
- package/src/modules/objectives_tools/properties.js +0 -109
- package/src/modules/people/index.js +0 -10
- package/src/modules/people/properties.js +0 -161
- package/src/modules/tags/index.js +0 -10
- package/src/modules/tags/properties.js +0 -80
- package/src/modules/tools/index.js +0 -10
- package/src/modules/tools/properties.js +0 -121
package/scripts/indexes.sql
DELETED
|
@@ -1,661 +0,0 @@
|
|
|
1
|
-
-- ============================================================================
|
|
2
|
-
-- Script: indexes.sql
|
|
3
|
-
-- Descrição: Índices para otimização de performance do banco GAgents
|
|
4
|
-
-- Versão: 1.0
|
|
5
|
-
-- Dependências: Todas as tabelas (001-017)
|
|
6
|
-
-- Autor: Sistema de Migração GAgents
|
|
7
|
-
-- Data: 2025-09-20
|
|
8
|
-
-- ============================================================================
|
|
9
|
-
|
|
10
|
-
-- Verificação de pré-requisitos
|
|
11
|
-
DO $$
|
|
12
|
-
BEGIN
|
|
13
|
-
-- Verificar versão PostgreSQL
|
|
14
|
-
IF current_setting('server_version_num')::integer < 140000 THEN
|
|
15
|
-
RAISE EXCEPTION 'PostgreSQL versão 14+ é obrigatória. Versão atual: %', version();
|
|
16
|
-
END IF;
|
|
17
|
-
|
|
18
|
-
RAISE NOTICE '[%] Iniciando criação de índices para otimização de performance', now();
|
|
19
|
-
END $$;
|
|
20
|
-
|
|
21
|
-
-- ========================================
|
|
22
|
-
-- ACCOUNTS - Índices
|
|
23
|
-
-- ========================================
|
|
24
|
-
DO $$
|
|
25
|
-
BEGIN
|
|
26
|
-
RAISE NOTICE '[%] Criando índices para tabela: accounts', now();
|
|
27
|
-
|
|
28
|
-
-- Índices B-tree para campos filterable
|
|
29
|
-
CREATE INDEX IF NOT EXISTS idx_accounts_deleted ON accounts(deleted);
|
|
30
|
-
CREATE INDEX IF NOT EXISTS idx_accounts_datetime_add ON accounts(datetime_add);
|
|
31
|
-
CREATE INDEX IF NOT EXISTS idx_accounts_datetime_alt ON accounts(datetime_alt);
|
|
32
|
-
CREATE INDEX IF NOT EXISTS idx_accounts_datetime_del ON accounts(datetime_del);
|
|
33
|
-
|
|
34
|
-
-- Índices full-text para campos searchable
|
|
35
|
-
CREATE INDEX IF NOT EXISTS idx_accounts_name_search ON accounts
|
|
36
|
-
USING gin(to_tsvector('portuguese', name)) WHERE name IS NOT NULL;
|
|
37
|
-
|
|
38
|
-
-- Índices compostos para consultas frequentes
|
|
39
|
-
CREATE INDEX IF NOT EXISTS idx_accounts_not_deleted ON accounts(id, deleted)
|
|
40
|
-
WHERE deleted = FALSE;
|
|
41
|
-
|
|
42
|
-
RAISE NOTICE '[%] Índices da tabela accounts criados com sucesso', now();
|
|
43
|
-
EXCEPTION
|
|
44
|
-
WHEN OTHERS THEN
|
|
45
|
-
RAISE NOTICE '[%] Erro ao criar índices para accounts: %', now(), SQLERRM;
|
|
46
|
-
RAISE;
|
|
47
|
-
END $$;
|
|
48
|
-
|
|
49
|
-
-- ========================================
|
|
50
|
-
-- USERS - Índices
|
|
51
|
-
-- ========================================
|
|
52
|
-
DO $$
|
|
53
|
-
BEGIN
|
|
54
|
-
RAISE NOTICE '[%] Criando índices para tabela: users', now();
|
|
55
|
-
|
|
56
|
-
-- Índices B-tree para campos filterable
|
|
57
|
-
CREATE INDEX IF NOT EXISTS idx_users_deleted ON users(deleted);
|
|
58
|
-
CREATE INDEX IF NOT EXISTS idx_users_datetime_add ON users(datetime_add);
|
|
59
|
-
CREATE INDEX IF NOT EXISTS idx_users_datetime_alt ON users(datetime_alt);
|
|
60
|
-
CREATE INDEX IF NOT EXISTS idx_users_datetime_del ON users(datetime_del);
|
|
61
|
-
CREATE INDEX IF NOT EXISTS idx_users_profile ON users(profile);
|
|
62
|
-
|
|
63
|
-
-- Índices full-text para campos searchable
|
|
64
|
-
CREATE INDEX IF NOT EXISTS idx_users_name_search ON users
|
|
65
|
-
USING gin(to_tsvector('portuguese', name)) WHERE name IS NOT NULL;
|
|
66
|
-
CREATE INDEX IF NOT EXISTS idx_users_last_name_search ON users
|
|
67
|
-
USING gin(to_tsvector('portuguese', last_name)) WHERE last_name IS NOT NULL;
|
|
68
|
-
CREATE INDEX IF NOT EXISTS idx_users_email_search ON users
|
|
69
|
-
USING gin(to_tsvector('portuguese', email)) WHERE email IS NOT NULL;
|
|
70
|
-
|
|
71
|
-
-- Índices compostos para consultas frequentes
|
|
72
|
-
CREATE INDEX IF NOT EXISTS idx_users_account_not_deleted ON users(id_account, deleted)
|
|
73
|
-
WHERE deleted = FALSE;
|
|
74
|
-
CREATE INDEX IF NOT EXISTS idx_users_account_datetime ON users(id_account, datetime_add);
|
|
75
|
-
|
|
76
|
-
RAISE NOTICE '[%] Índices da tabela users criados com sucesso', now();
|
|
77
|
-
EXCEPTION
|
|
78
|
-
WHEN OTHERS THEN
|
|
79
|
-
RAISE NOTICE '[%] Erro ao criar índices para users: %', now(), SQLERRM;
|
|
80
|
-
RAISE;
|
|
81
|
-
END $$;
|
|
82
|
-
|
|
83
|
-
-- ========================================
|
|
84
|
-
-- PEOPLE - Índices
|
|
85
|
-
-- ========================================
|
|
86
|
-
DO $$
|
|
87
|
-
BEGIN
|
|
88
|
-
RAISE NOTICE '[%] Criando índices para tabela: people', now();
|
|
89
|
-
|
|
90
|
-
-- Índices B-tree para campos filterable
|
|
91
|
-
CREATE INDEX IF NOT EXISTS idx_people_deleted ON people(deleted);
|
|
92
|
-
CREATE INDEX IF NOT EXISTS idx_people_datetime_add ON people(datetime_add);
|
|
93
|
-
CREATE INDEX IF NOT EXISTS idx_people_datetime_alt ON people(datetime_alt);
|
|
94
|
-
CREATE INDEX IF NOT EXISTS idx_people_datetime_del ON people(datetime_del);
|
|
95
|
-
CREATE INDEX IF NOT EXISTS idx_people_birth_date ON people(birth_date);
|
|
96
|
-
|
|
97
|
-
-- Índices full-text para campos searchable
|
|
98
|
-
CREATE INDEX IF NOT EXISTS idx_people_full_name_search ON people
|
|
99
|
-
USING gin(to_tsvector('portuguese', full_name)) WHERE full_name IS NOT NULL;
|
|
100
|
-
CREATE INDEX IF NOT EXISTS idx_people_first_name_search ON people
|
|
101
|
-
USING gin(to_tsvector('portuguese', first_name)) WHERE first_name IS NOT NULL;
|
|
102
|
-
CREATE INDEX IF NOT EXISTS idx_people_last_name_search ON people
|
|
103
|
-
USING gin(to_tsvector('portuguese', last_name)) WHERE last_name IS NOT NULL;
|
|
104
|
-
CREATE INDEX IF NOT EXISTS idx_people_document_search ON people
|
|
105
|
-
USING gin(to_tsvector('portuguese', document)) WHERE document IS NOT NULL;
|
|
106
|
-
|
|
107
|
-
-- Índices compostos para consultas frequentes
|
|
108
|
-
CREATE INDEX IF NOT EXISTS idx_people_account_not_deleted ON people(id_account, deleted)
|
|
109
|
-
WHERE deleted = FALSE;
|
|
110
|
-
CREATE INDEX IF NOT EXISTS idx_people_account_datetime ON people(id_account, datetime_add);
|
|
111
|
-
|
|
112
|
-
RAISE NOTICE '[%] Índices da tabela people criados com sucesso', now();
|
|
113
|
-
EXCEPTION
|
|
114
|
-
WHEN OTHERS THEN
|
|
115
|
-
RAISE NOTICE '[%] Erro ao criar índices para people: %', now(), SQLERRM;
|
|
116
|
-
RAISE;
|
|
117
|
-
END $$;
|
|
118
|
-
|
|
119
|
-
-- ========================================
|
|
120
|
-
-- TAGS - Índices
|
|
121
|
-
-- ========================================
|
|
122
|
-
DO $$
|
|
123
|
-
BEGIN
|
|
124
|
-
RAISE NOTICE '[%] Criando índices para tabela: tags', now();
|
|
125
|
-
|
|
126
|
-
-- Índices B-tree para campos filterable
|
|
127
|
-
CREATE INDEX IF NOT EXISTS idx_tags_deleted ON tags(deleted);
|
|
128
|
-
CREATE INDEX IF NOT EXISTS idx_tags_datetime_add ON tags(datetime_add);
|
|
129
|
-
CREATE INDEX IF NOT EXISTS idx_tags_datetime_alt ON tags(datetime_alt);
|
|
130
|
-
CREATE INDEX IF NOT EXISTS idx_tags_datetime_del ON tags(datetime_del);
|
|
131
|
-
CREATE INDEX IF NOT EXISTS idx_tags_color ON tags(color);
|
|
132
|
-
|
|
133
|
-
-- Índices full-text para campos searchable
|
|
134
|
-
CREATE INDEX IF NOT EXISTS idx_tags_name_search ON tags
|
|
135
|
-
USING gin(to_tsvector('portuguese', name)) WHERE name IS NOT NULL;
|
|
136
|
-
|
|
137
|
-
-- Índices compostos para consultas frequentes
|
|
138
|
-
CREATE INDEX IF NOT EXISTS idx_tags_account_not_deleted ON tags(id_account, deleted)
|
|
139
|
-
WHERE deleted = FALSE;
|
|
140
|
-
CREATE INDEX IF NOT EXISTS idx_tags_account_datetime ON tags(id_account, datetime_add);
|
|
141
|
-
|
|
142
|
-
RAISE NOTICE '[%] Índices da tabela tags criados com sucesso', now();
|
|
143
|
-
EXCEPTION
|
|
144
|
-
WHEN OTHERS THEN
|
|
145
|
-
RAISE NOTICE '[%] Erro ao criar índices para tags: %', now(), SQLERRM;
|
|
146
|
-
RAISE;
|
|
147
|
-
END $$;
|
|
148
|
-
|
|
149
|
-
-- ========================================
|
|
150
|
-
-- CREDENTIALS - Índices
|
|
151
|
-
-- ========================================
|
|
152
|
-
DO $$
|
|
153
|
-
BEGIN
|
|
154
|
-
RAISE NOTICE '[%] Criando índices para tabela: credentials', now();
|
|
155
|
-
|
|
156
|
-
-- Índices B-tree para campos filterable
|
|
157
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_deleted ON credentials(deleted);
|
|
158
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_datetime_add ON credentials(datetime_add);
|
|
159
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_datetime_alt ON credentials(datetime_alt);
|
|
160
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_datetime_del ON credentials(datetime_del);
|
|
161
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_provider ON credentials(provider);
|
|
162
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_authtype ON credentials(authType);
|
|
163
|
-
|
|
164
|
-
-- Índices full-text para campos searchable
|
|
165
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_title_search ON credentials
|
|
166
|
-
USING gin(to_tsvector('portuguese', title)) WHERE title IS NOT NULL;
|
|
167
|
-
|
|
168
|
-
-- Índices compostos para consultas frequentes
|
|
169
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_account_not_deleted ON credentials(id_account, deleted)
|
|
170
|
-
WHERE deleted = FALSE;
|
|
171
|
-
CREATE INDEX IF NOT EXISTS idx_credentials_account_datetime ON credentials(id_account, datetime_add);
|
|
172
|
-
|
|
173
|
-
RAISE NOTICE '[%] Índices da tabela credentials criados com sucesso', now();
|
|
174
|
-
EXCEPTION
|
|
175
|
-
WHEN OTHERS THEN
|
|
176
|
-
RAISE NOTICE '[%] Erro ao criar índices para credentials: %', now(), SQLERRM;
|
|
177
|
-
RAISE;
|
|
178
|
-
END $$;
|
|
179
|
-
|
|
180
|
-
-- ========================================
|
|
181
|
-
-- AGENTS - Índices
|
|
182
|
-
-- ========================================
|
|
183
|
-
DO $$
|
|
184
|
-
BEGIN
|
|
185
|
-
RAISE NOTICE '[%] Criando índices para tabela: agents', now();
|
|
186
|
-
|
|
187
|
-
-- Índices B-tree para campos filterable
|
|
188
|
-
CREATE INDEX IF NOT EXISTS idx_agents_deleted ON agents(deleted);
|
|
189
|
-
CREATE INDEX IF NOT EXISTS idx_agents_datetime_add ON agents(datetime_add);
|
|
190
|
-
CREATE INDEX IF NOT EXISTS idx_agents_datetime_alt ON agents(datetime_alt);
|
|
191
|
-
CREATE INDEX IF NOT EXISTS idx_agents_datetime_del ON agents(datetime_del);
|
|
192
|
-
CREATE INDEX IF NOT EXISTS idx_agents_delaytypying ON agents(delay_typing);
|
|
193
|
-
CREATE INDEX IF NOT EXISTS idx_agents_waiting_time ON agents(waiting_time);
|
|
194
|
-
|
|
195
|
-
-- Índices full-text para campos searchable
|
|
196
|
-
CREATE INDEX IF NOT EXISTS idx_agents_title_search ON agents
|
|
197
|
-
USING gin(to_tsvector('portuguese', title)) WHERE title IS NOT NULL;
|
|
198
|
-
|
|
199
|
-
-- Índices compostos para consultas frequentes
|
|
200
|
-
CREATE INDEX IF NOT EXISTS idx_agents_account_not_deleted ON agents(id_account, deleted)
|
|
201
|
-
WHERE deleted = FALSE;
|
|
202
|
-
CREATE INDEX IF NOT EXISTS idx_agents_account_datetime ON agents(id_account, datetime_add);
|
|
203
|
-
|
|
204
|
-
RAISE NOTICE '[%] Índices da tabela agents criados com sucesso', now();
|
|
205
|
-
EXCEPTION
|
|
206
|
-
WHEN OTHERS THEN
|
|
207
|
-
RAISE NOTICE '[%] Erro ao criar índices para agents: %', now(), SQLERRM;
|
|
208
|
-
RAISE;
|
|
209
|
-
END $$;
|
|
210
|
-
|
|
211
|
-
-- ========================================
|
|
212
|
-
-- TOOLS - Índices
|
|
213
|
-
-- ========================================
|
|
214
|
-
DO $$
|
|
215
|
-
BEGIN
|
|
216
|
-
RAISE NOTICE '[%] Criando índices para tabela: tools', now();
|
|
217
|
-
|
|
218
|
-
-- Índices B-tree para campos filterable
|
|
219
|
-
CREATE INDEX IF NOT EXISTS idx_tools_deleted ON tools(deleted);
|
|
220
|
-
CREATE INDEX IF NOT EXISTS idx_tools_datetime_add ON tools(datetime_add);
|
|
221
|
-
CREATE INDEX IF NOT EXISTS idx_tools_datetime_alt ON tools(datetime_alt);
|
|
222
|
-
CREATE INDEX IF NOT EXISTS idx_tools_datetime_del ON tools(datetime_del);
|
|
223
|
-
CREATE INDEX IF NOT EXISTS idx_tools_type ON tools(type);
|
|
224
|
-
CREATE INDEX IF NOT EXISTS idx_tools_id_credential ON tools(id_credential);
|
|
225
|
-
|
|
226
|
-
-- Índices full-text para campos searchable
|
|
227
|
-
CREATE INDEX IF NOT EXISTS idx_tools_title_search ON tools
|
|
228
|
-
USING gin(to_tsvector('portuguese', title)) WHERE title IS NOT NULL;
|
|
229
|
-
CREATE INDEX IF NOT EXISTS idx_tools_description_search ON tools
|
|
230
|
-
USING gin(to_tsvector('portuguese', description)) WHERE description IS NOT NULL;
|
|
231
|
-
|
|
232
|
-
-- Índices compostos para consultas frequentes
|
|
233
|
-
CREATE INDEX IF NOT EXISTS idx_tools_account_not_deleted ON tools(id_account, deleted)
|
|
234
|
-
WHERE deleted = FALSE;
|
|
235
|
-
CREATE INDEX IF NOT EXISTS idx_tools_account_datetime ON tools(id_account, datetime_add);
|
|
236
|
-
|
|
237
|
-
RAISE NOTICE '[%] Índices da tabela tools criados com sucesso', now();
|
|
238
|
-
EXCEPTION
|
|
239
|
-
WHEN OTHERS THEN
|
|
240
|
-
RAISE NOTICE '[%] Erro ao criar índices para tools: %', now(), SQLERRM;
|
|
241
|
-
RAISE;
|
|
242
|
-
END $$;
|
|
243
|
-
|
|
244
|
-
-- ========================================
|
|
245
|
-
-- CHANNELS - Índices
|
|
246
|
-
-- ========================================
|
|
247
|
-
DO $$
|
|
248
|
-
BEGIN
|
|
249
|
-
RAISE NOTICE '[%] Criando índices para tabela: channels', now();
|
|
250
|
-
|
|
251
|
-
-- Índices B-tree para campos filterable
|
|
252
|
-
CREATE INDEX IF NOT EXISTS idx_channels_deleted ON channels(deleted);
|
|
253
|
-
CREATE INDEX IF NOT EXISTS idx_channels_datetime_add ON channels(datetime_add);
|
|
254
|
-
CREATE INDEX IF NOT EXISTS idx_channels_datetime_alt ON channels(datetime_alt);
|
|
255
|
-
CREATE INDEX IF NOT EXISTS idx_channels_datetime_del ON channels(datetime_del);
|
|
256
|
-
CREATE INDEX IF NOT EXISTS idx_channels_provider ON channels(provider);
|
|
257
|
-
CREATE INDEX IF NOT EXISTS idx_channels_active ON channels(active);
|
|
258
|
-
CREATE INDEX IF NOT EXISTS idx_channels_handle ON channels(handle);
|
|
259
|
-
CREATE INDEX IF NOT EXISTS idx_channels_id_credential ON channels(id_credential);
|
|
260
|
-
|
|
261
|
-
-- Índices full-text para campos searchable
|
|
262
|
-
CREATE INDEX IF NOT EXISTS idx_channels_title_search ON channels
|
|
263
|
-
USING gin(to_tsvector('portuguese', title)) WHERE title IS NOT NULL;
|
|
264
|
-
|
|
265
|
-
-- Índices compostos para consultas frequentes
|
|
266
|
-
CREATE INDEX IF NOT EXISTS idx_channels_account_not_deleted ON channels(id_account, deleted)
|
|
267
|
-
WHERE deleted = FALSE;
|
|
268
|
-
CREATE INDEX IF NOT EXISTS idx_channels_account_datetime ON channels(id_account, datetime_add);
|
|
269
|
-
CREATE INDEX IF NOT EXISTS idx_channels_active_provider ON channels(active, provider)
|
|
270
|
-
WHERE active = TRUE;
|
|
271
|
-
|
|
272
|
-
RAISE NOTICE '[%] Índices da tabela channels criados com sucesso', now();
|
|
273
|
-
EXCEPTION
|
|
274
|
-
WHEN OTHERS THEN
|
|
275
|
-
RAISE NOTICE '[%] Erro ao criar índices para channels: %', now(), SQLERRM;
|
|
276
|
-
RAISE;
|
|
277
|
-
END $$;
|
|
278
|
-
|
|
279
|
-
-- ========================================
|
|
280
|
-
-- LEADS - Índices
|
|
281
|
-
-- ========================================
|
|
282
|
-
DO $$
|
|
283
|
-
BEGIN
|
|
284
|
-
RAISE NOTICE '[%] Criando índices para tabela: leads', now();
|
|
285
|
-
|
|
286
|
-
-- Índices B-tree para campos filterable
|
|
287
|
-
CREATE INDEX IF NOT EXISTS idx_leads_deleted ON leads(deleted);
|
|
288
|
-
CREATE INDEX IF NOT EXISTS idx_leads_datetime_add ON leads(datetime_add);
|
|
289
|
-
CREATE INDEX IF NOT EXISTS idx_leads_datetime_alt ON leads(datetime_alt);
|
|
290
|
-
CREATE INDEX IF NOT EXISTS idx_leads_datetime_del ON leads(datetime_del);
|
|
291
|
-
CREATE INDEX IF NOT EXISTS idx_leads_id_person ON leads(id_person);
|
|
292
|
-
CREATE INDEX IF NOT EXISTS idx_leads_id_user_owner ON leads(id_user_owner);
|
|
293
|
-
CREATE INDEX IF NOT EXISTS idx_leads_id_current_agent ON leads(id_current_agent);
|
|
294
|
-
CREATE INDEX IF NOT EXISTS idx_leads_id_current_mission ON leads(id_current_mission);
|
|
295
|
-
CREATE INDEX IF NOT EXISTS idx_leads_id_current_objective ON leads(id_current_objective);
|
|
296
|
-
|
|
297
|
-
-- Índices full-text para campos searchable
|
|
298
|
-
CREATE INDEX IF NOT EXISTS idx_leads_email_search ON leads
|
|
299
|
-
USING gin(to_tsvector('portuguese', email)) WHERE email IS NOT NULL;
|
|
300
|
-
CREATE INDEX IF NOT EXISTS idx_leads_phone_search ON leads
|
|
301
|
-
USING gin(to_tsvector('portuguese', phone)) WHERE phone IS NOT NULL;
|
|
302
|
-
CREATE INDEX IF NOT EXISTS idx_leads_notes_search ON leads
|
|
303
|
-
USING gin(to_tsvector('portuguese', notes)) WHERE notes IS NOT NULL;
|
|
304
|
-
|
|
305
|
-
-- Índices compostos para consultas frequentes
|
|
306
|
-
CREATE INDEX IF NOT EXISTS idx_leads_account_not_deleted ON leads(id_account, deleted)
|
|
307
|
-
WHERE deleted = FALSE;
|
|
308
|
-
CREATE INDEX IF NOT EXISTS idx_leads_account_datetime ON leads(id_account, datetime_add);
|
|
309
|
-
CREATE INDEX IF NOT EXISTS idx_leads_agent_status ON leads(id_current_agent, deleted)
|
|
310
|
-
WHERE deleted = FALSE AND id_current_agent IS NOT NULL;
|
|
311
|
-
|
|
312
|
-
RAISE NOTICE '[%] Índices da tabela leads criados com sucesso', now();
|
|
313
|
-
EXCEPTION
|
|
314
|
-
WHEN OTHERS THEN
|
|
315
|
-
RAISE NOTICE '[%] Erro ao criar índices para leads: %', now(), SQLERRM;
|
|
316
|
-
RAISE;
|
|
317
|
-
END $$;
|
|
318
|
-
|
|
319
|
-
-- ========================================
|
|
320
|
-
-- MISSIONS - Índices
|
|
321
|
-
-- ========================================
|
|
322
|
-
DO $$
|
|
323
|
-
BEGIN
|
|
324
|
-
RAISE NOTICE '[%] Criando índices para tabela: missions', now();
|
|
325
|
-
|
|
326
|
-
-- Índices B-tree para campos filterable
|
|
327
|
-
CREATE INDEX IF NOT EXISTS idx_missions_deleted ON missions(deleted);
|
|
328
|
-
CREATE INDEX IF NOT EXISTS idx_missions_datetime_add ON missions(datetime_add);
|
|
329
|
-
CREATE INDEX IF NOT EXISTS idx_missions_datetime_alt ON missions(datetime_alt);
|
|
330
|
-
CREATE INDEX IF NOT EXISTS idx_missions_datetime_del ON missions(datetime_del);
|
|
331
|
-
CREATE INDEX IF NOT EXISTS idx_missions_id_agent ON missions(id_agent);
|
|
332
|
-
|
|
333
|
-
-- Índices full-text para campos searchable
|
|
334
|
-
CREATE INDEX IF NOT EXISTS idx_missions_title_search ON missions
|
|
335
|
-
USING gin(to_tsvector('portuguese', title)) WHERE title IS NOT NULL;
|
|
336
|
-
|
|
337
|
-
-- Índices compostos para consultas frequentes
|
|
338
|
-
CREATE INDEX IF NOT EXISTS idx_missions_account_not_deleted ON missions(id_account, deleted)
|
|
339
|
-
WHERE deleted = FALSE;
|
|
340
|
-
CREATE INDEX IF NOT EXISTS idx_missions_account_datetime ON missions(id_account, datetime_add);
|
|
341
|
-
|
|
342
|
-
RAISE NOTICE '[%] Índices da tabela missions criados com sucesso', now();
|
|
343
|
-
EXCEPTION
|
|
344
|
-
WHEN OTHERS THEN
|
|
345
|
-
RAISE NOTICE '[%] Erro ao criar índices para missions: %', now(), SQLERRM;
|
|
346
|
-
RAISE;
|
|
347
|
-
END $$;
|
|
348
|
-
|
|
349
|
-
-- ========================================
|
|
350
|
-
-- OBJECTIVES - Índices
|
|
351
|
-
-- ========================================
|
|
352
|
-
DO $$
|
|
353
|
-
BEGIN
|
|
354
|
-
RAISE NOTICE '[%] Criando índices para tabela: objectives', now();
|
|
355
|
-
|
|
356
|
-
-- Índices B-tree para campos filterable
|
|
357
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_deleted ON objectives(deleted);
|
|
358
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_datetime_add ON objectives(datetime_add);
|
|
359
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_datetime_alt ON objectives(datetime_alt);
|
|
360
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_datetime_del ON objectives(datetime_del);
|
|
361
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_id_mission ON objectives(id_mission);
|
|
362
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_order_number ON objectives(order_number);
|
|
363
|
-
|
|
364
|
-
-- Índices full-text para campos searchable
|
|
365
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_title_search ON objectives
|
|
366
|
-
USING gin(to_tsvector('portuguese', title)) WHERE title IS NOT NULL;
|
|
367
|
-
|
|
368
|
-
-- Índices compostos para consultas frequentes
|
|
369
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_account_not_deleted ON objectives(id_account, deleted)
|
|
370
|
-
WHERE deleted = FALSE;
|
|
371
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_account_datetime ON objectives(id_account, datetime_add);
|
|
372
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_mission_order ON objectives(id_mission, order_number)
|
|
373
|
-
WHERE deleted = FALSE;
|
|
374
|
-
|
|
375
|
-
RAISE NOTICE '[%] Índices da tabela objectives criados com sucesso', now();
|
|
376
|
-
EXCEPTION
|
|
377
|
-
WHEN OTHERS THEN
|
|
378
|
-
RAISE NOTICE '[%] Erro ao criar índices para objectives: %', now(), SQLERRM;
|
|
379
|
-
RAISE;
|
|
380
|
-
END $$;
|
|
381
|
-
|
|
382
|
-
-- ========================================
|
|
383
|
-
-- CONVERSATIONS - Índices
|
|
384
|
-
-- ========================================
|
|
385
|
-
DO $$
|
|
386
|
-
BEGIN
|
|
387
|
-
RAISE NOTICE '[%] Criando índices para tabela: conversations', now();
|
|
388
|
-
|
|
389
|
-
-- Índices B-tree para campos filterable
|
|
390
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_deleted ON conversations(deleted);
|
|
391
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_datetime_add ON conversations(datetime_add);
|
|
392
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_datetime_alt ON conversations(datetime_alt);
|
|
393
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_datetime_del ON conversations(datetime_del);
|
|
394
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_lead ON conversations(id_lead);
|
|
395
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_channel ON conversations(id_channel);
|
|
396
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_assignee ON conversations(id_assignee);
|
|
397
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_last_message_at ON conversations(last_message_at);
|
|
398
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_last_message ON conversations(id_last_message);
|
|
399
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_stop_ai ON conversations(stop_ai);
|
|
400
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_status ON conversations(status);
|
|
401
|
-
|
|
402
|
-
-- Índices compostos para consultas frequentes
|
|
403
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_account_not_deleted ON conversations(id_account, deleted)
|
|
404
|
-
WHERE deleted = FALSE;
|
|
405
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_account_datetime ON conversations(id_account, datetime_add);
|
|
406
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_status_datetime ON conversations(status, last_message_at)
|
|
407
|
-
WHERE deleted = FALSE;
|
|
408
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_channel_status ON conversations(id_channel, status)
|
|
409
|
-
WHERE deleted = FALSE;
|
|
410
|
-
|
|
411
|
-
RAISE NOTICE '[%] Índices da tabela conversations criados com sucesso', now();
|
|
412
|
-
EXCEPTION
|
|
413
|
-
WHEN OTHERS THEN
|
|
414
|
-
RAISE NOTICE '[%] Erro ao criar índices para conversations: %', now(), SQLERRM;
|
|
415
|
-
RAISE;
|
|
416
|
-
END $$;
|
|
417
|
-
|
|
418
|
-
-- ========================================
|
|
419
|
-
-- OBJECTIVES_TOOLS - Índices
|
|
420
|
-
-- ========================================
|
|
421
|
-
DO $$
|
|
422
|
-
BEGIN
|
|
423
|
-
RAISE NOTICE '[%] Criando índices para tabela: objectives_tools', now();
|
|
424
|
-
|
|
425
|
-
-- Índices B-tree para campos filterable
|
|
426
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_deleted ON objectives_tools(deleted);
|
|
427
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_datetime_add ON objectives_tools(datetime_add);
|
|
428
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_datetime_alt ON objectives_tools(datetime_alt);
|
|
429
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_datetime_del ON objectives_tools(datetime_del);
|
|
430
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_id_objective ON objectives_tools(id_objective);
|
|
431
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_id_tool ON objectives_tools(id_tool);
|
|
432
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_wait ON objectives_tools(wait);
|
|
433
|
-
|
|
434
|
-
-- Índices compostos para consultas frequentes
|
|
435
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_account_not_deleted ON objectives_tools(id_account, deleted)
|
|
436
|
-
WHERE deleted = FALSE;
|
|
437
|
-
CREATE INDEX IF NOT EXISTS idx_objectives_tools_account_datetime ON objectives_tools(id_account, datetime_add);
|
|
438
|
-
|
|
439
|
-
-- Índice único para evitar duplicatas
|
|
440
|
-
CREATE UNIQUE INDEX IF NOT EXISTS idx_objectives_tools_unique ON objectives_tools(id_objective, id_tool)
|
|
441
|
-
WHERE deleted = FALSE;
|
|
442
|
-
|
|
443
|
-
RAISE NOTICE '[%] Índices da tabela objectives_tools criados com sucesso', now();
|
|
444
|
-
EXCEPTION
|
|
445
|
-
WHEN OTHERS THEN
|
|
446
|
-
RAISE NOTICE '[%] Erro ao criar índices para objectives_tools: %', now(), SQLERRM;
|
|
447
|
-
RAISE;
|
|
448
|
-
END $$;
|
|
449
|
-
|
|
450
|
-
-- ========================================
|
|
451
|
-
-- MESSAGES - Índices
|
|
452
|
-
-- ========================================
|
|
453
|
-
DO $$
|
|
454
|
-
BEGIN
|
|
455
|
-
RAISE NOTICE '[%] Criando índices para tabela: messages', now();
|
|
456
|
-
|
|
457
|
-
-- Índices B-tree para campos filterable
|
|
458
|
-
CREATE INDEX IF NOT EXISTS idx_messages_deleted ON messages(deleted);
|
|
459
|
-
CREATE INDEX IF NOT EXISTS idx_messages_datetime_add ON messages(datetime_add);
|
|
460
|
-
CREATE INDEX IF NOT EXISTS idx_messages_datetime_alt ON messages(datetime_alt);
|
|
461
|
-
CREATE INDEX IF NOT EXISTS idx_messages_datetime_del ON messages(datetime_del);
|
|
462
|
-
CREATE INDEX IF NOT EXISTS idx_messages_id_conversation ON messages(id_conversation);
|
|
463
|
-
CREATE INDEX IF NOT EXISTS idx_messages_id_agent ON messages(id_agent);
|
|
464
|
-
CREATE INDEX IF NOT EXISTS idx_messages_id_user ON messages(id_user);
|
|
465
|
-
CREATE INDEX IF NOT EXISTS idx_messages_direction ON messages(direction);
|
|
466
|
-
CREATE INDEX IF NOT EXISTS idx_messages_role ON messages(role);
|
|
467
|
-
|
|
468
|
-
-- Índices full-text para campos searchable
|
|
469
|
-
CREATE INDEX IF NOT EXISTS idx_messages_content_search ON messages
|
|
470
|
-
USING gin(to_tsvector('portuguese', content)) WHERE content IS NOT NULL;
|
|
471
|
-
|
|
472
|
-
-- Índices compostos para consultas frequentes
|
|
473
|
-
CREATE INDEX IF NOT EXISTS idx_messages_account_not_deleted ON messages(id_account, deleted)
|
|
474
|
-
WHERE deleted = FALSE;
|
|
475
|
-
CREATE INDEX IF NOT EXISTS idx_messages_account_datetime ON messages(id_account, datetime_add);
|
|
476
|
-
CREATE INDEX IF NOT EXISTS idx_messages_conversation_datetime ON messages(id_conversation, datetime_add)
|
|
477
|
-
WHERE deleted = FALSE;
|
|
478
|
-
CREATE INDEX IF NOT EXISTS idx_messages_conversation_role ON messages(id_conversation, role)
|
|
479
|
-
WHERE deleted = FALSE;
|
|
480
|
-
|
|
481
|
-
RAISE NOTICE '[%] Índices da tabela messages criados com sucesso', now();
|
|
482
|
-
EXCEPTION
|
|
483
|
-
WHEN OTHERS THEN
|
|
484
|
-
RAISE NOTICE '[%] Erro ao criar índices para messages: %', now(), SQLERRM;
|
|
485
|
-
RAISE;
|
|
486
|
-
END $$;
|
|
487
|
-
|
|
488
|
-
-- ========================================
|
|
489
|
-
-- COMPANIES - Índices
|
|
490
|
-
-- ========================================
|
|
491
|
-
DO $$
|
|
492
|
-
BEGIN
|
|
493
|
-
RAISE NOTICE '[%] Criando índices para tabela: companies', now();
|
|
494
|
-
|
|
495
|
-
-- Índices B-tree para campos filterable
|
|
496
|
-
CREATE INDEX IF NOT EXISTS idx_companies_deleted ON companies(deleted);
|
|
497
|
-
CREATE INDEX IF NOT EXISTS idx_companies_datetime_add ON companies(datetime_add);
|
|
498
|
-
CREATE INDEX IF NOT EXISTS idx_companies_datetime_alt ON companies(datetime_alt);
|
|
499
|
-
CREATE INDEX IF NOT EXISTS idx_companies_datetime_del ON companies(datetime_del);
|
|
500
|
-
CREATE INDEX IF NOT EXISTS idx_companies_id_lead ON companies(id_lead);
|
|
501
|
-
|
|
502
|
-
-- Índices full-text para campos searchable
|
|
503
|
-
CREATE INDEX IF NOT EXISTS idx_companies_name_search ON companies
|
|
504
|
-
USING gin(to_tsvector('portuguese', name)) WHERE name IS NOT NULL;
|
|
505
|
-
CREATE INDEX IF NOT EXISTS idx_companies_website_search ON companies
|
|
506
|
-
USING gin(to_tsvector('portuguese', website)) WHERE website IS NOT NULL;
|
|
507
|
-
CREATE INDEX IF NOT EXISTS idx_companies_document_search ON companies
|
|
508
|
-
USING gin(to_tsvector('portuguese', document)) WHERE document IS NOT NULL;
|
|
509
|
-
CREATE INDEX IF NOT EXISTS idx_companies_notes_search ON companies
|
|
510
|
-
USING gin(to_tsvector('portuguese', notes)) WHERE notes IS NOT NULL;
|
|
511
|
-
CREATE INDEX IF NOT EXISTS idx_companies_industry_search ON companies
|
|
512
|
-
USING gin(to_tsvector('portuguese', industry)) WHERE industry IS NOT NULL;
|
|
513
|
-
CREATE INDEX IF NOT EXISTS idx_companies_size_search ON companies
|
|
514
|
-
USING gin(to_tsvector('portuguese', size)) WHERE size IS NOT NULL;
|
|
515
|
-
|
|
516
|
-
-- Índices compostos para consultas frequentes
|
|
517
|
-
CREATE INDEX IF NOT EXISTS idx_companies_account_not_deleted ON companies(id_account, deleted)
|
|
518
|
-
WHERE deleted = FALSE;
|
|
519
|
-
CREATE INDEX IF NOT EXISTS idx_companies_account_datetime ON companies(id_account, datetime_add);
|
|
520
|
-
|
|
521
|
-
RAISE NOTICE '[%] Índices da tabela companies criados com sucesso', now();
|
|
522
|
-
EXCEPTION
|
|
523
|
-
WHEN OTHERS THEN
|
|
524
|
-
RAISE NOTICE '[%] Erro ao criar índices para companies: %', now(), SQLERRM;
|
|
525
|
-
RAISE;
|
|
526
|
-
END $$;
|
|
527
|
-
|
|
528
|
-
-- ========================================
|
|
529
|
-
-- CONVERSATIONS_TAGS - Índices
|
|
530
|
-
-- ========================================
|
|
531
|
-
DO $$
|
|
532
|
-
BEGIN
|
|
533
|
-
RAISE NOTICE '[%] Criando índices para tabela: conversations_tags', now();
|
|
534
|
-
|
|
535
|
-
-- Índices B-tree para campos filterable
|
|
536
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_tags_deleted ON conversations_tags(deleted);
|
|
537
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_tags_datetime_add ON conversations_tags(datetime_add);
|
|
538
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_tags_datetime_alt ON conversations_tags(datetime_alt);
|
|
539
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_tags_datetime_del ON conversations_tags(datetime_del);
|
|
540
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_tags_id_conversation ON conversations_tags(id_conversation);
|
|
541
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_tags_id_tag ON conversations_tags(id_tag);
|
|
542
|
-
|
|
543
|
-
-- Índices compostos para consultas frequentes
|
|
544
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_tags_account_not_deleted ON conversations_tags(id_account, deleted)
|
|
545
|
-
WHERE deleted = FALSE;
|
|
546
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_tags_account_datetime ON conversations_tags(id_account, datetime_add);
|
|
547
|
-
|
|
548
|
-
-- Índice único para evitar duplicatas (já existe na tabela, mas vamos garantir)
|
|
549
|
-
CREATE UNIQUE INDEX IF NOT EXISTS idx_conversations_tags_unique_rel ON conversations_tags(id_conversation, id_tag)
|
|
550
|
-
WHERE deleted = FALSE;
|
|
551
|
-
|
|
552
|
-
RAISE NOTICE '[%] Índices da tabela conversations_tags criados com sucesso', now();
|
|
553
|
-
EXCEPTION
|
|
554
|
-
WHEN OTHERS THEN
|
|
555
|
-
RAISE NOTICE '[%] Erro ao criar índices para conversations_tags: %', now(), SQLERRM;
|
|
556
|
-
RAISE;
|
|
557
|
-
END $$;
|
|
558
|
-
|
|
559
|
-
-- ========================================
|
|
560
|
-
-- LEADS_TAGS - Índices
|
|
561
|
-
-- ========================================
|
|
562
|
-
DO $$
|
|
563
|
-
BEGIN
|
|
564
|
-
RAISE NOTICE '[%] Criando índices para tabela: leads_tags', now();
|
|
565
|
-
|
|
566
|
-
-- Índices B-tree para campos filterable
|
|
567
|
-
CREATE INDEX IF NOT EXISTS idx_leads_tags_deleted ON leads_tags(deleted);
|
|
568
|
-
CREATE INDEX IF NOT EXISTS idx_leads_tags_datetime_add ON leads_tags(datetime_add);
|
|
569
|
-
CREATE INDEX IF NOT EXISTS idx_leads_tags_datetime_alt ON leads_tags(datetime_alt);
|
|
570
|
-
CREATE INDEX IF NOT EXISTS idx_leads_tags_datetime_del ON leads_tags(datetime_del);
|
|
571
|
-
CREATE INDEX IF NOT EXISTS idx_leads_tags_id_lead ON leads_tags(id_lead);
|
|
572
|
-
CREATE INDEX IF NOT EXISTS idx_leads_tags_id_tag ON leads_tags(id_tag);
|
|
573
|
-
|
|
574
|
-
-- Índices compostos para consultas frequentes
|
|
575
|
-
CREATE INDEX IF NOT EXISTS idx_leads_tags_account_not_deleted ON leads_tags(id_account, deleted)
|
|
576
|
-
WHERE deleted = FALSE;
|
|
577
|
-
CREATE INDEX IF NOT EXISTS idx_leads_tags_account_datetime ON leads_tags(id_account, datetime_add);
|
|
578
|
-
|
|
579
|
-
-- Índice único para evitar duplicatas (já existe na tabela, mas vamos garantir)
|
|
580
|
-
CREATE UNIQUE INDEX IF NOT EXISTS idx_leads_tags_unique_rel ON leads_tags(id_lead, id_tag)
|
|
581
|
-
WHERE deleted = FALSE;
|
|
582
|
-
|
|
583
|
-
RAISE NOTICE '[%] Índices da tabela leads_tags criados com sucesso', now();
|
|
584
|
-
EXCEPTION
|
|
585
|
-
WHEN OTHERS THEN
|
|
586
|
-
RAISE NOTICE '[%] Erro ao criar índices para leads_tags: %', now(), SQLERRM;
|
|
587
|
-
RAISE;
|
|
588
|
-
END $$;
|
|
589
|
-
|
|
590
|
-
-- ========================================
|
|
591
|
-
-- ÍNDICES GLOBAIS PARA PERFORMANCE
|
|
592
|
-
-- ========================================
|
|
593
|
-
DO $$
|
|
594
|
-
BEGIN
|
|
595
|
-
RAISE NOTICE '[%] Criando índices globais para performance', now();
|
|
596
|
-
|
|
597
|
-
-- Índice para consultas cross-table por conta
|
|
598
|
-
CREATE INDEX IF NOT EXISTS idx_global_account_activity ON accounts(id, datetime_add)
|
|
599
|
-
WHERE deleted = FALSE;
|
|
600
|
-
|
|
601
|
-
-- Índices para consultas temporais frequentes
|
|
602
|
-
CREATE INDEX IF NOT EXISTS idx_global_recent_activity_conversations ON conversations(datetime_add DESC, id_account)
|
|
603
|
-
WHERE deleted = FALSE;
|
|
604
|
-
CREATE INDEX IF NOT EXISTS idx_global_recent_activity_messages ON messages(datetime_add DESC, id_account)
|
|
605
|
-
WHERE deleted = FALSE;
|
|
606
|
-
CREATE INDEX IF NOT EXISTS idx_global_recent_activity_leads ON leads(datetime_add DESC, id_account)
|
|
607
|
-
WHERE deleted = FALSE;
|
|
608
|
-
|
|
609
|
-
RAISE NOTICE '[%] Índices globais criados com sucesso', now();
|
|
610
|
-
EXCEPTION
|
|
611
|
-
WHEN OTHERS THEN
|
|
612
|
-
RAISE NOTICE '[%] Erro ao criar índices globais: %', now(), SQLERRM;
|
|
613
|
-
RAISE;
|
|
614
|
-
END $$;
|
|
615
|
-
|
|
616
|
-
-- ========================================
|
|
617
|
-
-- VERIFICAÇÃO FINAL E ESTATÍSTICAS
|
|
618
|
-
-- ========================================
|
|
619
|
-
DO $$
|
|
620
|
-
DECLARE
|
|
621
|
-
total_indexes INTEGER;
|
|
622
|
-
total_unique_indexes INTEGER;
|
|
623
|
-
total_gin_indexes INTEGER;
|
|
624
|
-
BEGIN
|
|
625
|
-
-- Contar índices criados
|
|
626
|
-
SELECT COUNT(*) INTO total_indexes
|
|
627
|
-
FROM pg_indexes
|
|
628
|
-
WHERE schemaname = 'public'
|
|
629
|
-
AND indexname LIKE 'idx_%';
|
|
630
|
-
|
|
631
|
-
SELECT COUNT(*) INTO total_unique_indexes
|
|
632
|
-
FROM pg_indexes
|
|
633
|
-
WHERE schemaname = 'public'
|
|
634
|
-
AND indexname LIKE 'idx_%'
|
|
635
|
-
AND indexdef LIKE '%UNIQUE%';
|
|
636
|
-
|
|
637
|
-
SELECT COUNT(*) INTO total_gin_indexes
|
|
638
|
-
FROM pg_indexes
|
|
639
|
-
WHERE schemaname = 'public'
|
|
640
|
-
AND indexname LIKE 'idx_%'
|
|
641
|
-
AND indexdef LIKE '%gin%';
|
|
642
|
-
|
|
643
|
-
RAISE NOTICE '[%] ========================================', now();
|
|
644
|
-
RAISE NOTICE '[%] RESUMO DA CRIAÇÃO DE ÍNDICES:', now();
|
|
645
|
-
RAISE NOTICE '[%] ========================================', now();
|
|
646
|
-
RAISE NOTICE '[%] Total de índices criados: %', now(), total_indexes;
|
|
647
|
-
RAISE NOTICE '[%] Índices únicos (relacionamentos): %', now(), total_unique_indexes;
|
|
648
|
-
RAISE NOTICE '[%] Índices GIN (full-text search): %', now(), total_gin_indexes;
|
|
649
|
-
RAISE NOTICE '[%] Índices B-tree (filterable): %', now(), (total_indexes - total_gin_indexes);
|
|
650
|
-
RAISE NOTICE '[%] ========================================', now();
|
|
651
|
-
RAISE NOTICE '[%] Criação de índices concluída com sucesso!', now();
|
|
652
|
-
RAISE NOTICE '[%] ========================================', now();
|
|
653
|
-
|
|
654
|
-
-- Sugestão para próximos passos
|
|
655
|
-
RAISE NOTICE '[%] PRÓXIMOS PASSOS SUGERIDOS:', now();
|
|
656
|
-
RAISE NOTICE '[%] 1. Execute o script constraints.sql para foreign keys', now();
|
|
657
|
-
RAISE NOTICE '[%] 2. Execute o script triggers.sql para auditoria', now();
|
|
658
|
-
RAISE NOTICE '[%] 3. Execute ANALYZE para atualizar estatísticas', now();
|
|
659
|
-
RAISE NOTICE '[%] 4. Monitore performance das consultas', now();
|
|
660
|
-
|
|
661
|
-
END $$;
|