--ideia reduzir a complexidade da tabela
-- colocar apenas token, id de queme ele pertence, e apenas a data de validade.
-- com isso reduz a complexidade melhora a segurança
-- e mais fazer uma rotina que remova todos os token que tenhão vencido do banco
-- com isso evita sqlIject e melhorar o desempenho

-- "$2a$10$MTgwODQxNjg0NTU1M2E2OOpOyRBAqP41zPrh6.cgYxePqEyjx38bC"
-- "$2a$10$MTE1MzA0NzgwMTU1M2E2NuK5l8BbSeABM5GOvJ6.ukMd2.XN2Uqfm"

SELECT * FROM tokens;

SELECT * FROM tokens WHERE token = '$2a$10$MTgwODQxNjg0NTU1M2E2OOpOyRBAqP41zPrh6.cgYxePqEyjx38bC' AND expiredate >= 'now';

SELECT * FROM getToken WHERE token = '$2a$10$MTgwODQxNjg0NTU1M2E2OOpOyRBAqP41zPrh6.cgYxePqEyjx38bC';

CREATE VIEW getToken AS (
SELECT token FROM tokens WHERE
expiredate >= 'now'
);

CREATE VIEW getToken AS(
SELECT status, token FROM tokens WHERE
status = 1
);

DROP VIEW getToken;

SELECT * FROM tokens WHERE
token = '$2a$10$MTgwODQxNjg0NTU1M2E2OOpOyRBAqP41zPrh6.cgYxePqEyjx38bC'
AND expire = true
AND expiredate <= 'now'
AND status = 1;

UPDATE tokens SET status = 1
WHERE status = 0
AND expire = true

UPDATE tokens SET status = 0
WHERE expire = true
AND status != 0
AND expiredate <= 'now'

DELETE FROM tokens WHERE expiredate <= 'now';

INSERT INTO tokens (token, expiredate) 
VALUES 
('9B1549D8FC9FA1FDF68430E6BF0DB5094151C168', CURRENT_TIMESTAMP(0)+ interval '2 hours'),
('9B1549D8FC9FA1FDF68430E6BF0DB5094151C175', CURRENT_TIMESTAMP(0)+ interval '20 hours');

SELECT CURRENT_TIMESTAMP(0) AS "Date E Hora";

SELECT * FROM tokens WHERE token = '9B1549D8FC9FA1FDF68430E6BF0DB5094151C168';








