@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.
Files changed (54) hide show
  1. package/package.json +1 -1
  2. package/src/modules/objectives/index.js +1 -1
  3. package/src/modules/objectives/properties.js +8 -7
  4. package/src/product.js +1 -25
  5. package/docs/ERD_GAGents_Database.mmd +0 -331
  6. package/scripts/MIGRATION_COMPLETE_DOCUMENTATION.md +0 -672
  7. package/scripts/README.md +0 -165
  8. package/scripts/constraints.sql +0 -585
  9. package/scripts/indexes.sql +0 -661
  10. package/scripts/migrate_v1.sql +0 -1225
  11. package/scripts/tables/001_accounts.sql +0 -51
  12. package/scripts/tables/002_users.sql +0 -69
  13. package/scripts/tables/003_people.sql +0 -70
  14. package/scripts/tables/004_tags.sql +0 -62
  15. package/scripts/tables/005_credentials.sql +0 -79
  16. package/scripts/tables/006_agents.sql +0 -70
  17. package/scripts/tables/007_tools.sql +0 -68
  18. package/scripts/tables/008_channels.sql +0 -75
  19. package/scripts/tables/009_leads.sql +0 -85
  20. package/scripts/tables/010_missions.sql +0 -62
  21. package/scripts/tables/011_objectives.sql +0 -68
  22. package/scripts/tables/012_conversations.sql +0 -80
  23. package/scripts/tables/013_objectives_tools.sql +0 -66
  24. package/scripts/tables/014_messages.sql +0 -78
  25. package/scripts/tables/015_companies.sql +0 -77
  26. package/scripts/tables/016_conversations_tags.sql +0 -64
  27. package/scripts/tables/017_leads_tags.sql +0 -64
  28. package/scripts/triggers.sql +0 -497
  29. package/src/modules/channels/index.js +0 -10
  30. package/src/modules/channels/properties.js +0 -150
  31. package/src/modules/companies/index.js +0 -10
  32. package/src/modules/companies/properties.js +0 -168
  33. package/src/modules/conversations/index.js +0 -10
  34. package/src/modules/conversations/properties.js +0 -163
  35. package/src/modules/conversations_tags/index.js +0 -10
  36. package/src/modules/conversations_tags/properties.js +0 -84
  37. package/src/modules/credentials/index.js +0 -10
  38. package/src/modules/credentials/properties.js +0 -271
  39. package/src/modules/leads/index.js +0 -10
  40. package/src/modules/leads/properties.js +0 -193
  41. package/src/modules/leads_tags/index.js +0 -10
  42. package/src/modules/leads_tags/properties.js +0 -84
  43. package/src/modules/messages/index.js +0 -10
  44. package/src/modules/messages/properties.js +0 -152
  45. package/src/modules/missions/index.js +0 -10
  46. package/src/modules/missions/properties.js +0 -101
  47. package/src/modules/objectives_tools/index.js +0 -10
  48. package/src/modules/objectives_tools/properties.js +0 -109
  49. package/src/modules/people/index.js +0 -10
  50. package/src/modules/people/properties.js +0 -161
  51. package/src/modules/tags/index.js +0 -10
  52. package/src/modules/tags/properties.js +0 -80
  53. package/src/modules/tools/index.js +0 -10
  54. package/src/modules/tools/properties.js +0 -121
@@ -1,51 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 001_accounts.sql
3
- -- Descrição: Tabela base de contas - sem dependências
4
- -- Versão: 1.0
5
- -- Dependências: Nenhuma (tabela base)
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 da tabela: accounts', now();
19
- END $$;
20
-
21
- -- Criação da tabela accounts (tabela base sem dependências)
22
- CREATE TABLE IF NOT EXISTS accounts (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela accounts
31
- name VARCHAR(100) -- Campo name com maxLength: 100
32
- );
33
-
34
- -- Comentários na tabela
35
- COMMENT ON TABLE accounts IS 'Tabela base de contas do sistema';
36
- COMMENT ON COLUMN accounts.id IS 'Identificador único da conta';
37
- COMMENT ON COLUMN accounts.name IS 'Nome da conta';
38
- COMMENT ON COLUMN accounts.deleted IS 'Flag de exclusão lógica';
39
- COMMENT ON COLUMN accounts.datetime_add IS 'Data e hora de criação do registro';
40
- COMMENT ON COLUMN accounts.datetime_alt IS 'Data e hora da última alteração';
41
- COMMENT ON COLUMN accounts.datetime_del IS 'Data e hora da exclusão lógica';
42
-
43
- -- Verificação pós-execução
44
- DO $$
45
- BEGIN
46
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'accounts') THEN
47
- RAISE EXCEPTION 'Falha na criação da tabela accounts';
48
- END IF;
49
-
50
- RAISE NOTICE '[%] Tabela accounts criada com sucesso', now();
51
- END $$;
@@ -1,69 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 002_users.sql
3
- -- Descrição: Tabela de usuários - depende de accounts
4
- -- Versão: 1.0
5
- -- Dependências: accounts
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 da tabela: users', now();
19
- END $$;
20
-
21
- -- Criação da tabela users (depende de accounts)
22
- CREATE TABLE IF NOT EXISTS users (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela users
31
- id_account INTEGER NOT NULL,
32
- name VARCHAR(50), -- maxLength: 50
33
- last_name VARCHAR(255), -- sem maxLength definido
34
- email VARCHAR(255) NOT NULL, -- required: true, format: email
35
- profile VARCHAR(50) DEFAULT 'collaborator', -- default: "collaborator"
36
- photo VARCHAR(255), -- type: image -> VARCHAR para URL da imagem
37
-
38
- -- Foreign keys
39
- FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
40
-
41
- -- Constraints
42
- CONSTRAINT users_email_valid CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'),
43
- CONSTRAINT users_profile_valid CHECK (profile IN ('viewer', 'collaborator', 'admin', 'owner', 'attendant'))
44
- );
45
-
46
- -- Índices para otimização
47
- CREATE INDEX IF NOT EXISTS idx_users_id_account ON users(id_account);
48
- CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
49
- CREATE INDEX IF NOT EXISTS idx_users_profile ON users(profile);
50
-
51
- -- Comentários na tabela
52
- COMMENT ON TABLE users IS 'Tabela de usuários do sistema';
53
- COMMENT ON COLUMN users.id IS 'Identificador único do usuário';
54
- COMMENT ON COLUMN users.id_account IS 'Referência à conta (FK)';
55
- COMMENT ON COLUMN users.name IS 'Nome do usuário';
56
- COMMENT ON COLUMN users.last_name IS 'Sobrenome do usuário';
57
- COMMENT ON COLUMN users.email IS 'E-mail do usuário (obrigatório)';
58
- COMMENT ON COLUMN users.profile IS 'Perfil de acesso (viewer, collaborator, admin, owner, attendant)';
59
- COMMENT ON COLUMN users.photo IS 'URL da foto do usuário';
60
-
61
- -- Verificação pós-execução
62
- DO $$
63
- BEGIN
64
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'users') THEN
65
- RAISE EXCEPTION 'Falha na criação da tabela users';
66
- END IF;
67
-
68
- RAISE NOTICE '[%] Tabela users criada com sucesso', now();
69
- END $$;
@@ -1,70 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 003_people.sql
3
- -- Descrição: Tabela de pessoas - depende de accounts
4
- -- Versão: 1.0
5
- -- Dependências: accounts
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 da tabela: people', now();
19
- END $$;
20
-
21
- -- Criação da tabela people (depende de accounts)
22
- CREATE TABLE IF NOT EXISTS people (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela people
31
- id_account INTEGER NOT NULL,
32
- full_name VARCHAR(255), -- maxLength: 255, searchable
33
- first_name VARCHAR(255), -- maxLength: 255, searchable
34
- last_name VARCHAR(255), -- maxLength: 255, searchable
35
- photo VARCHAR(255), -- type: image -> VARCHAR para URL da imagem
36
- document VARCHAR(50), -- maxLength: 50, searchable (CPF/CNPJ)
37
- birth_date TIMESTAMP WITH TIME ZONE, -- type: date
38
-
39
- -- Foreign keys
40
- FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE
41
- );
42
-
43
- -- Índices para otimização
44
- CREATE INDEX IF NOT EXISTS idx_people_id_account ON people(id_account);
45
- CREATE INDEX IF NOT EXISTS idx_people_full_name ON people(full_name);
46
- CREATE INDEX IF NOT EXISTS idx_people_first_name ON people(first_name);
47
- CREATE INDEX IF NOT EXISTS idx_people_last_name ON people(last_name);
48
- CREATE INDEX IF NOT EXISTS idx_people_document ON people(document);
49
- CREATE INDEX IF NOT EXISTS idx_people_birth_date ON people(birth_date);
50
-
51
- -- Comentários na tabela
52
- COMMENT ON TABLE people IS 'Tabela de pessoas do sistema';
53
- COMMENT ON COLUMN people.id IS 'Identificador único da pessoa';
54
- COMMENT ON COLUMN people.id_account IS 'Referência à conta (FK)';
55
- COMMENT ON COLUMN people.full_name IS 'Nome completo da pessoa';
56
- COMMENT ON COLUMN people.first_name IS 'Primeiro nome da pessoa';
57
- COMMENT ON COLUMN people.last_name IS 'Último nome da pessoa';
58
- COMMENT ON COLUMN people.photo IS 'URL da foto da pessoa';
59
- COMMENT ON COLUMN people.document IS 'Documento da pessoa (CPF/CNPJ)';
60
- COMMENT ON COLUMN people.birth_date IS 'Data de nascimento da pessoa';
61
-
62
- -- Verificação pós-execução
63
- DO $$
64
- BEGIN
65
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'people') THEN
66
- RAISE EXCEPTION 'Falha na criação da tabela people';
67
- END IF;
68
-
69
- RAISE NOTICE '[%] Tabela people criada com sucesso', now();
70
- END $$;
@@ -1,62 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 004_tags.sql
3
- -- Descrição: Tabela de tags - depende de accounts
4
- -- Versão: 1.0
5
- -- Dependências: accounts
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 da tabela: tags', now();
19
- END $$;
20
-
21
- -- Criação da tabela tags (depende de accounts)
22
- CREATE TABLE IF NOT EXISTS tags (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela tags
31
- id_account INTEGER NOT NULL,
32
- name VARCHAR(255) NOT NULL, -- required: true, maxLength: 255
33
- color VARCHAR(7) DEFAULT '#000000', -- default: "#000000"
34
-
35
- -- Foreign keys
36
- FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
37
-
38
- -- Constraints
39
- CONSTRAINT tags_color_valid CHECK (color ~* '^#[0-9A-Fa-f]{6}$')
40
- );
41
-
42
- -- Índices para otimização
43
- CREATE INDEX IF NOT EXISTS idx_tags_id_account ON tags(id_account);
44
- CREATE INDEX IF NOT EXISTS idx_tags_name ON tags(name);
45
- CREATE INDEX IF NOT EXISTS idx_tags_color ON tags(color);
46
-
47
- -- Comentários na tabela
48
- COMMENT ON TABLE tags IS 'Tabela de tags do sistema';
49
- COMMENT ON COLUMN tags.id IS 'Identificador único da tag';
50
- COMMENT ON COLUMN tags.id_account IS 'Referência à conta (FK)';
51
- COMMENT ON COLUMN tags.name IS 'Nome da tag (obrigatório)';
52
- COMMENT ON COLUMN tags.color IS 'Cor da tag em formato hexadecimal';
53
-
54
- -- Verificação pós-execução
55
- DO $$
56
- BEGIN
57
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'tags') THEN
58
- RAISE EXCEPTION 'Falha na criação da tabela tags';
59
- END IF;
60
-
61
- RAISE NOTICE '[%] Tabela tags criada com sucesso', now();
62
- END $$;
@@ -1,79 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 005_credentials.sql
3
- -- Descrição: Tabela de credenciais - depende de accounts
4
- -- Versão: 1.0
5
- -- Dependências: accounts
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 da tabela: credentials', now();
19
- END $$;
20
-
21
- -- Criação da tabela credentials (depende de accounts)
22
- CREATE TABLE IF NOT EXISTS credentials (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela credentials
31
- id_account INTEGER NOT NULL,
32
- title VARCHAR(255) NOT NULL, -- required: true, maxLength: 255
33
- provider VARCHAR(50) DEFAULT 'web-chat' NOT NULL, -- required: true, default: "web-chat"
34
- authType VARCHAR(20) DEFAULT 'none' NOT NULL, -- required: true, default: "none"
35
- userName VARCHAR(255), -- opcional
36
- password VARCHAR(255), -- opcional
37
- apiKey VARCHAR(255), -- opcional
38
- token TEXT, -- opcional, pode ser longo
39
- paramName VARCHAR(255), -- opcional
40
- refreshToken TEXT, -- opcional, pode ser longo
41
- clientSecret VARCHAR(255), -- opcional
42
- clientId VARCHAR(255), -- opcional
43
- sendIn VARCHAR(20) DEFAULT 'none', -- default: "none"
44
- scheme VARCHAR(20) DEFAULT 'none', -- default: "none"
45
- prefix VARCHAR(100), -- opcional
46
-
47
- -- Foreign keys
48
- FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
49
-
50
- -- Constraints
51
- CONSTRAINT credentials_provider_valid CHECK (provider IN ('web-chat', 'whatsapp-oficial', 'z-api', 'evolution-api', 'telegram', 'facebook', 'instagram', 'custom')),
52
- CONSTRAINT credentials_authtype_valid CHECK (authType IN ('none', 'basic', 'oauth2', 'apikey')),
53
- CONSTRAINT credentials_sendin_valid CHECK (sendIn IN ('none', 'bearer', 'header', 'query', 'body')),
54
- CONSTRAINT credentials_scheme_valid CHECK (scheme IN ('none', 'raw', 'bearer', 'prefix'))
55
- );
56
-
57
- -- Índices para otimização
58
- CREATE INDEX IF NOT EXISTS idx_credentials_id_account ON credentials(id_account);
59
- CREATE INDEX IF NOT EXISTS idx_credentials_title ON credentials(title);
60
- CREATE INDEX IF NOT EXISTS idx_credentials_provider ON credentials(provider);
61
- CREATE INDEX IF NOT EXISTS idx_credentials_authtype ON credentials(authType);
62
-
63
- -- Comentários na tabela
64
- COMMENT ON TABLE credentials IS 'Tabela de credenciais do sistema';
65
- COMMENT ON COLUMN credentials.id IS 'Identificador único da credencial';
66
- COMMENT ON COLUMN credentials.id_account IS 'Referência à conta (FK)';
67
- COMMENT ON COLUMN credentials.title IS 'Título da credencial (obrigatório)';
68
- COMMENT ON COLUMN credentials.provider IS 'Provedor da credencial';
69
- COMMENT ON COLUMN credentials.authType IS 'Tipo de autenticação';
70
-
71
- -- Verificação pós-execução
72
- DO $$
73
- BEGIN
74
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'credentials') THEN
75
- RAISE EXCEPTION 'Falha na criação da tabela credentials';
76
- END IF;
77
-
78
- RAISE NOTICE '[%] Tabela credentials criada com sucesso', now();
79
- END $$;
@@ -1,70 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 006_agents.sql
3
- -- Descrição: Tabela de agentes - depende de accounts
4
- -- Versão: 1.0
5
- -- Dependências: accounts
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 da tabela: agents', now();
19
- END $$;
20
-
21
- -- Criação da tabela agents (depende de accounts)
22
- CREATE TABLE IF NOT EXISTS agents (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela agents
31
- id_account INTEGER NOT NULL,
32
- title VARCHAR(255) NOT NULL, -- required: true, maxLength: 255
33
- photo VARCHAR(255), -- type: image -> VARCHAR para URL da imagem
34
- prompt TEXT, -- type: string, pode ser longo
35
- delay_typing INTEGER DEFAULT 0, -- type: number, default: 0
36
- waiting_time INTEGER DEFAULT 0, -- type: number, default: 0
37
-
38
- -- Foreign keys
39
- FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
40
-
41
- -- Constraints
42
- CONSTRAINT agents_delay_typing_valid CHECK (delay_typing >= 0),
43
- CONSTRAINT agents_waiting_time_valid CHECK (waiting_time >= 0)
44
- );
45
-
46
- -- Índices para otimização
47
- CREATE INDEX IF NOT EXISTS idx_agents_id_account ON agents(id_account);
48
- CREATE INDEX IF NOT EXISTS idx_agents_title ON agents(title);
49
- CREATE INDEX IF NOT EXISTS idx_agents_delay_typing ON agents(delay_typing);
50
- CREATE INDEX IF NOT EXISTS idx_agents_waiting_time ON agents(waiting_time);
51
-
52
- -- Comentários na tabela
53
- COMMENT ON TABLE agents IS 'Tabela de agentes do sistema';
54
- COMMENT ON COLUMN agents.id IS 'Identificador único do agente';
55
- COMMENT ON COLUMN agents.id_account IS 'Referência à conta (FK)';
56
- COMMENT ON COLUMN agents.title IS 'Título do agente (obrigatório)';
57
- COMMENT ON COLUMN agents.photo IS 'URL da foto do agente';
58
- COMMENT ON COLUMN agents.prompt IS 'Instruções do agente';
59
- COMMENT ON COLUMN agents.delay_typing IS 'Atraso em segundos para mostrar "digitando..."';
60
- COMMENT ON COLUMN agents.waiting_time IS 'Tempo em segundos para aguardar mensagens antes de responder';
61
-
62
- -- Verificação pós-execução
63
- DO $$
64
- BEGIN
65
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'agents') THEN
66
- RAISE EXCEPTION 'Falha na criação da tabela agents';
67
- END IF;
68
-
69
- RAISE NOTICE '[%] Tabela agents criada com sucesso', now();
70
- END $$;
@@ -1,68 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 007_tools.sql
3
- -- Descrição: Tabela de ferramentas - depende de accounts
4
- -- Versão: 1.0
5
- -- Dependências: accounts
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 da tabela: tools', now();
19
- END $$;
20
-
21
- -- Criação da tabela tools (depende de accounts)
22
- CREATE TABLE IF NOT EXISTS tools (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela tools
31
- id_account INTEGER NOT NULL,
32
- title VARCHAR(255) NOT NULL, -- required: true, maxLength: 255
33
- type VARCHAR(50) DEFAULT 'mcp', -- default: "mcp"
34
- description TEXT, -- maxLength: 1000, pode ser grande
35
- id_credential INTEGER, -- required: false, pode ser NULL
36
-
37
- -- Foreign keys
38
- FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
39
- FOREIGN KEY (id_credential) REFERENCES credentials(id) ON DELETE SET NULL,
40
-
41
- -- Constraints
42
- CONSTRAINT tools_type_valid CHECK (type IN ('mcp', 'a2a', 'api', 'internal-agent', 'internal-function', 'native-integration', 'knowledge-base'))
43
- );
44
-
45
- -- Índices para otimização
46
- CREATE INDEX IF NOT EXISTS idx_tools_id_account ON tools(id_account);
47
- CREATE INDEX IF NOT EXISTS idx_tools_title ON tools(title);
48
- CREATE INDEX IF NOT EXISTS idx_tools_type ON tools(type);
49
- CREATE INDEX IF NOT EXISTS idx_tools_id_credential ON tools(id_credential);
50
-
51
- -- Comentários na tabela
52
- COMMENT ON TABLE tools IS 'Tabela de ferramentas do sistema';
53
- COMMENT ON COLUMN tools.id IS 'Identificador único da ferramenta';
54
- COMMENT ON COLUMN tools.id_account IS 'Referência à conta (FK)';
55
- COMMENT ON COLUMN tools.title IS 'Título da ferramenta (obrigatório)';
56
- COMMENT ON COLUMN tools.type IS 'Tipo da ferramenta';
57
- COMMENT ON COLUMN tools.description IS 'Descrição da ferramenta';
58
- COMMENT ON COLUMN tools.id_credential IS 'Referência à credencial (FK, opcional)';
59
-
60
- -- Verificação pós-execução
61
- DO $$
62
- BEGIN
63
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'tools') THEN
64
- RAISE EXCEPTION 'Falha na criação da tabela tools';
65
- END IF;
66
-
67
- RAISE NOTICE '[%] Tabela tools criada com sucesso', now();
68
- END $$;
@@ -1,75 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 008_channels.sql
3
- -- Descrição: Tabela de canais - depende de credentials
4
- -- Versão: 1.0
5
- -- Dependências: credentials
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 da tabela: channels', now();
19
- END $$;
20
-
21
- -- Criação da tabela channels (depende de accounts e credentials)
22
- CREATE TABLE IF NOT EXISTS channels (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela channels
31
- id_account INTEGER NOT NULL,
32
- title VARCHAR(255) NOT NULL, -- required: true, maxLength: 255
33
- provider VARCHAR(50) DEFAULT 'web-chat' NOT NULL, -- required: true, default: "web-chat"
34
- url VARCHAR(255), -- opcional
35
- active BOOLEAN DEFAULT TRUE, -- default: true
36
- id_credential INTEGER, -- required: false, pode ser NULL
37
- handle VARCHAR(255), -- maxLength: 255, identificador único do canal
38
-
39
- -- Foreign keys
40
- FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
41
- FOREIGN KEY (id_credential) REFERENCES credentials(id) ON DELETE SET NULL,
42
-
43
- -- Constraints
44
- CONSTRAINT channels_provider_valid CHECK (provider IN ('web-chat', 'whatsap-oficial', 'z-api', 'evolution-api', 'telegram', 'facebook', 'instagram')),
45
- CONSTRAINT channels_url_valid CHECK (url IS NULL OR url ~* '^https?://.*')
46
- );
47
-
48
- -- Índices para otimização
49
- CREATE INDEX IF NOT EXISTS idx_channels_id_account ON channels(id_account);
50
- CREATE INDEX IF NOT EXISTS idx_channels_title ON channels(title);
51
- CREATE INDEX IF NOT EXISTS idx_channels_provider ON channels(provider);
52
- CREATE INDEX IF NOT EXISTS idx_channels_active ON channels(active);
53
- CREATE INDEX IF NOT EXISTS idx_channels_id_credential ON channels(id_credential);
54
- CREATE INDEX IF NOT EXISTS idx_channels_handle ON channels(handle);
55
-
56
- -- Comentários na tabela
57
- COMMENT ON TABLE channels IS 'Tabela de canais de comunicação do sistema';
58
- COMMENT ON COLUMN channels.id IS 'Identificador único do canal';
59
- COMMENT ON COLUMN channels.id_account IS 'Referência à conta (FK)';
60
- COMMENT ON COLUMN channels.title IS 'Título do canal (obrigatório)';
61
- COMMENT ON COLUMN channels.provider IS 'Provedor do canal';
62
- COMMENT ON COLUMN channels.url IS 'URL do canal';
63
- COMMENT ON COLUMN channels.active IS 'Status ativo do canal';
64
- COMMENT ON COLUMN channels.id_credential IS 'Referência à credencial (FK, opcional)';
65
- COMMENT ON COLUMN channels.handle IS 'Identificador único do canal (número WhatsApp, ID Telegram, etc.)';
66
-
67
- -- Verificação pós-execução
68
- DO $$
69
- BEGIN
70
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'channels') THEN
71
- RAISE EXCEPTION 'Falha na criação da tabela channels';
72
- END IF;
73
-
74
- RAISE NOTICE '[%] Tabela channels criada com sucesso', now();
75
- END $$;
@@ -1,85 +0,0 @@
1
- -- ============================================================================
2
- -- Script: 009_leads.sql
3
- -- Descrição: Tabela de leads - depende de people
4
- -- Versão: 1.0
5
- -- Dependências: people
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 da tabela: leads', now();
19
- END $$;
20
-
21
- -- Criação da tabela leads (depende de accounts, people, users, agents, missions, objectives)
22
- CREATE TABLE IF NOT EXISTS leads (
23
- -- Campos automáticos padrão
24
- id SERIAL PRIMARY KEY,
25
- deleted BOOLEAN DEFAULT FALSE,
26
- datetime_add TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
27
- datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
28
- datetime_del TIMESTAMP WITH TIME ZONE NULL,
29
-
30
- -- Campos específicos da tabela leads
31
- id_account INTEGER NOT NULL,
32
- id_person INTEGER NOT NULL,
33
- email VARCHAR(255), -- maxLength: 255, pattern: email
34
- phone VARCHAR(20), -- maxLength: 20, pattern: phone
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
- notes TEXT, -- searchable, pode ser longo
40
-
41
- -- Foreign keys
42
- FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
43
- FOREIGN KEY (id_person) REFERENCES people(id) ON DELETE CASCADE,
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
-
49
- -- Constraints
50
- CONSTRAINT leads_email_valid CHECK (email IS NULL OR email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'),
51
- CONSTRAINT leads_phone_valid CHECK (phone IS NULL OR phone ~* '^\+?[1-9]\d{1,14}$')
52
- );
53
-
54
- -- Índices para otimização
55
- CREATE INDEX IF NOT EXISTS idx_leads_id_account ON leads(id_account);
56
- CREATE INDEX IF NOT EXISTS idx_leads_id_person ON leads(id_person);
57
- CREATE INDEX IF NOT EXISTS idx_leads_email ON leads(email);
58
- CREATE INDEX IF NOT EXISTS idx_leads_phone ON leads(phone);
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
-
64
- -- Comentários na tabela
65
- COMMENT ON TABLE leads IS 'Tabela de leads do sistema';
66
- COMMENT ON COLUMN leads.id IS 'Identificador único do lead';
67
- COMMENT ON COLUMN leads.id_account IS 'Referência à conta (FK)';
68
- COMMENT ON COLUMN leads.id_person IS 'Referência à pessoa (FK)';
69
- COMMENT ON COLUMN leads.email IS 'E-mail do lead';
70
- COMMENT ON COLUMN leads.phone IS 'Telefone do lead';
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
- COMMENT ON COLUMN leads.notes IS 'Notas sobre o lead';
76
-
77
- -- Verificação pós-execução
78
- DO $$
79
- BEGIN
80
- IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'leads') THEN
81
- RAISE EXCEPTION 'Falha na criação da tabela leads';
82
- END IF;
83
-
84
- RAISE NOTICE '[%] Tabela leads criada com sucesso', now();
85
- END $$;