CREATE TABLE TBTELEGRAM_SOLICITACAO (
    ID INTEGER NOT NULL,
    FONE VARCHAR(50),
    NOME VARCHAR(50),
    DATAHORA TIMESTAMP);

ALTER TABLE TBTELEGRAM_SOLICITACAO
ADD CONSTRAINT PK_TBTELEGRAM_SOLICITACAO
PRIMARY KEY (ID);

CREATE SEQUENCE GTBTELEGRAM_SOLICITACAO;

SET TERM ^ ;

create trigger Ttbtelegram_solicitacao_b01i for tbtelegram_solicitacao
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbtelegram_solicitacao,1);
end
^

SET TERM ; ^

ALTER TABLE TBWHATSAPP
    ADD CHAT_ID INTEGER;

CREATE TABLE TELEGRAM_MENSAGENS (
    ID INTEGER NOT NULL,
    USUARIO_ID INTEGER,
    STATUS INTEGER,
    DATAHORA TIMESTAMP,
    DATAHORA_ENV TIMESTAMP,
    MSG VARCHAR(500));

ALTER TABLE TELEGRAM_MENSAGENS
ADD CONSTRAINT PK_TELEGRAM_MENSAGENS
PRIMARY KEY (ID);

CREATE SEQUENCE GTELEGRAM_MENSAGENS;

SET TERM ^ ;

create trigger ttelegram_mensagens_b01i for telegram_mensagens
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtelegram_mensagens,1);
end
^

SET TERM ; ^

CREATE INDEX ITELEGRAM_MENSAGENS_01
ON TELEGRAM_MENSAGENS (STATUS);

