CREATE TABLE IF NOT EXISTS sales_goals (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    goal_month DATE NOT NULL,
    user_id INT UNSIGNED NULL,
    goal_amount DECIMAL(15, 2) NOT NULL DEFAULT 0,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    CONSTRAINT fk_sales_goals_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);

CREATE UNIQUE INDEX idx_sales_goals_unique_period_user
    ON sales_goals (goal_month, user_id);

CREATE INDEX idx_sales_goals_month
    ON sales_goals (goal_month);
