/******************************************************************************/
/****              Generated by IBExpert 19/06/2023 10:21:25               ****/
/******************************************************************************/

/******************************************************************************/
/****     Following SET SQL DIALECT is just for the Database Comparer      ****/
/******************************************************************************/


/******************************************************************************/
/****                                Tables                                ****/
/******************************************************************************/


CREATE GENERATOR GEN_ROTAS_MINERACAO_ID;

CREATE TABLE ROTAS_MINERACAO (
    CODIGO        DOM_CODIGO NOT NULL /* DOM_CODIGO = INTEGER */,
    ATIVO         DOM_LOGICO DEFAULT 0 /* DOM_LOGICO = SMALLINT DEFAULT 0 */,
    DESCRICAO     DOM_TEXTO_150 /* DOM_TEXTO_150 = VARCHAR(150) */,
    IP            DOM_TEXTO_015 /* DOM_TEXTO_015 = VARCHAR(15) */,
    PORTA         DOM_TEXTO_005 /* DOM_TEXTO_005 = VARCHAR(5) */,
    TIPO          DOM_TEXTO_150 /* DOM_TEXTO_150 = VARCHAR(150) */,
    USUARIO       DOM_TEXTO_250 /* DOM_TEXTO_040 = VARCHAR(40) */,
    SENHA         DOM_TEXTO_250 /* DOM_TEXTO_040 = VARCHAR(40) */,
    ACCESS_TOKEN  DOM_ARQUIVO /* DOM_ARQUIVO = BLOB SUB_TYPE 0 SEGMENT SIZE 4096 */,
    LOTE_ENVIO    DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    QTD_THREADS   DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    COD_USUARIO   DOM_CODIGO /* DOM_CODIGO = INTEGER */,
    DATA_INC      DOM_DATA_HORA /* DOM_DATA_HORA = DATE */
);



/******************************************************************************/
/****                             Primary keys                             ****/
/******************************************************************************/

ALTER TABLE ROTAS_MINERACAO ADD CONSTRAINT PK_ROTAS_MINERACAO PRIMARY KEY (CODIGO);


/******************************************************************************/
/****                               Triggers                               ****/
/******************************************************************************/



SET TERM ^ ;



/******************************************************************************/
/****                         Triggers for tables                          ****/
/******************************************************************************/



/* Trigger: ROTAS_MINERACAO_BI */
CREATE OR ALTER TRIGGER ROTAS_MINERACAO_BI FOR ROTAS_MINERACAO
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.CODIGO IS NULL) THEN
    NEW.CODIGO = GEN_ID(GEN_ROTAS_MINERACAO_ID,1);
END
^

/* Trigger: ROTAS_MINERACAO_DATA_INC */
CREATE OR ALTER TRIGGER ROTAS_MINERACAO_DATA_INC FOR ROTAS_MINERACAO
ACTIVE BEFORE INSERT POSITION 1
as
begin
  new.DATA_INC = current_timestamp;
end
^

/* Trigger: ROTAS_MINERACAO_USUARIO */
CREATE OR ALTER TRIGGER ROTAS_MINERACAO_USUARIO FOR ROTAS_MINERACAO
ACTIVE BEFORE INSERT POSITION 2
AS
DECLARE VARIABLE I_TEMP INTEGER;
BEGIN
    SELECT COD_USUARIO 
    FROM FUNCAO_COD_USUARIO 
    INTO :I_TEMP;

    NEW.COD_USUARIO = :I_TEMP;
END
^

/* Trigger: TRG_PREVENT_ALTER */
CREATE OR ALTER TRIGGER TRG_PREVENT_ALTER FOR ROTAS_MINERACAO
ACTIVE BEFORE INSERT OR UPDATE OR DELETE POSITION 10
AS
BEGIN
  EXCEPTION EXCEPT_PROIBIDO_ALTERAR;
END
^
SET TERM ; ^