
CREATE TABLE IF NOT EXISTS contribution_log (

  id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,

  member_id INT UNSIGNED NOT NULL,

  contribution_plan_id INT UNSIGNED NOT NULL,

  staff_id INT UNSIGNED NULL,

  amount DECIMAL(12,2) NOT NULL,

  month_number TINYINT UNSIGNED NOT NULL,

  year SMALLINT UNSIGNED NOT NULL,

  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

  CONSTRAINT fk_cl_member FOREIGN KEY (member_id) REFERENCES members (id) ON DELETE CASCADE,

  CONSTRAINT fk_cl_plan FOREIGN KEY (contribution_plan_id) REFERENCES contribution_plans (id) ON DELETE CASCADE,

  CONSTRAINT fk_cl_staff FOREIGN KEY (staff_id) REFERENCES staff (id) ON DELETE SET NULL,

  INDEX idx_cl_member (member_id),

  INDEX idx_cl_staff (staff_id),

  INDEX idx_cl_month_year (year, month_number)

);

