@greatapps/greatagents 0.1.5 → 0.1.6

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.
Files changed (53) hide show
  1. package/MIGRATION_COMPLETE_DOCUMENTATION.md +672 -0
  2. package/package.json +1 -1
  3. package/scripts/README.md +128 -235
  4. package/scripts/constraints.sql +585 -0
  5. package/scripts/indexes.sql +663 -0
  6. package/scripts/migrate_v1.sql +1230 -0
  7. package/scripts/tables/001_accounts.sql +51 -0
  8. package/scripts/tables/002_users.sql +69 -0
  9. package/scripts/tables/003_people.sql +70 -0
  10. package/scripts/tables/004_tags.sql +62 -0
  11. package/scripts/tables/005_credentials.sql +79 -0
  12. package/scripts/tables/006_agents.sql +70 -0
  13. package/scripts/tables/007_tools.sql +68 -0
  14. package/scripts/tables/008_channels.sql +75 -0
  15. package/scripts/tables/009_leads.sql +85 -0
  16. package/scripts/tables/010_missions.sql +62 -0
  17. package/scripts/tables/011_objectives.sql +72 -0
  18. package/scripts/tables/012_conversations.sql +84 -0
  19. package/scripts/tables/013_objectives_tools.sql +66 -0
  20. package/scripts/tables/014_messages.sql +78 -0
  21. package/scripts/tables/015_companies.sql +77 -0
  22. package/scripts/tables/016_conversations_tags.sql +64 -0
  23. package/scripts/tables/017_leads_tags.sql +64 -0
  24. package/scripts/triggers.sql +497 -0
  25. package/src/modules/accounts/index.js +11 -0
  26. package/src/modules/accounts/properties.js +46 -0
  27. package/src/modules/channels/properties.js +1 -0
  28. package/src/modules/conversations/index.js +1 -1
  29. package/src/modules/conversations/properties.js +29 -26
  30. package/src/modules/credentials/properties.js +2 -2
  31. package/src/modules/messages/properties.js +40 -2
  32. package/src/modules/objectives_tools/index.js +1 -1
  33. package/src/modules/objectives_tools/properties.js +1 -37
  34. package/src/modules/tools/properties.js +1 -0
  35. package/src/modules/users/index.js +11 -0
  36. package/src/modules/users/properties.js +156 -0
  37. package/src/product.js +4 -0
  38. package/scripts/agents/create_table.sql +0 -43
  39. package/scripts/channels/create_table.sql +0 -48
  40. package/scripts/companies/create_table.sql +0 -52
  41. package/scripts/conversations/add_messages_reference.sql +0 -42
  42. package/scripts/conversations/create_table.sql +0 -55
  43. package/scripts/conversations_tags/create_table.sql +0 -39
  44. package/scripts/credentials/create_table.sql +0 -63
  45. package/scripts/leads/create_table.sql +0 -55
  46. package/scripts/leads_tags/create_table.sql +0 -39
  47. package/scripts/messages/create_table.sql +0 -44
  48. package/scripts/missions/create_table.sql +0 -39
  49. package/scripts/objectives/create_table.sql +0 -47
  50. package/scripts/objectives_tools/create_table.sql +0 -52
  51. package/scripts/people/create_table.sql +0 -51
  52. package/scripts/tags/create_table.sql +0 -38
  53. package/scripts/tools/create_table.sql +0 -43
@@ -65,7 +65,7 @@ export const properties = {
65
65
  }
66
66
  }
67
67
  },
68
- integration: {
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: "tool", label: { "pt-br": "Tool", "en": "Tool" } },
81
+ { value: "custom", label: { "pt-br": "Customizado", "en": "Custom" } }
82
82
  ],
83
83
  interface: {
84
84
  component: "select",
@@ -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,
@@ -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", "id_agent", "id_mission", "id_objective", "id_tool"],
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,
@@ -109,6 +109,7 @@ export const properties = {
109
109
  type: "number",
110
110
  filterable: true,
111
111
  index: true,
112
+ required: false,
112
113
  interface: {
113
114
  label: {
114
115
  "pt-br": "ID da credencial",
@@ -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.)';
@@ -1,39 +0,0 @@
1
- -- =====================================================
2
- -- Script de criação da tabela CONVERSATIONS_TAGS
3
- -- =====================================================
4
- -- Descrição: Tabela de relacionamento entre conversas e tags (many-to-many)
5
- -- Dependências: accounts, conversations, tags
6
- -- =====================================================
7
-
8
- -- Cria a tabela conversations_tags
9
- CREATE TABLE IF NOT EXISTS conversations_tags (
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_tags
18
- id_account INTEGER NOT NULL,
19
- id_conversation INTEGER REFERENCES conversations(id) ON DELETE CASCADE,
20
- id_tag INTEGER REFERENCES tags(id) ON DELETE CASCADE
21
- );
22
-
23
- -- Cria índices para otimização de consultas
24
- CREATE INDEX IF NOT EXISTS idx_conversations_tags_deleted ON conversations_tags(deleted);
25
- CREATE INDEX IF NOT EXISTS idx_conversations_tags_id_account ON conversations_tags(id_account);
26
- CREATE INDEX IF NOT EXISTS idx_conversations_tags_id_conversation ON conversations_tags(id_conversation);
27
- CREATE INDEX IF NOT EXISTS idx_conversations_tags_id_tag ON conversations_tags(id_tag);
28
- CREATE INDEX IF NOT EXISTS idx_conversations_tags_conversation_tag ON conversations_tags(id_conversation, id_tag);
29
-
30
- -- Adiciona comentários para documentação
31
- COMMENT ON TABLE conversations_tags IS 'Tabela de relacionamento entre conversas e tags para categorização';
32
- COMMENT ON COLUMN conversations_tags.id IS 'Identificador único do relacionamento conversa-tag (chave primária)';
33
- COMMENT ON COLUMN conversations_tags.deleted IS 'Flag indicando se o registro foi excluído logicamente';
34
- COMMENT ON COLUMN conversations_tags.datetime_add IS 'Data e hora de criação do registro';
35
- COMMENT ON COLUMN conversations_tags.datetime_alt IS 'Data e hora da última alteração do registro';
36
- COMMENT ON COLUMN conversations_tags.datetime_del IS 'Data e hora da exclusão lógica do registro';
37
- COMMENT ON COLUMN conversations_tags.id_account IS 'Referência para a conta proprietária do relacionamento';
38
- COMMENT ON COLUMN conversations_tags.id_conversation IS 'Referência para a conversa associada à tag';
39
- COMMENT ON COLUMN conversations_tags.id_tag IS 'Referência para a tag associada à conversa';
@@ -1,63 +0,0 @@
1
- -- =====================================================
2
- -- Script de criação da tabela CREDENTIALS
3
- -- =====================================================
4
- -- Descrição: Tabela que armazena credenciais de autenticação para integrações
5
- -- Dependências: accounts
6
- -- =====================================================
7
-
8
- -- Cria a tabela credentials
9
- CREATE TABLE IF NOT EXISTS credentials (
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 credentials
18
- id_account INTEGER NOT NULL,
19
- title VARCHAR(255) NOT NULL,
20
- integration VARCHAR(50) DEFAULT 'web-chat' NOT NULL,
21
- authType VARCHAR(20) DEFAULT 'none' NOT NULL,
22
- userName VARCHAR(255),
23
- password VARCHAR(255),
24
- apiKey VARCHAR(255),
25
- token VARCHAR(255),
26
- paramName VARCHAR(255),
27
- refreshToken VARCHAR(255),
28
- clientSecret VARCHAR(255),
29
- clientId VARCHAR(255),
30
- sendIn VARCHAR(255) DEFAULT 'none' NOT NULL,
31
- scheme VARCHAR(255) DEFAULT 'none' NOT NULL,
32
- prefix VARCHAR(255)
33
- );
34
-
35
- -- Cria índices para otimização de consultas
36
- CREATE INDEX IF NOT EXISTS idx_credentials_deleted ON credentials(deleted);
37
- CREATE INDEX IF NOT EXISTS idx_credentials_id_account ON credentials(id_account);
38
- CREATE INDEX IF NOT EXISTS idx_credentials_integration ON credentials(integration);
39
- CREATE INDEX IF NOT EXISTS idx_credentials_authType ON credentials(authType);
40
- CREATE INDEX IF NOT EXISTS idx_credentials_title ON credentials(title);
41
-
42
- -- Adiciona comentários para documentação
43
- COMMENT ON TABLE credentials IS 'Tabela que armazena credenciais de autenticação para integrações com serviços externos';
44
- COMMENT ON COLUMN credentials.id IS 'Identificador único da credencial (chave primária)';
45
- COMMENT ON COLUMN credentials.deleted IS 'Flag indicando se o registro foi excluído logicamente';
46
- COMMENT ON COLUMN credentials.datetime_add IS 'Data e hora de criação do registro';
47
- COMMENT ON COLUMN credentials.datetime_alt IS 'Data e hora da última alteração do registro';
48
- COMMENT ON COLUMN credentials.datetime_del IS 'Data e hora da exclusão lógica do registro';
49
- COMMENT ON COLUMN credentials.id_account IS 'Referência para a conta proprietária da credencial';
50
- COMMENT ON COLUMN credentials.title IS 'Título/nome identificador da credencial';
51
- COMMENT ON COLUMN credentials.integration IS 'Tipo da integração (web-chat, whatsapp, z-api, evolution-api, telegram, facebook, instagram)';
52
- COMMENT ON COLUMN credentials.authType IS 'Tipo de autenticação (0=Nenhum, 1=Básico, 2=OAuth2, 3=API Key)';
53
- COMMENT ON COLUMN credentials.userName IS 'Nome de usuário para autenticação básica';
54
- COMMENT ON COLUMN credentials.password IS 'Senha para autenticação básica (deve ser criptografada)';
55
- COMMENT ON COLUMN credentials.apiKey IS 'Chave de API para autenticação por API Key';
56
- COMMENT ON COLUMN credentials.token IS 'Token de acesso para autenticação por token';
57
- COMMENT ON COLUMN credentials.paramName IS 'Nome do parâmetro para envio da credencial';
58
- COMMENT ON COLUMN credentials.refreshToken IS 'Token de renovação para OAuth';
59
- COMMENT ON COLUMN credentials.clientSecret IS 'Segredo do cliente para OAuth';
60
- COMMENT ON COLUMN credentials.clientId IS 'ID do cliente para OAuth';
61
- COMMENT ON COLUMN credentials.sendIn IS 'Local de envio da credencial (0=header, 1=query, 2=body)';
62
- COMMENT ON COLUMN credentials.scheme IS 'Esquema de autenticação (0=Bearer, 1=Basic, 2=Custom)';
63
- COMMENT ON COLUMN credentials.prefix IS 'Prefixo para o valor da credencial (ex: "Bearer ", "API-Key ")';