-- CostusWorx © 2026 — Feature 2: Add Funds
-- Audit trail of manual top-ups applied to assets.

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS asset_contributions (
    id              INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    tenant_id       INT UNSIGNED  NOT NULL,
    asset_id        INT UNSIGNED  NOT NULL,
    amount          DECIMAL(14,2) NOT NULL,
    effective_date  DATE          NOT NULL,
    note            VARCHAR(255)  DEFAULT NULL,
    created_by      INT UNSIGNED  NOT NULL,
    created_at      DATETIME      NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (tenant_id)  REFERENCES tenants(id),
    FOREIGN KEY (asset_id)   REFERENCES assets(id) ON DELETE CASCADE,
    FOREIGN KEY (created_by) REFERENCES users(id),
    INDEX idx_asset (asset_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
