CREATE TABLE TBDRE_GERENCIAL_VISUALIZACAO (
    ID INTEGER NOT NULL,
    DESCRICAO INTEGER,
    STATUS INTEGER);

ALTER TABLE TBDRE_GERENCIAL_VISUALIZACAO
ADD CONSTRAINT PK_TBDRE_GERENCIAL_VISUALIZACAO
PRIMARY KEY (ID);

CREATE SEQUENCE GTBDRE_GERENCIAL_VISUAL;

create trigger ttbdre_gerencial_visual_bi for tbdre_gerencial_visualizacao
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbdre_gerencial_visual,1);
end;

ALTER TABLE TBDRE_GERENCIAL_VISUALIZACAO
    ALTER DESCRICAO TYPE VARCHAR(50);

ALTER TABLE TBDRE_GERENCIAL_VISUALIZACAO
    ADD DRE_ID INTEGER;

ALTER TABLE TBDRE_GERENCIAL_HISTORICO_MES
    ADD VISUALIZACAO_ID INTEGER DEFAULT 1;

CREATE TABLE TBDRE_GERENCIAL_VIS_ITEM (
    ID INTEGER NOT NULL,
    CONTA_ID INTEGER,
    VISUALIZACAO_ID INTEGER,
    MARCADO INTEGER);

ALTER TABLE TBDRE_GERENCIAL_VIS_ITEM
ADD CONSTRAINT PK_TBDRE_GERENCIAL_VIS_ITEM
PRIMARY KEY (ID);

CREATE SEQUENCE GTBDRE_GERENCIAL_VIS_ITEM;

create trigger Ttbdre_gerencial_vis_item_b01i for tbdre_gerencial_vis_item
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbdre_gerencial_vis_item,1);
end;
