hubxglpi/scripts/data/database.sql
Rafael Lopes 2eba69ac12 FEAT: Dados inseridos no banco de dados intermediário.
- Dados coletados do hubsoft agora estão sendo inseridos no bando de dados hubglpi.
- Dados sendo inseridos através  do model e processos sendo controlado pelo processcontroller
2025-10-07 17:57:23 -03:00

62 lines
1.8 KiB
SQL

-- =============================================
-- BANCO DE DADOS: hubglpi
-- DESCRIÇÃO: Sistema de integração entre HubSoft e GLPI
-- OBS: Chamados sempre são abertos pelo HubSoft
-- =============================================
-- =============================================
-- TABELA: hubsoft_tickets
-- DESCRIÇÃO: Armazena os chamados originados do HubSoft
-- =============================================
CREATE TABLE hubsoft_tickets (
id_atendimento INT PRIMARY KEY,
codigo_cliente INTEGER NOT NULL,
status_atendimento VARCHAR(64) NOT NULL,
servico_nome VARCHAR(255),
protocolo_hub VARCHAR(50) UNIQUE NOT NULL,
ticket_mundiale INT,
cliente_nome VARCHAR(255) NOT NULL,
descricao_fechamento TEXT,
data_fechamento TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- =============================================
-- TABELA: sync_data
-- DESCRIÇÃO: Armazena o estado da sincronização entre HubSoft e GLPI
-- =============================================
CREATE TYPE source_last_enum AS ENUM ('hubsoft', 'glpi');
CREATE TYPE status_sync_enum AS ENUM (
'pending_create',
'created_glpi',
'pending_close',
'closed_glpi',
'sync_error',
'need_update'
);
CREATE TABLE sync_data (
id SERIAL PRIMARY KEY,
hubsoft_ticket_id INTEGER NOT NULL REFERENCES hubsoft_tickets(id_atendimento),
glpi_ticket_id INTEGER,
source_last source_last_enum DEFAULT 'hubsoft',
status_sync status_sync_enum DEFAULT 'pending_create',
sync_metadata JSONB,
last_sync_attempt TIMESTAMP,
sync_error_message TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE (hubsoft_ticket_id, glpi_ticket_id)
);