-- Cria tabela para controle mensal de exercícios
CREATE TABLE IF NOT EXISTS back.exerciciodet (
    cdexerciciodet SERIAL PRIMARY KEY,
    cdexercicio    INT NOT NULL REFERENCES back.exercicio(cdexercicio) ON DELETE CASCADE,
    mesref         SMALLINT NOT NULL CHECK (mesref BETWEEN 1 AND 12),
    flaberto       BOOLEAN NOT NULL DEFAULT TRUE,
    dtfechamento   TIMESTAMP NULL,
    dthcriacao     TIMESTAMP NOT NULL DEFAULT NOW(),
    dthedicao      TIMESTAMP NOT NULL DEFAULT NOW(),
    UNIQUE (cdexercicio, mesref)
);
