@greatapps/greatagents 0.1.6 → 0.1.7

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.
@@ -0,0 +1,333 @@
1
+ %%{init: {
2
+ 'title': 'GAGents Database - Entity Relationship Diagram',
3
+ 'theme': 'base',
4
+ 'themeVariables': {
5
+ 'primaryColor': '#2E86AB',
6
+ 'primaryTextColor': '#000000',
7
+ 'primaryBorderColor': '#A23B72',
8
+ 'lineColor': '#F18F01',
9
+ 'sectionBkgColor': '#A23B72',
10
+ 'altSectionBkgColor': '#C73E1D'
11
+ }
12
+ }}%%
13
+
14
+ erDiagram
15
+
16
+ accounts {
17
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
18
+ VARCHAR(100) name "searchable, maxLength=100"
19
+ BOOLEAN deleted "DEFAULT false"
20
+ TIMESTAMP datetime_add "filterable, updatable=false"
21
+ TIMESTAMP datetime_alt "filterable"
22
+ TIMESTAMP datetime_del "filterable"
23
+ }
24
+
25
+ users {
26
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
27
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
28
+ VARCHAR(50) name "searchable, maxLength=50"
29
+ VARCHAR last_name "searchable"
30
+ VARCHAR email "NOT NULL, searchable, filterable, format=email"
31
+ VARCHAR profile "DEFAULT 'collaborator'"
32
+ IMAGE photo "types=[png,jpg,jpeg,gif,svg,webp], storage=gapps-r1-storage, 160x160"
33
+ BOOLEAN deleted "DEFAULT false"
34
+ TIMESTAMP datetime_add "filterable, updatable=false"
35
+ TIMESTAMP datetime_alt "filterable"
36
+ TIMESTAMP datetime_del "filterable"
37
+ }
38
+
39
+ people {
40
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
41
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
42
+ VARCHAR(255) full_name "searchable, maxLength=255"
43
+ VARCHAR(255) first_name "searchable, maxLength=255"
44
+ VARCHAR(255) last_name "searchable, maxLength=255"
45
+ IMAGE photo "types=[png,jpg,jpeg,gif,svg,webp], storage=gpages, 200x200"
46
+ VARCHAR(50) document "searchable, maxLength=50"
47
+ DATE birth_date "filterable"
48
+ BOOLEAN deleted "DEFAULT false, filterable"
49
+ TIMESTAMP datetime_add "filterable, updatable=false"
50
+ TIMESTAMP datetime_alt "filterable"
51
+ TIMESTAMP datetime_del "filterable"
52
+ }
53
+
54
+ tags {
55
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
56
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
57
+ VARCHAR(255) name "NOT NULL, searchable, filterable, maxLength=255"
58
+ VARCHAR color "DEFAULT '#000000', filterable"
59
+ BOOLEAN deleted "DEFAULT false, filterable"
60
+ TIMESTAMP datetime_add "filterable, updatable=false"
61
+ TIMESTAMP datetime_alt "filterable"
62
+ TIMESTAMP datetime_del "filterable"
63
+ }
64
+
65
+ credentials {
66
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
67
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
68
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
69
+ VARCHAR provider "NOT NULL, filterable, DEFAULT 'web-chat'"
70
+ VARCHAR authType "NOT NULL, filterable, DEFAULT 'none'"
71
+ VARCHAR userName
72
+ VARCHAR password
73
+ VARCHAR apiKey
74
+ VARCHAR token
75
+ VARCHAR paramName
76
+ VARCHAR refreshToken
77
+ VARCHAR clientSecret
78
+ VARCHAR clientId
79
+ VARCHAR sendIn "DEFAULT 'none'"
80
+ VARCHAR scheme "DEFAULT 'none'"
81
+ VARCHAR prefix
82
+ BOOLEAN deleted "DEFAULT false, filterable"
83
+ TIMESTAMP datetime_add "filterable, updatable=false"
84
+ TIMESTAMP datetime_alt "filterable"
85
+ TIMESTAMP datetime_del "filterable"
86
+ }
87
+
88
+ %% ==========================================
89
+ %% AI & AUTOMATION DOMAIN (Domínio de IA)
90
+ %% ==========================================
91
+
92
+ agents {
93
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
94
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
95
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
96
+ IMAGE photo "types=[png,jpg,jpeg,gif,svg,webp], storage=gpages, 200x200"
97
+ TEXT prompt
98
+ INTEGER delayTyping "DEFAULT 0, filterable"
99
+ INTEGER waitingTime "DEFAULT 0, filterable"
100
+ BOOLEAN deleted "DEFAULT false, filterable"
101
+ TIMESTAMP datetime_add "filterable, updatable=false"
102
+ TIMESTAMP datetime_alt "filterable"
103
+ TIMESTAMP datetime_del "filterable"
104
+ }
105
+
106
+ tools {
107
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
108
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
109
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
110
+ VARCHAR type "filterable, DEFAULT 'mcp'"
111
+ VARCHAR(1000) description "searchable, filterable, maxLength=1000"
112
+ INTEGER id_credential FK "filterable, index, optional"
113
+ BOOLEAN deleted "DEFAULT false, filterable"
114
+ TIMESTAMP datetime_add "filterable, updatable=false"
115
+ TIMESTAMP datetime_alt "filterable"
116
+ TIMESTAMP datetime_del "filterable"
117
+ }
118
+
119
+ missions {
120
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
121
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
122
+ INTEGER id_agent FK "NOT NULL, filterable, index, reference=agents.id"
123
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
124
+ TEXT prompt
125
+ BOOLEAN deleted "DEFAULT false, filterable"
126
+ TIMESTAMP datetime_add "filterable, updatable=false"
127
+ TIMESTAMP datetime_alt "filterable"
128
+ TIMESTAMP datetime_del "filterable"
129
+ }
130
+
131
+ objectives {
132
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
133
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
134
+ INTEGER id_mission FK "NOT NULL, filterable, index, reference=missions.id"
135
+ INTEGER order "NOT NULL, filterable, DEFAULT 0"
136
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
137
+ TEXT prompt
138
+ BOOLEAN deleted "DEFAULT false, filterable"
139
+ TIMESTAMP datetime_add "filterable, updatable=false"
140
+ TIMESTAMP datetime_alt "filterable"
141
+ TIMESTAMP datetime_del "filterable"
142
+ }
143
+
144
+ objectives_tools {
145
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
146
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
147
+ INTEGER id_objective FK "filterable, index, reference=objectives.id"
148
+ INTEGER id_tool FK "filterable, index, reference=tools.id"
149
+ TEXT instructions
150
+ BOOLEAN wait "DEFAULT false"
151
+ BOOLEAN deleted "DEFAULT false, filterable"
152
+ TIMESTAMP datetime_add "filterable, updatable=false"
153
+ TIMESTAMP datetime_alt "filterable"
154
+ TIMESTAMP datetime_del "filterable"
155
+ }
156
+
157
+ %% ==========================================
158
+ %% COMMUNICATION DOMAIN (Domínio de Comunicação)
159
+ %% ==========================================
160
+
161
+ channels {
162
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
163
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
164
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
165
+ VARCHAR provider "NOT NULL, filterable, DEFAULT 'web-chat'"
166
+ VARCHAR url
167
+ BOOLEAN active "DEFAULT true, filterable"
168
+ INTEGER id_credential FK "optional, reference=credentials.id"
169
+ VARCHAR(255) handle "filterable, maxLength=255"
170
+ BOOLEAN deleted "DEFAULT false, filterable"
171
+ TIMESTAMP datetime_add "filterable, updatable=false"
172
+ TIMESTAMP datetime_alt "filterable"
173
+ TIMESTAMP datetime_del "filterable"
174
+ }
175
+
176
+ conversations {
177
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
178
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
179
+ INTEGER id_lead FK "filterable, index, reference=leads.id"
180
+ INTEGER id_channel FK "filterable, index, reference=channels.id"
181
+ INTEGER id_assignee FK "filterable, index, reference=users.id"
182
+ INTEGER id_last_agent FK "filterable, index, optional, reference=agents.id"
183
+ TIMESTAMP last_message_at "filterable, optional"
184
+ INTEGER id_last_message FK "filterable, index, optional, reference=messages.id"
185
+ BOOLEAN stop_ai "DEFAULT false, filterable"
186
+ VARCHAR status "filterable, DEFAULT 'open'"
187
+ BOOLEAN deleted "DEFAULT false, filterable"
188
+ TIMESTAMP datetime_add "filterable, updatable=false"
189
+ TIMESTAMP datetime_alt "filterable"
190
+ TIMESTAMP datetime_del "filterable"
191
+ }
192
+
193
+ messages {
194
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
195
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
196
+ INTEGER id_conversation FK "filterable, index, reference=conversations.id"
197
+ INTEGER id_agent FK "filterable, index, optional, reference=agents.id"
198
+ INTEGER id_user FK "filterable, index, optional, reference=users.id"
199
+ VARCHAR direction "DEFAULT 'in', filterable"
200
+ VARCHAR role "DEFAULT 'user', filterable"
201
+ TEXT content "NOT NULL"
202
+ BOOLEAN deleted "DEFAULT false, filterable"
203
+ TIMESTAMP datetime_add "filterable, updatable=false"
204
+ TIMESTAMP datetime_alt "filterable"
205
+ TIMESTAMP datetime_del "filterable"
206
+ }
207
+
208
+ %% ==========================================
209
+ %% CRM & ORGANIZATION DOMAIN (Domínio CRM)
210
+ %% ==========================================
211
+
212
+ leads {
213
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
214
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
215
+ INTEGER id_person FK "NOT NULL, filterable, reference=people.id"
216
+ VARCHAR(255) email "searchable, maxLength=255, pattern=email"
217
+ VARCHAR(20) phone "searchable, maxLength=20, pattern=phone"
218
+ INTEGER id_user_owner FK "filterable, index, reference=users.id"
219
+ INTEGER id_current_agent FK "filterable, index, reference=agents.id"
220
+ INTEGER id_current_mission FK "filterable, index, reference=missions.id"
221
+ INTEGER id_current_objective FK "filterable, index, reference=objectives.id"
222
+ TEXT notes "searchable"
223
+ BOOLEAN deleted "DEFAULT false, filterable"
224
+ TIMESTAMP datetime_add "filterable, updatable=false"
225
+ TIMESTAMP datetime_alt "filterable"
226
+ TIMESTAMP datetime_del "filterable"
227
+ }
228
+
229
+ companies {
230
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
231
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
232
+ INTEGER id_lead FK "NOT NULL, filterable, reference=leads.id"
233
+ VARCHAR(255) name "searchable, maxLength=255"
234
+ VARCHAR(255) website "searchable, maxLength=255, pattern=url"
235
+ VARCHAR(50) document "searchable, maxLength=50"
236
+ TEXT notes "searchable"
237
+ VARCHAR industry "searchable"
238
+ VARCHAR size "searchable"
239
+ BOOLEAN deleted "DEFAULT false, filterable"
240
+ TIMESTAMP datetime_add "filterable, updatable=false"
241
+ TIMESTAMP datetime_alt "filterable"
242
+ TIMESTAMP datetime_del "filterable"
243
+ }
244
+
245
+ conversations_tags {
246
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
247
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
248
+ INTEGER id_conversation FK "filterable, index, reference=conversations.id"
249
+ INTEGER id_tag FK "filterable, index, reference=tags.id"
250
+ BOOLEAN deleted "DEFAULT false, filterable"
251
+ TIMESTAMP datetime_add "filterable, updatable=false"
252
+ TIMESTAMP datetime_alt "filterable"
253
+ TIMESTAMP datetime_del "filterable"
254
+ }
255
+
256
+ leads_tags {
257
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
258
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
259
+ INTEGER id_lead FK "filterable, index, reference=leads.id"
260
+ INTEGER id_tag FK "filterable, index, reference=tags.id"
261
+ BOOLEAN deleted "DEFAULT false, filterable"
262
+ TIMESTAMP datetime_add "filterable, updatable=false"
263
+ TIMESTAMP datetime_alt "filterable"
264
+ TIMESTAMP datetime_del "filterable"
265
+ }
266
+
267
+ %% ==========================================
268
+ %% RELACIONAMENTOS 1:N (Um para Muitos)
269
+ %% ==========================================
270
+
271
+ %% ACCOUNTS como entidade central (Multi-tenancy)
272
+ accounts ||--o{ users : "Multi-tenant"
273
+ accounts ||--o{ people : "Multi-tenant"
274
+ accounts ||--o{ tags : "Multi-tenant"
275
+ accounts ||--o{ credentials : "Multi-tenant"
276
+ accounts ||--o{ agents : "Multi-tenant"
277
+ accounts ||--o{ tools : "Multi-tenant"
278
+ accounts ||--o{ missions : "Multi-tenant"
279
+ accounts ||--o{ objectives : "Multi-tenant"
280
+ accounts ||--o{ objectives_tools : "Multi-tenant"
281
+ accounts ||--o{ channels : "Multi-tenant"
282
+ accounts ||--o{ conversations : "Multi-tenant"
283
+ accounts ||--o{ messages : "Multi-tenant"
284
+ accounts ||--o{ leads : "Multi-tenant"
285
+ accounts ||--o{ companies : "Multi-tenant"
286
+ accounts ||--o{ conversations_tags : "Multi-tenant"
287
+ accounts ||--o{ leads_tags : "Multi-tenant"
288
+
289
+ %% RELACIONAMENTOS PRINCIPAIS
290
+ people ||--o{ leads : "Person-Lead"
291
+ leads ||--o{ companies : "Lead-Company"
292
+ leads ||--o{ conversations : "Lead-Conversation"
293
+
294
+ %% AI & AUTOMATION RELATIONSHIPS
295
+ agents ||--o{ missions : "Agent-Mission"
296
+ missions ||--o{ objectives : "Mission-Objective"
297
+ objectives ||--o{ objectives_tools : "Objective-ObjectiveTool"
298
+ tools ||--o{ objectives_tools : "Tool-ObjectiveTool"
299
+
300
+ %% COMMUNICATION RELATIONSHIPS
301
+ channels ||--o{ conversations : "Channel-Conversation"
302
+ conversations ||--o{ messages : "Conversation-Message"
303
+
304
+ %% USER ASSIGNMENTS
305
+ users ||--o{ conversations : "User-ConversationAssignee"
306
+ users ||--o{ leads : "User-LeadOwner"
307
+ users ||--o{ messages : "User-Message"
308
+
309
+ %% AGENT RELATIONSHIPS
310
+ agents ||--o{ conversations : "Agent-LastAgent"
311
+ agents ||--o{ messages : "Agent-Message"
312
+ agents ||--o{ leads : "Agent-CurrentAgent"
313
+
314
+ %% MISSION & OBJECTIVE CURRENT STATES
315
+ missions ||--o{ leads : "Mission-CurrentMission"
316
+ objectives ||--o{ leads : "Objective-CurrentObjective"
317
+
318
+ %% CREDENTIAL RELATIONSHIPS
319
+ credentials ||--o{ tools : "Credential-Tool"
320
+ credentials ||--o{ channels : "Credential-Channel"
321
+
322
+ %% TAG RELATIONSHIPS
323
+ tags ||--o{ conversations_tags : "Tag-ConversationTag"
324
+ tags ||--o{ leads_tags : "Tag-LeadTag"
325
+ conversations ||--o{ conversations_tags : "Conversation-ConversationTag"
326
+ leads ||--o{ leads_tags : "Lead-LeadTag"
327
+
328
+ %% ==========================================
329
+ %% RELACIONAMENTO CÍCLICO ESPECIAL
330
+ %% ==========================================
331
+
332
+ %% CYCLIC REFERENCE: conversations ↔ messages
333
+ conversations ||--o| messages : "LastMessage"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/greatagents",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Schemas para GreatAgents",
5
5
  "main": "./src/product.js",
6
6
  "type": "module"
@@ -289,10 +289,10 @@ BEGIN
289
289
  CREATE INDEX IF NOT EXISTS idx_leads_datetime_alt ON leads(datetime_alt);
290
290
  CREATE INDEX IF NOT EXISTS idx_leads_datetime_del ON leads(datetime_del);
291
291
  CREATE INDEX IF NOT EXISTS idx_leads_id_person ON leads(id_person);
292
- CREATE INDEX IF NOT EXISTS idx_leads_owner_user_id ON leads(owner_user_id);
293
- CREATE INDEX IF NOT EXISTS idx_leads_current_agent_id ON leads(current_agent_id);
294
- CREATE INDEX IF NOT EXISTS idx_leads_current_mission_id ON leads(current_mission_id);
295
- CREATE INDEX IF NOT EXISTS idx_leads_current_objective_id ON leads(current_objective_id);
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
296
 
297
297
  -- Índices full-text para campos searchable
298
298
  CREATE INDEX IF NOT EXISTS idx_leads_email_search ON leads
@@ -306,8 +306,8 @@ BEGIN
306
306
  CREATE INDEX IF NOT EXISTS idx_leads_account_not_deleted ON leads(id_account, deleted)
307
307
  WHERE deleted = FALSE;
308
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(current_agent_id, deleted)
310
- WHERE deleted = FALSE AND current_agent_id IS NOT NULL;
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
311
 
312
312
  RAISE NOTICE '[%] Índices da tabela leads criados com sucesso', now();
313
313
  EXCEPTION
@@ -358,7 +358,6 @@ BEGIN
358
358
  CREATE INDEX IF NOT EXISTS idx_objectives_datetime_add ON objectives(datetime_add);
359
359
  CREATE INDEX IF NOT EXISTS idx_objectives_datetime_alt ON objectives(datetime_alt);
360
360
  CREATE INDEX IF NOT EXISTS idx_objectives_datetime_del ON objectives(datetime_del);
361
- CREATE INDEX IF NOT EXISTS idx_objectives_id_agent ON objectives(id_agent);
362
361
  CREATE INDEX IF NOT EXISTS idx_objectives_id_mission ON objectives(id_mission);
363
362
  CREATE INDEX IF NOT EXISTS idx_objectives_order_number ON objectives(order_number);
364
363
 
@@ -355,15 +355,15 @@ BEGIN
355
355
  id_person INTEGER NOT NULL,
356
356
  email VARCHAR(255),
357
357
  phone VARCHAR(20),
358
- owner_user_id INTEGER,
359
- current_agent_id INTEGER,
360
- current_mission_id INTEGER,
361
- current_objective_id INTEGER,
358
+ id_user_owner INTEGER,
359
+ id_current_agent INTEGER,
360
+ id_current_mission INTEGER,
361
+ id_current_objective INTEGER,
362
362
  notes TEXT,
363
363
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
364
364
  FOREIGN KEY (id_person) REFERENCES people(id) ON DELETE CASCADE,
365
- FOREIGN KEY (owner_user_id) REFERENCES users(id) ON DELETE SET NULL,
366
- FOREIGN KEY (current_agent_id) REFERENCES agents(id) ON DELETE SET NULL,
365
+ FOREIGN KEY (id_user_owner) REFERENCES users(id) ON DELETE SET NULL,
366
+ FOREIGN KEY (id_current_agent) REFERENCES agents(id) ON DELETE SET NULL,
367
367
  CONSTRAINT leads_email_valid CHECK (email IS NULL OR email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'),
368
368
  CONSTRAINT leads_phone_valid CHECK (phone IS NULL OR phone ~* '^\+?[1-9]\d{1,14}$')
369
369
  );
@@ -378,11 +378,11 @@ BEGIN
378
378
  datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
379
379
  datetime_del TIMESTAMP WITH TIME ZONE NULL,
380
380
  id_account INTEGER NOT NULL,
381
- id_agent INTEGER,
381
+ id_agent INTEGER NOT NULL,
382
382
  title VARCHAR(255) NOT NULL,
383
383
  prompt TEXT,
384
384
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
385
- FOREIGN KEY (id_agent) REFERENCES agents(id) ON DELETE SET NULL
385
+ FOREIGN KEY (id_agent) REFERENCES agents(id) ON DELETE CASCADE
386
386
  );
387
387
  COMMENT ON TABLE missions IS 'Tabela de missões do sistema';
388
388
 
@@ -395,14 +395,12 @@ BEGIN
395
395
  datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
396
396
  datetime_del TIMESTAMP WITH TIME ZONE NULL,
397
397
  id_account INTEGER NOT NULL,
398
- id_agent INTEGER,
399
- id_mission INTEGER,
398
+ id_mission INTEGER NOT NULL,
400
399
  order_number INTEGER DEFAULT 0 NOT NULL,
401
400
  title VARCHAR(255) NOT NULL,
402
401
  prompt TEXT,
403
402
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
404
- FOREIGN KEY (id_agent) REFERENCES agents(id) ON DELETE SET NULL,
405
- FOREIGN KEY (id_mission) REFERENCES missions(id) ON DELETE SET NULL,
403
+ FOREIGN KEY (id_mission) REFERENCES missions(id) ON DELETE CASCADE,
406
404
  CONSTRAINT objectives_order_valid CHECK (order_number >= 0)
407
405
  );
408
406
  COMMENT ON TABLE objectives IS 'Tabela de objetivos do sistema';
@@ -410,11 +408,11 @@ BEGIN
410
408
  -- Atualizar referências em LEADS para MISSIONS e OBJECTIVES
411
409
  ALTER TABLE leads
412
410
  ADD CONSTRAINT fk_leads_current_mission
413
- FOREIGN KEY (current_mission_id) REFERENCES missions(id) ON DELETE SET NULL;
411
+ FOREIGN KEY (id_current_mission) REFERENCES missions(id) ON DELETE SET NULL;
414
412
 
415
413
  ALTER TABLE leads
416
414
  ADD CONSTRAINT fk_leads_current_objective
417
- FOREIGN KEY (current_objective_id) REFERENCES objectives(id) ON DELETE SET NULL;
415
+ FOREIGN KEY (id_current_objective) REFERENCES objectives(id) ON DELETE SET NULL;
418
416
 
419
417
  -- TABELA 012: CONVERSATIONS (sem FK para messages - referência cíclica)
420
418
  RAISE NOTICE '[%] Criando tabela: conversations', now();
@@ -643,7 +641,7 @@ BEGIN
643
641
  CREATE INDEX IF NOT EXISTS idx_leads_id_person ON leads(id_person);
644
642
  CREATE INDEX IF NOT EXISTS idx_leads_email ON leads(email);
645
643
  CREATE INDEX IF NOT EXISTS idx_leads_phone ON leads(phone);
646
- CREATE INDEX IF NOT EXISTS idx_leads_current_agent_id ON leads(current_agent_id);
644
+ CREATE INDEX IF NOT EXISTS idx_leads_id_current_agent ON leads(id_current_agent);
647
645
  CREATE INDEX IF NOT EXISTS idx_leads_deleted ON leads(deleted);
648
646
 
649
647
  -- ÍNDICES MISSIONS
@@ -656,7 +654,6 @@ BEGIN
656
654
  -- ÍNDICES OBJECTIVES
657
655
  RAISE NOTICE '[%] Criando índices para: objectives', now();
658
656
  CREATE INDEX IF NOT EXISTS idx_objectives_id_account ON objectives(id_account);
659
- CREATE INDEX IF NOT EXISTS idx_objectives_id_agent ON objectives(id_agent);
660
657
  CREATE INDEX IF NOT EXISTS idx_objectives_id_mission ON objectives(id_mission);
661
658
  CREATE INDEX IF NOT EXISTS idx_objectives_order ON objectives(order_number);
662
659
  CREATE INDEX IF NOT EXISTS idx_objectives_deleted ON objectives(deleted);
@@ -32,19 +32,19 @@ CREATE TABLE IF NOT EXISTS leads (
32
32
  id_person INTEGER NOT NULL,
33
33
  email VARCHAR(255), -- maxLength: 255, pattern: email
34
34
  phone VARCHAR(20), -- maxLength: 20, pattern: phone
35
- owner_user_id INTEGER, -- opcional
36
- current_agent_id INTEGER, -- opcional
37
- current_mission_id INTEGER, -- opcional
38
- current_objective_id INTEGER, -- opcional
35
+ id_user_owner INTEGER, -- opcional
36
+ id_current_agent INTEGER, -- opcional
37
+ id_current_mission INTEGER, -- opcional
38
+ id_current_objective INTEGER, -- opcional
39
39
  notes TEXT, -- searchable, pode ser longo
40
40
 
41
41
  -- Foreign keys
42
42
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
43
43
  FOREIGN KEY (id_person) REFERENCES people(id) ON DELETE CASCADE,
44
- FOREIGN KEY (owner_user_id) REFERENCES users(id) ON DELETE SET NULL,
45
- FOREIGN KEY (current_agent_id) REFERENCES agents(id) ON DELETE SET NULL,
46
- FOREIGN KEY (current_mission_id) REFERENCES missions(id) ON DELETE SET NULL,
47
- FOREIGN KEY (current_objective_id) REFERENCES objectives(id) ON DELETE SET NULL,
44
+ FOREIGN KEY (id_user_owner) REFERENCES users(id) ON DELETE SET NULL,
45
+ FOREIGN KEY (id_current_agent) REFERENCES agents(id) ON DELETE SET NULL,
46
+ FOREIGN KEY (id_current_mission) REFERENCES missions(id) ON DELETE SET NULL,
47
+ FOREIGN KEY (id_current_objective) REFERENCES objectives(id) ON DELETE SET NULL,
48
48
 
49
49
  -- Constraints
50
50
  CONSTRAINT leads_email_valid CHECK (email IS NULL OR email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'),
@@ -56,10 +56,10 @@ CREATE INDEX IF NOT EXISTS idx_leads_id_account ON leads(id_account);
56
56
  CREATE INDEX IF NOT EXISTS idx_leads_id_person ON leads(id_person);
57
57
  CREATE INDEX IF NOT EXISTS idx_leads_email ON leads(email);
58
58
  CREATE INDEX IF NOT EXISTS idx_leads_phone ON leads(phone);
59
- CREATE INDEX IF NOT EXISTS idx_leads_owner_user_id ON leads(owner_user_id);
60
- CREATE INDEX IF NOT EXISTS idx_leads_current_agent_id ON leads(current_agent_id);
61
- CREATE INDEX IF NOT EXISTS idx_leads_current_mission_id ON leads(current_mission_id);
62
- CREATE INDEX IF NOT EXISTS idx_leads_current_objective_id ON leads(current_objective_id);
59
+ CREATE INDEX IF NOT EXISTS idx_leads_id_user_owner ON leads(id_user_owner);
60
+ CREATE INDEX IF NOT EXISTS idx_leads_id_current_agent ON leads(id_current_agent);
61
+ CREATE INDEX IF NOT EXISTS idx_leads_id_current_mission ON leads(id_current_mission);
62
+ CREATE INDEX IF NOT EXISTS idx_leads_id_current_objective ON leads(id_current_objective);
63
63
 
64
64
  -- Comentários na tabela
65
65
  COMMENT ON TABLE leads IS 'Tabela de leads do sistema';
@@ -68,10 +68,10 @@ COMMENT ON COLUMN leads.id_account IS 'Referência à conta (FK)';
68
68
  COMMENT ON COLUMN leads.id_person IS 'Referência à pessoa (FK)';
69
69
  COMMENT ON COLUMN leads.email IS 'E-mail do lead';
70
70
  COMMENT ON COLUMN leads.phone IS 'Telefone do lead';
71
- COMMENT ON COLUMN leads.owner_user_id IS 'Usuário proprietário do lead (FK, opcional)';
72
- COMMENT ON COLUMN leads.current_agent_id IS 'Agente atual do lead (FK, opcional)';
73
- COMMENT ON COLUMN leads.current_mission_id IS 'Missão atual do lead (FK, opcional)';
74
- COMMENT ON COLUMN leads.current_objective_id IS 'Objetivo atual do lead (FK, opcional)';
71
+ COMMENT ON COLUMN leads.id_user_owner IS 'Usuário proprietário do lead (FK, opcional)';
72
+ COMMENT ON COLUMN leads.id_current_agent IS 'Agente atual do lead (FK, opcional)';
73
+ COMMENT ON COLUMN leads.id_current_mission IS 'Missão atual do lead (FK, opcional)';
74
+ COMMENT ON COLUMN leads.id_current_objective IS 'Objetivo atual do lead (FK, opcional)';
75
75
  COMMENT ON COLUMN leads.notes IS 'Notas sobre o lead';
76
76
 
77
77
  -- Verificação pós-execução
@@ -29,13 +29,13 @@ CREATE TABLE IF NOT EXISTS missions (
29
29
 
30
30
  -- Campos específicos da tabela missions
31
31
  id_account INTEGER NOT NULL,
32
- id_agent INTEGER, -- opcional
32
+ id_agent INTEGER NOT NULL,
33
33
  title VARCHAR(255) NOT NULL, -- required: true, maxLength: 255
34
34
  prompt TEXT, -- instruções específicas da missão
35
35
 
36
36
  -- Foreign keys
37
37
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
38
- FOREIGN KEY (id_agent) REFERENCES agents(id) ON DELETE SET NULL
38
+ FOREIGN KEY (id_agent) REFERENCES agents(id) ON DELETE CASCADE
39
39
  );
40
40
 
41
41
  -- Índices para otimização
@@ -47,7 +47,7 @@ CREATE INDEX IF NOT EXISTS idx_missions_title ON missions(title);
47
47
  COMMENT ON TABLE missions IS 'Tabela de missões do sistema';
48
48
  COMMENT ON COLUMN missions.id IS 'Identificador único da missão';
49
49
  COMMENT ON COLUMN missions.id_account IS 'Referência à conta (FK)';
50
- COMMENT ON COLUMN missions.id_agent IS 'Referência ao agente (FK, opcional)';
50
+ COMMENT ON COLUMN missions.id_agent IS 'Referência ao agente (FK)';
51
51
  COMMENT ON COLUMN missions.title IS 'Título da missão (obrigatório)';
52
52
  COMMENT ON COLUMN missions.prompt IS 'Instruções específicas da missão';
53
53
 
@@ -29,16 +29,14 @@ CREATE TABLE IF NOT EXISTS objectives (
29
29
 
30
30
  -- Campos específicos da tabela objectives
31
31
  id_account INTEGER NOT NULL,
32
- id_agent INTEGER, -- opcional
33
- id_mission INTEGER, -- opcional
32
+ id_mission INTEGER NOT NULL,
34
33
  order_number INTEGER DEFAULT 0 NOT NULL, -- required: true, default: 0
35
34
  title VARCHAR(255) NOT NULL, -- required: true, maxLength: 255
36
35
  prompt TEXT, -- instruções específicas do objetivo
37
36
 
38
37
  -- Foreign keys
39
38
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
40
- FOREIGN KEY (id_agent) REFERENCES agents(id) ON DELETE SET NULL,
41
- FOREIGN KEY (id_mission) REFERENCES missions(id) ON DELETE SET NULL,
39
+ FOREIGN KEY (id_mission) REFERENCES missions(id) ON DELETE CASCADE,
42
40
 
43
41
  -- Constraints
44
42
  CONSTRAINT objectives_order_valid CHECK (order_number >= 0)
@@ -46,7 +44,6 @@ CREATE TABLE IF NOT EXISTS objectives (
46
44
 
47
45
  -- Índices para otimização
48
46
  CREATE INDEX IF NOT EXISTS idx_objectives_id_account ON objectives(id_account);
49
- CREATE INDEX IF NOT EXISTS idx_objectives_id_agent ON objectives(id_agent);
50
47
  CREATE INDEX IF NOT EXISTS idx_objectives_id_mission ON objectives(id_mission);
51
48
  CREATE INDEX IF NOT EXISTS idx_objectives_order ON objectives(order_number);
52
49
  CREATE INDEX IF NOT EXISTS idx_objectives_title ON objectives(title);
@@ -55,7 +52,6 @@ CREATE INDEX IF NOT EXISTS idx_objectives_title ON objectives(title);
55
52
  COMMENT ON TABLE objectives IS 'Tabela de objetivos do sistema';
56
53
  COMMENT ON COLUMN objectives.id IS 'Identificador único do objetivo';
57
54
  COMMENT ON COLUMN objectives.id_account IS 'Referência à conta (FK)';
58
- COMMENT ON COLUMN objectives.id_agent IS 'Referência ao agente (FK, opcional)';
59
55
  COMMENT ON COLUMN objectives.id_mission IS 'Referência à missão (FK, opcional)';
60
56
  COMMENT ON COLUMN objectives.order_number IS 'Ordem do objetivo na sequência';
61
57
  COMMENT ON COLUMN objectives.title IS 'Título do objetivo (obrigatório)';
@@ -103,7 +103,7 @@ export const properties = {
103
103
  }
104
104
  }
105
105
  },
106
- owner_user_id: {
106
+ id_user_owner: {
107
107
  type: "number",
108
108
  filterable: true,
109
109
  index: true,
@@ -121,7 +121,7 @@ export const properties = {
121
121
  component: "number"
122
122
  }
123
123
  },
124
- current_agent_id: {
124
+ id_current_agent: {
125
125
  type: "number",
126
126
  filterable: true,
127
127
  index: true,
@@ -139,7 +139,7 @@ export const properties = {
139
139
  component: "number"
140
140
  }
141
141
  },
142
- current_mission_id: {
142
+ id_current_mission: {
143
143
  type: "number",
144
144
  filterable: true,
145
145
  index: true,
@@ -157,7 +157,7 @@ export const properties = {
157
157
  component: "number"
158
158
  }
159
159
  },
160
- current_objective_id: {
160
+ id_current_objective: {
161
161
  type: "number",
162
162
  filterable: true,
163
163
  index: true,
@@ -47,6 +47,7 @@ export const properties = {
47
47
  },
48
48
  id_agent: {
49
49
  type: "number",
50
+ required: true,
50
51
  filterable: true,
51
52
  index: true,
52
53
  reference: {
@@ -45,27 +45,10 @@ export const properties = {
45
45
  disabled: true
46
46
  }
47
47
  },
48
- id_agent: {
49
- type: "number",
50
- filterable: true,
51
- index: true,
52
- reference: {
53
- module: "agents",
54
- label: "title",
55
- value: "id",
56
- disabled: true
57
- },
58
- interface: {
59
- label: {
60
- "pt-br": "ID do agente",
61
- "en": "Agent ID"
62
- },
63
- component: "number"
64
- }
65
- },
66
48
  id_mission: {
67
49
  type: "number",
68
50
  filterable: true,
51
+ required: true,
69
52
  index: true,
70
53
  reference: {
71
54
  module: "missions",