@greatapps/greatagents 0.1.5 → 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.
- package/docs/ERD_GAGents_Database.mmd +333 -0
- package/package.json +1 -1
- package/scripts/MIGRATION_COMPLETE_DOCUMENTATION.md +672 -0
- package/scripts/README.md +128 -235
- package/scripts/constraints.sql +585 -0
- package/scripts/indexes.sql +662 -0
- package/scripts/migrate_v1.sql +1227 -0
- package/scripts/tables/001_accounts.sql +51 -0
- package/scripts/tables/002_users.sql +69 -0
- package/scripts/tables/003_people.sql +70 -0
- package/scripts/tables/004_tags.sql +62 -0
- package/scripts/tables/005_credentials.sql +79 -0
- package/scripts/tables/006_agents.sql +70 -0
- package/scripts/tables/007_tools.sql +68 -0
- package/scripts/tables/008_channels.sql +75 -0
- package/scripts/tables/009_leads.sql +85 -0
- package/scripts/tables/010_missions.sql +62 -0
- package/scripts/tables/011_objectives.sql +68 -0
- package/scripts/tables/012_conversations.sql +84 -0
- package/scripts/tables/013_objectives_tools.sql +66 -0
- package/scripts/tables/014_messages.sql +78 -0
- package/scripts/tables/015_companies.sql +77 -0
- package/scripts/tables/016_conversations_tags.sql +64 -0
- package/scripts/tables/017_leads_tags.sql +64 -0
- package/scripts/triggers.sql +497 -0
- package/src/modules/accounts/index.js +11 -0
- package/src/modules/accounts/properties.js +46 -0
- package/src/modules/channels/properties.js +1 -0
- package/src/modules/conversations/index.js +1 -1
- package/src/modules/conversations/properties.js +29 -26
- package/src/modules/credentials/properties.js +2 -2
- package/src/modules/leads/properties.js +4 -4
- package/src/modules/messages/properties.js +40 -2
- package/src/modules/missions/properties.js +1 -0
- package/src/modules/objectives/properties.js +1 -18
- package/src/modules/objectives_tools/index.js +1 -1
- package/src/modules/objectives_tools/properties.js +1 -37
- package/src/modules/tools/properties.js +1 -0
- package/src/modules/users/index.js +11 -0
- package/src/modules/users/properties.js +156 -0
- package/src/product.js +4 -0
- package/scripts/agents/create_table.sql +0 -43
- package/scripts/channels/create_table.sql +0 -48
- package/scripts/companies/create_table.sql +0 -52
- package/scripts/conversations/add_messages_reference.sql +0 -42
- package/scripts/conversations/create_table.sql +0 -55
- package/scripts/conversations_tags/create_table.sql +0 -39
- package/scripts/credentials/create_table.sql +0 -63
- package/scripts/leads/create_table.sql +0 -55
- package/scripts/leads_tags/create_table.sql +0 -39
- package/scripts/messages/create_table.sql +0 -44
- package/scripts/missions/create_table.sql +0 -39
- package/scripts/objectives/create_table.sql +0 -47
- package/scripts/objectives_tools/create_table.sql +0 -52
- package/scripts/people/create_table.sql +0 -51
- package/scripts/tags/create_table.sql +0 -38
- package/scripts/tools/create_table.sql +0 -43
|
@@ -65,7 +65,7 @@ export const properties = {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
|
-
|
|
68
|
+
provider: {
|
|
69
69
|
type: "string",
|
|
70
70
|
required: true,
|
|
71
71
|
filterable: true,
|
|
@@ -78,7 +78,7 @@ export const properties = {
|
|
|
78
78
|
{ value: "telegram", label: { "pt-br": "Telegram", "en": "Telegram" } },
|
|
79
79
|
{ value: "facebook", label: { "pt-br": "Facebook", "en": "Facebook" } },
|
|
80
80
|
{ value: "instagram", label: { "pt-br": "Instagram", "en": "Instagram" } },
|
|
81
|
-
{ value: "
|
|
81
|
+
{ value: "custom", label: { "pt-br": "Customizado", "en": "Custom" } }
|
|
82
82
|
],
|
|
83
83
|
interface: {
|
|
84
84
|
component: "select",
|
|
@@ -103,7 +103,7 @@ export const properties = {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
160
|
+
id_current_objective: {
|
|
161
161
|
type: "number",
|
|
162
162
|
filterable: true,
|
|
163
163
|
index: true,
|
|
@@ -64,6 +64,44 @@ export const properties = {
|
|
|
64
64
|
disabled: true
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
+
id_agent: {
|
|
68
|
+
type: "number",
|
|
69
|
+
filterable: true,
|
|
70
|
+
index: true,
|
|
71
|
+
required: false,
|
|
72
|
+
reference: {
|
|
73
|
+
module: "agents",
|
|
74
|
+
label: "name",
|
|
75
|
+
value: "id",
|
|
76
|
+
disabled: true
|
|
77
|
+
},
|
|
78
|
+
interface: {
|
|
79
|
+
label: {
|
|
80
|
+
"pt-br": "Agente",
|
|
81
|
+
"en": "Agent"
|
|
82
|
+
},
|
|
83
|
+
component: "select"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
id_user: {
|
|
87
|
+
type: "number",
|
|
88
|
+
filterable: true,
|
|
89
|
+
index: true,
|
|
90
|
+
required: false,
|
|
91
|
+
reference: {
|
|
92
|
+
module: "users",
|
|
93
|
+
label: "full_name",
|
|
94
|
+
value: "id",
|
|
95
|
+
disabled: true
|
|
96
|
+
},
|
|
97
|
+
interface: {
|
|
98
|
+
label: {
|
|
99
|
+
"pt-br": "Usuário",
|
|
100
|
+
"en": "User"
|
|
101
|
+
},
|
|
102
|
+
component: "select"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
67
105
|
direction: {
|
|
68
106
|
type: "string",
|
|
69
107
|
default: "in",
|
|
@@ -85,9 +123,9 @@ export const properties = {
|
|
|
85
123
|
default: "user",
|
|
86
124
|
options: [
|
|
87
125
|
{ value: "user", label: { "pt-br": "Usuário", "en": "User" } },
|
|
88
|
-
{ value: "agent", label: { "pt-br": "Agente", "en": "Agent" } },
|
|
126
|
+
{ value: "ai-agent", label: { "pt-br": "Agente I.A.", "en": "A.I. Agent" } },
|
|
127
|
+
{ value: "human-agent", label: { "pt-br": "Agente Humano", "en": "Human Agent" } },
|
|
89
128
|
{ value: "system", label: { "pt-br": "Sistema", "en": "System" } },
|
|
90
|
-
{ value: "assistant", label: { "pt-br": "Assistente", "en": "Assistant" } },
|
|
91
129
|
{ value: "note", label: { "pt-br": "Nota", "en": "Note" } }
|
|
92
130
|
],
|
|
93
131
|
filterable: true,
|
|
@@ -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",
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
product: "greatagents",
|
|
5
5
|
name: "objectives_tools",
|
|
6
6
|
cache: { ttlView: 30, ttlList: 0 },
|
|
7
|
-
params: ["id_account", "
|
|
7
|
+
params: ["id_account", "id_objective", "id_tool"],
|
|
8
8
|
properties: properties,
|
|
9
9
|
routes: {}
|
|
10
10
|
};
|
|
@@ -44,43 +44,7 @@ export const properties = {
|
|
|
44
44
|
component: "select",
|
|
45
45
|
disabled: true
|
|
46
46
|
}
|
|
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
|
-
id_mission: {
|
|
67
|
-
type: "number",
|
|
68
|
-
filterable: true,
|
|
69
|
-
index: true,
|
|
70
|
-
reference: {
|
|
71
|
-
module: "missions",
|
|
72
|
-
label: "title",
|
|
73
|
-
value: "id",
|
|
74
|
-
disabled: true
|
|
75
|
-
},
|
|
76
|
-
interface: {
|
|
77
|
-
label: {
|
|
78
|
-
"pt-br": "ID da missão",
|
|
79
|
-
"en": "Mission ID"
|
|
80
|
-
},
|
|
81
|
-
component: "number"
|
|
82
|
-
}
|
|
83
|
-
},
|
|
47
|
+
},
|
|
84
48
|
id_objective: {
|
|
85
49
|
type: "number",
|
|
86
50
|
filterable: true,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { properties } from "./properties.js";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
product: "greatagents",
|
|
5
|
+
name: "users",
|
|
6
|
+
cache: { ttlView: 3600, ttlList: 0 },
|
|
7
|
+
summary: "Armazena informações de usuários do sistema",
|
|
8
|
+
params: [ "id_account" ],
|
|
9
|
+
properties: properties,
|
|
10
|
+
routes: {}
|
|
11
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export const properties = {
|
|
2
|
+
id: {
|
|
3
|
+
type: "number",
|
|
4
|
+
filterable: true,
|
|
5
|
+
unique: true,
|
|
6
|
+
autoIncrement: true,
|
|
7
|
+
index: true
|
|
8
|
+
},
|
|
9
|
+
id_account: {
|
|
10
|
+
type: "number",
|
|
11
|
+
required: true,
|
|
12
|
+
updatable: false,
|
|
13
|
+
filterable: true,
|
|
14
|
+
reference: {
|
|
15
|
+
module: "accounts",
|
|
16
|
+
label: "name",
|
|
17
|
+
value: "id",
|
|
18
|
+
disabled: true
|
|
19
|
+
},
|
|
20
|
+
interface: {
|
|
21
|
+
label: {
|
|
22
|
+
"pt-br": "Conta",
|
|
23
|
+
en: "Account"
|
|
24
|
+
},
|
|
25
|
+
component: "select",
|
|
26
|
+
disabled: true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
name: {
|
|
30
|
+
type: "string",
|
|
31
|
+
searchable: true,
|
|
32
|
+
maxLength: 50,
|
|
33
|
+
interface: {
|
|
34
|
+
label: {
|
|
35
|
+
"pt-br": "Nome",
|
|
36
|
+
"en": "Name"
|
|
37
|
+
},
|
|
38
|
+
component: "input"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
last_name: {
|
|
42
|
+
type: "string",
|
|
43
|
+
searchable: true,
|
|
44
|
+
interface: {
|
|
45
|
+
label: {
|
|
46
|
+
"pt-br": "Sobrenome",
|
|
47
|
+
en: "Lastname"
|
|
48
|
+
},
|
|
49
|
+
component: "input"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
email: {
|
|
53
|
+
type: "string",
|
|
54
|
+
required: true,
|
|
55
|
+
searchable: true,
|
|
56
|
+
filterable: true,
|
|
57
|
+
interface: {
|
|
58
|
+
label: {
|
|
59
|
+
"pt-br": "E-mail",
|
|
60
|
+
en: "E-mail"
|
|
61
|
+
},
|
|
62
|
+
component: "input",
|
|
63
|
+
format: "email"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
profile: {
|
|
67
|
+
type: "string",
|
|
68
|
+
default: "collaborator",
|
|
69
|
+
options: [
|
|
70
|
+
{
|
|
71
|
+
value: "viewer",
|
|
72
|
+
icon: "",
|
|
73
|
+
title: {
|
|
74
|
+
"pt-br": "Visualizador",
|
|
75
|
+
en: "Viewer"
|
|
76
|
+
},
|
|
77
|
+
description: "",
|
|
78
|
+
style: ""
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: "collaborator",
|
|
82
|
+
icon: "",
|
|
83
|
+
title: {
|
|
84
|
+
"pt-br": "Colaborador",
|
|
85
|
+
en: "Collaborator"
|
|
86
|
+
},
|
|
87
|
+
description: "",
|
|
88
|
+
style: ""
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
value: "admin",
|
|
92
|
+
icon: "",
|
|
93
|
+
title: {
|
|
94
|
+
"pt-br": "Administrador",
|
|
95
|
+
en: "Admin"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
value: "owner",
|
|
100
|
+
icon: "",
|
|
101
|
+
title: {
|
|
102
|
+
"pt-br": "Proprietário",
|
|
103
|
+
en: "Owner"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
value: "attendant",
|
|
108
|
+
icon: "",
|
|
109
|
+
title: {
|
|
110
|
+
"pt-br": "Atendente",
|
|
111
|
+
en: "Attendant"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
interface: {
|
|
116
|
+
label: {
|
|
117
|
+
"pt-br": "Perfil de acesso",
|
|
118
|
+
en: "Profile"
|
|
119
|
+
},
|
|
120
|
+
component: "select"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
photo: {
|
|
124
|
+
type: "image",
|
|
125
|
+
interface: {
|
|
126
|
+
label: {
|
|
127
|
+
"pt-br": "Foto",
|
|
128
|
+
en: "Photo"
|
|
129
|
+
},
|
|
130
|
+
component: "image"
|
|
131
|
+
},
|
|
132
|
+
file: {
|
|
133
|
+
types: ["png", "jpg", "jpeg", "gif", "svg", "webp"],
|
|
134
|
+
storage: "gapps-r1-storage",
|
|
135
|
+
width: 160,
|
|
136
|
+
height: 160
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
deleted: {
|
|
140
|
+
type: "boolean",
|
|
141
|
+
default: false
|
|
142
|
+
},
|
|
143
|
+
datetime_alt: {
|
|
144
|
+
type: "date",
|
|
145
|
+
filterable: true,
|
|
146
|
+
updatable: false
|
|
147
|
+
},
|
|
148
|
+
datetime_del: {
|
|
149
|
+
type: "date",
|
|
150
|
+
filterable: true
|
|
151
|
+
},
|
|
152
|
+
datetime_add: {
|
|
153
|
+
type: "date",
|
|
154
|
+
filterable: true
|
|
155
|
+
}
|
|
156
|
+
};
|
package/src/product.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* Modules */
|
|
2
2
|
|
|
3
|
+
import accounts from './modules/accounts/index.js';
|
|
4
|
+
import users from './modules/users/index.js';
|
|
3
5
|
import agents from './modules/agents/index.js';
|
|
4
6
|
import channels from './modules/channels/index.js';
|
|
5
7
|
import companies from './modules/companies/index.js';
|
|
@@ -38,6 +40,8 @@ export default {
|
|
|
38
40
|
},
|
|
39
41
|
},
|
|
40
42
|
modules: {
|
|
43
|
+
accounts,
|
|
44
|
+
users,
|
|
41
45
|
agents,
|
|
42
46
|
channels,
|
|
43
47
|
companies,
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
-- =====================================================
|
|
2
|
-
-- Script de criação da tabela AGENTS
|
|
3
|
-
-- =====================================================
|
|
4
|
-
-- Descrição: Tabela que armazena informações dos agentes de IA
|
|
5
|
-
-- Dependências: accounts
|
|
6
|
-
-- =====================================================
|
|
7
|
-
|
|
8
|
-
-- Cria a tabela agents
|
|
9
|
-
CREATE TABLE IF NOT EXISTS agents (
|
|
10
|
-
-- Propriedades automáticas (padrão para todas as tabelas)
|
|
11
|
-
id SERIAL PRIMARY KEY,
|
|
12
|
-
deleted BOOLEAN DEFAULT false NOT NULL,
|
|
13
|
-
datetime_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
14
|
-
datetime_alt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
15
|
-
datetime_del TIMESTAMP NULL,
|
|
16
|
-
|
|
17
|
-
-- Propriedades específicas da tabela agents
|
|
18
|
-
id_account INTEGER NOT NULL,
|
|
19
|
-
title VARCHAR(255) NOT NULL,
|
|
20
|
-
photo VARCHAR(255),
|
|
21
|
-
prompt TEXT,
|
|
22
|
-
delayTyping INTEGER DEFAULT 0 NOT NULL,
|
|
23
|
-
waitingTime INTEGER DEFAULT 0 NOT NULL
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
-- Cria índices para otimização de consultas
|
|
27
|
-
CREATE INDEX IF NOT EXISTS idx_agents_deleted ON agents(deleted);
|
|
28
|
-
CREATE INDEX IF NOT EXISTS idx_agents_id_account ON agents(id_account);
|
|
29
|
-
CREATE INDEX IF NOT EXISTS idx_agents_title ON agents(title);
|
|
30
|
-
|
|
31
|
-
-- Adiciona comentários para documentação
|
|
32
|
-
COMMENT ON TABLE agents IS 'Tabela que armazena informações dos agentes de IA do sistema';
|
|
33
|
-
COMMENT ON COLUMN agents.id IS 'Identificador único do agente (chave primária)';
|
|
34
|
-
COMMENT ON COLUMN agents.deleted IS 'Flag indicando se o registro foi excluído logicamente';
|
|
35
|
-
COMMENT ON COLUMN agents.datetime_add IS 'Data e hora de criação do registro';
|
|
36
|
-
COMMENT ON COLUMN agents.datetime_alt IS 'Data e hora da última alteração do registro';
|
|
37
|
-
COMMENT ON COLUMN agents.datetime_del IS 'Data e hora da exclusão lógica do registro';
|
|
38
|
-
COMMENT ON COLUMN agents.id_account IS 'Referência para a conta proprietária do agente';
|
|
39
|
-
COMMENT ON COLUMN agents.title IS 'Nome/título do agente';
|
|
40
|
-
COMMENT ON COLUMN agents.photo IS 'URL ou caminho para a foto/avatar do agente';
|
|
41
|
-
COMMENT ON COLUMN agents.prompt IS 'Prompt base/personalidade do agente para interações';
|
|
42
|
-
COMMENT ON COLUMN agents.delayTyping IS 'Delay em milissegundos para simular digitação humana';
|
|
43
|
-
COMMENT ON COLUMN agents.waitingTime IS 'Tempo de espera em milissegundos antes de responder';
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
-- =====================================================
|
|
2
|
-
-- Script de criação da tabela CHANNELS
|
|
3
|
-
-- =====================================================
|
|
4
|
-
-- Descrição: Tabela que armazena informações dos canais de comunicação
|
|
5
|
-
-- Dependências: accounts, credentials
|
|
6
|
-
-- =====================================================
|
|
7
|
-
|
|
8
|
-
-- Cria a tabela channels
|
|
9
|
-
CREATE TABLE IF NOT EXISTS channels (
|
|
10
|
-
-- Propriedades automáticas (padrão para todas as tabelas)
|
|
11
|
-
id SERIAL PRIMARY KEY,
|
|
12
|
-
deleted BOOLEAN DEFAULT false NOT NULL,
|
|
13
|
-
datetime_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
14
|
-
datetime_alt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
15
|
-
datetime_del TIMESTAMP NULL,
|
|
16
|
-
|
|
17
|
-
-- Propriedades específicas da tabela channels
|
|
18
|
-
id_account INTEGER NOT NULL,
|
|
19
|
-
title VARCHAR(255) NOT NULL,
|
|
20
|
-
provider VARCHAR(50) NOT NULL DEFAULT 'web-chat',
|
|
21
|
-
url VARCHAR(255),
|
|
22
|
-
active BOOLEAN DEFAULT true NOT NULL,
|
|
23
|
-
id_credential INTEGER REFERENCES credentials(id) ON DELETE SET NULL,
|
|
24
|
-
handle VARCHAR(255)
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
-- Cria índices para otimização de consultas
|
|
28
|
-
CREATE INDEX IF NOT EXISTS idx_channels_deleted ON channels(deleted);
|
|
29
|
-
CREATE INDEX IF NOT EXISTS idx_channels_id_account ON channels(id_account);
|
|
30
|
-
CREATE INDEX IF NOT EXISTS idx_channels_provider ON channels(provider);
|
|
31
|
-
CREATE INDEX IF NOT EXISTS idx_channels_active ON channels(active);
|
|
32
|
-
CREATE INDEX IF NOT EXISTS idx_channels_id_credential ON channels(id_credential);
|
|
33
|
-
CREATE INDEX IF NOT EXISTS idx_channels_handle ON channels(handle);
|
|
34
|
-
|
|
35
|
-
-- Adiciona comentários para documentação
|
|
36
|
-
COMMENT ON TABLE channels IS 'Tabela que armazena informações dos canais de comunicação (WhatsApp, Telegram, etc.)';
|
|
37
|
-
COMMENT ON COLUMN channels.id IS 'Identificador único do canal (chave primária)';
|
|
38
|
-
COMMENT ON COLUMN channels.deleted IS 'Flag indicando se o registro foi excluído logicamente';
|
|
39
|
-
COMMENT ON COLUMN channels.datetime_add IS 'Data e hora de criação do registro';
|
|
40
|
-
COMMENT ON COLUMN channels.datetime_alt IS 'Data e hora da última alteração do registro';
|
|
41
|
-
COMMENT ON COLUMN channels.datetime_del IS 'Data e hora da exclusão lógica do registro';
|
|
42
|
-
COMMENT ON COLUMN channels.id_account IS 'Referência para a conta proprietária do canal';
|
|
43
|
-
COMMENT ON COLUMN channels.title IS 'Nome/título do canal';
|
|
44
|
-
COMMENT ON COLUMN channels.provider IS 'Tipo de provedor do canal (0=WhatsApp, 1=Telegram, 2=Discord, etc.)';
|
|
45
|
-
COMMENT ON COLUMN channels.url IS 'URL de conexão ou webhook do canal';
|
|
46
|
-
COMMENT ON COLUMN channels.active IS 'Flag indicando se o canal está ativo';
|
|
47
|
-
COMMENT ON COLUMN channels.id_credential IS 'Referência para as credenciais de autenticação do canal';
|
|
48
|
-
COMMENT ON COLUMN channels.handle IS 'Identificador único do canal no provedor (ex: número do WhatsApp, bot token, etc.)';
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
-- =====================================================
|
|
2
|
-
-- Script de criação da tabela COMPANIES
|
|
3
|
-
-- =====================================================
|
|
4
|
-
-- Descrição: Tabela que armazena informações das empresas associadas aos leads
|
|
5
|
-
-- Dependências: accounts, leads
|
|
6
|
-
-- =====================================================
|
|
7
|
-
|
|
8
|
-
-- Cria a tabela companies
|
|
9
|
-
CREATE TABLE IF NOT EXISTS companies (
|
|
10
|
-
-- Propriedades automáticas (padrão para todas as tabelas)
|
|
11
|
-
id SERIAL PRIMARY KEY,
|
|
12
|
-
deleted BOOLEAN DEFAULT false NOT NULL,
|
|
13
|
-
datetime_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
14
|
-
datetime_alt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
15
|
-
datetime_del TIMESTAMP NULL,
|
|
16
|
-
|
|
17
|
-
-- Propriedades específicas da tabela companies
|
|
18
|
-
id_account INTEGER NOT NULL,
|
|
19
|
-
id_lead INTEGER REFERENCES leads(id) ON DELETE CASCADE,
|
|
20
|
-
name VARCHAR(255),
|
|
21
|
-
website VARCHAR(255),
|
|
22
|
-
document VARCHAR(50),
|
|
23
|
-
notes TEXT,
|
|
24
|
-
industry VARCHAR(255),
|
|
25
|
-
size VARCHAR(255)
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
-- Cria índices para otimização de consultas
|
|
29
|
-
CREATE INDEX IF NOT EXISTS idx_companies_deleted ON companies(deleted);
|
|
30
|
-
CREATE INDEX IF NOT EXISTS idx_companies_id_account ON companies(id_account);
|
|
31
|
-
CREATE INDEX IF NOT EXISTS idx_companies_id_lead ON companies(id_lead);
|
|
32
|
-
CREATE INDEX IF NOT EXISTS idx_companies_name ON companies(name);
|
|
33
|
-
CREATE INDEX IF NOT EXISTS idx_companies_website ON companies(website);
|
|
34
|
-
CREATE INDEX IF NOT EXISTS idx_companies_document ON companies(document);
|
|
35
|
-
CREATE INDEX IF NOT EXISTS idx_companies_industry ON companies(industry);
|
|
36
|
-
CREATE INDEX IF NOT EXISTS idx_companies_size ON companies(size);
|
|
37
|
-
|
|
38
|
-
-- Adiciona comentários para documentação
|
|
39
|
-
COMMENT ON TABLE companies IS 'Tabela que armazena informações das empresas associadas aos leads';
|
|
40
|
-
COMMENT ON COLUMN companies.id IS 'Identificador único da empresa (chave primária)';
|
|
41
|
-
COMMENT ON COLUMN companies.deleted IS 'Flag indicando se o registro foi excluído logicamente';
|
|
42
|
-
COMMENT ON COLUMN companies.datetime_add IS 'Data e hora de criação do registro';
|
|
43
|
-
COMMENT ON COLUMN companies.datetime_alt IS 'Data e hora da última alteração do registro';
|
|
44
|
-
COMMENT ON COLUMN companies.datetime_del IS 'Data e hora da exclusão lógica do registro';
|
|
45
|
-
COMMENT ON COLUMN companies.id_account IS 'Referência para a conta proprietária da empresa';
|
|
46
|
-
COMMENT ON COLUMN companies.id_lead IS 'Referência para o lead associado à empresa';
|
|
47
|
-
COMMENT ON COLUMN companies.name IS 'Nome da empresa';
|
|
48
|
-
COMMENT ON COLUMN companies.website IS 'Website da empresa';
|
|
49
|
-
COMMENT ON COLUMN companies.document IS 'Documento da empresa (CNPJ, etc.)';
|
|
50
|
-
COMMENT ON COLUMN companies.notes IS 'Notas e observações sobre a empresa';
|
|
51
|
-
COMMENT ON COLUMN companies.industry IS 'Setor/indústria da empresa';
|
|
52
|
-
COMMENT ON COLUMN companies.size IS 'Tamanho da empresa (pequena, média, grande, etc.)';
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
-- Script para conectar tabela conversations com tabela messages
|
|
2
|
-
-- Adiciona campo id_last_message e cria foreign key constraint
|
|
3
|
-
--
|
|
4
|
-
-- Autor: Sistema GAgents
|
|
5
|
-
-- Data: 2025-01-14
|
|
6
|
-
-- Descrição: Conecta conversations com messages através do campo id_last_message
|
|
7
|
-
|
|
8
|
-
-- =====================================================
|
|
9
|
-
-- 1. Adicionar campo id_last_message na tabela conversations
|
|
10
|
-
-- =====================================================
|
|
11
|
-
-- Campo nullable para permitir conversas sem mensagens ainda
|
|
12
|
-
ALTER TABLE conversations
|
|
13
|
-
ADD COLUMN IF NOT EXISTS id_last_message INTEGER;
|
|
14
|
-
|
|
15
|
-
-- =====================================================
|
|
16
|
-
-- 2. Criar foreign key constraint
|
|
17
|
-
-- =====================================================
|
|
18
|
-
-- Conecta conversations.id_last_message → messages.id
|
|
19
|
-
-- ON DELETE SET NULL: se a mensagem for deletada, apenas remove a referência
|
|
20
|
-
ALTER TABLE conversations
|
|
21
|
-
ADD CONSTRAINT IF NOT EXISTS fk_conversations_last_message
|
|
22
|
-
FOREIGN KEY (id_last_message) REFERENCES messages(id) ON DELETE SET NULL;
|
|
23
|
-
|
|
24
|
-
-- =====================================================
|
|
25
|
-
-- 3. Criar índice para otimização de consultas
|
|
26
|
-
-- =====================================================
|
|
27
|
-
-- Melhora performance em consultas que filtram por id_last_message
|
|
28
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_last_message
|
|
29
|
-
ON conversations(id_last_message);
|
|
30
|
-
|
|
31
|
-
-- =====================================================
|
|
32
|
-
-- Comentários sobre o uso:
|
|
33
|
-
-- =====================================================
|
|
34
|
-
-- Este campo permite:
|
|
35
|
-
-- - Identificar rapidamente a última mensagem de uma conversa
|
|
36
|
-
-- - Otimizar consultas de listagem de conversas com preview da última mensagem
|
|
37
|
-
-- - Manter integridade referencial com comportamento seguro (SET NULL)
|
|
38
|
-
--
|
|
39
|
-
-- Exemplo de uso:
|
|
40
|
-
-- SELECT c.*, m.content as last_message_content
|
|
41
|
-
-- FROM conversations c
|
|
42
|
-
-- LEFT JOIN messages m ON c.id_last_message = m.id;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
-- =====================================================
|
|
2
|
-
-- Script de criação da tabela CONVERSATIONS
|
|
3
|
-
-- =====================================================
|
|
4
|
-
-- Descrição: Tabela que armazena informações das conversas entre usuários e agentes
|
|
5
|
-
-- Dependências: accounts, agents, channels
|
|
6
|
-
-- =====================================================
|
|
7
|
-
|
|
8
|
-
-- Cria a tabela conversations
|
|
9
|
-
CREATE TABLE IF NOT EXISTS conversations (
|
|
10
|
-
-- Propriedades automáticas (padrão para todas as tabelas)
|
|
11
|
-
id SERIAL PRIMARY KEY,
|
|
12
|
-
deleted BOOLEAN DEFAULT false NOT NULL,
|
|
13
|
-
datetime_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
14
|
-
datetime_alt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
15
|
-
datetime_del TIMESTAMP NULL,
|
|
16
|
-
|
|
17
|
-
-- Propriedades específicas da tabela conversations
|
|
18
|
-
id_account INTEGER NOT NULL,
|
|
19
|
-
id_agent INTEGER REFERENCES agents(id) ON DELETE SET NULL,
|
|
20
|
-
id_channel INTEGER REFERENCES channels(id) ON DELETE SET NULL,
|
|
21
|
-
id_lead INTEGER REFERENCES leads(id) ON DELETE SET NULL,
|
|
22
|
-
id_assignee INTEGER,
|
|
23
|
-
last_message_at TIMESTAMP,
|
|
24
|
-
id_last_message INTEGER REFERENCES messages(id) ON DELETE SET NULL,
|
|
25
|
-
stop_ai BOOLEAN DEFAULT false NOT NULL,
|
|
26
|
-
status VARCHAR(20) DEFAULT 'open' NOT NULL
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
-- Cria índices para otimização de consultas
|
|
30
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_deleted ON conversations(deleted);
|
|
31
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_account ON conversations(id_account);
|
|
32
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_agent ON conversations(id_agent);
|
|
33
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_channel ON conversations(id_channel);
|
|
34
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_lead ON conversations(id_lead);
|
|
35
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_id_assignee ON conversations(id_assignee);
|
|
36
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_status ON conversations(status);
|
|
37
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_last_message_at ON conversations(last_message_at);
|
|
38
|
-
CREATE INDEX IF NOT EXISTS idx_conversations_stop_ai ON conversations(stop_ai);
|
|
39
|
-
|
|
40
|
-
-- Adiciona comentários para documentação
|
|
41
|
-
COMMENT ON TABLE conversations IS 'Tabela que armazena informações das conversas entre usuários e agentes';
|
|
42
|
-
COMMENT ON COLUMN conversations.id IS 'Identificador único da conversa (chave primária)';
|
|
43
|
-
COMMENT ON COLUMN conversations.deleted IS 'Flag indicando se o registro foi excluído logicamente';
|
|
44
|
-
COMMENT ON COLUMN conversations.datetime_add IS 'Data e hora de criação do registro';
|
|
45
|
-
COMMENT ON COLUMN conversations.datetime_alt IS 'Data e hora da última alteração do registro';
|
|
46
|
-
COMMENT ON COLUMN conversations.datetime_del IS 'Data e hora da exclusão lógica do registro';
|
|
47
|
-
COMMENT ON COLUMN conversations.id_account IS 'Referência para a conta proprietária da conversa';
|
|
48
|
-
COMMENT ON COLUMN conversations.id_agent IS 'Referência para o agente responsável pela conversa';
|
|
49
|
-
COMMENT ON COLUMN conversations.id_channel IS 'Referência para o canal onde a conversa está acontecendo';
|
|
50
|
-
COMMENT ON COLUMN conversations.id_lead IS 'Identificador do lead na conversa';
|
|
51
|
-
COMMENT ON COLUMN conversations.id_assignee IS 'Identificador do usuário humano responsável pela conversa';
|
|
52
|
-
COMMENT ON COLUMN conversations.last_message_at IS 'Data e hora da última mensagem na conversa';
|
|
53
|
-
COMMENT ON COLUMN conversations.id_last_message IS 'Identificador da última mensagem na conversa';
|
|
54
|
-
COMMENT ON COLUMN conversations.stop_ai IS 'Flag indicando se o agente de IA deve parar de responder automaticamente';
|
|
55
|
-
COMMENT ON COLUMN conversations.status IS 'Status da conversa (open, closed, pending, etc.)';
|