create table gestor(
    id int not null primary key auto_increment,
    name varchar(255),
    password varchar(255),
    email varchar(255),
    token varchar(255)
);

create table paciente(
    id int not null primary key auto_increment,
    name varchar(255),
    password varchar(255),
    email varchar(255),
    token varchar(255),
    id_gestor int not null,
    constraint foreign key fk_id_gestor (id_gestor) 
    references gestor (id)
);

create table alarm(
    id int not null primary key auto_increment,
    nameMedcines varchar(255),
    qtdDayMedicines varchar(255),
    hourTakeNextMedicine varchar(255),
    qtdMedicines varchar(255),
    dateInitMedidicne varchar(255),
    active varchar(255),
    intervalDay varchar(255),
    hourTakeMedicine  varchar(255),
    id_paciente int not null,
    constraint fk_id_superior foreign key (id_paciente) references paciente(id) 
);
alter table alarm add column updated_at timestamp;
alter table alarm add column created_at VARCHAR(255);



create table unidade(
    codigo int not null primary key auto_increment,
    nome varchar(255) not null,
    endereco varchar(255) not null,
    cidade varchar(255) not null,
    cep varchar(255) not null,
    descricao text  
);


create table usuario(
    codigo int not null primary key auto_increment,
    nome varchar(255) not null,
    matricula varchar(255) not null,
    descricao text,
    id_superior int,
    constraint fk_id_superior foreign key (id_superior) references superior(codigo) 
);




create table superior(
    codigo int not null primary key auto_increment,
    nome varchar(255) not null
);
insert into superior values 
(1, 'Jose Gomes'),
(2, 'Augusto Lobos');

alter table gestor add column updated_at timestamp;
alter table gestor add column created_at VARCHAR(255);

alter table usuario add column id_unidade int after id_superior;
--add fk
alter table usuario add constraint fk_unidade foreign key (id_unidade) 
references unidade (id)

