CREATE TABLE asset_type (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL UNIQUE
);

CREATE TABLE asset (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    asset_type_id INT NOT NULL,
    FOREIGN KEY (asset_type_id) REFERENCES asset_type(id)
);

CREATE TABLE log_type (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL UNIQUE
);

CREATE TABLE log (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    log_type_id INT NOT NULL,
    date DATE DEFAULT CURRENT_DATE,
    FOREIGN KEY (log_type_id) REFERENCES log_type(id)
);

-- Junction table for equipment assets
CREATE TABLE log_equipment_asset (
    log_id INT NOT NULL,
    asset_id INT NOT NULL,
    PRIMARY KEY (log_id, asset_id),
    FOREIGN KEY (log_id) REFERENCES log(id) ON DELETE CASCADE,
    FOREIGN KEY (asset_id) REFERENCES asset(id) ON DELETE CASCADE
);

-- Junction table for substance assets
CREATE TABLE log_substance_asset (
    log_id INT NOT NULL,
    asset_id INT NOT NULL,
    PRIMARY KEY (log_id, asset_id),
    FOREIGN KEY (log_id) REFERENCES log(id) ON DELETE CASCADE,
    FOREIGN KEY (asset_id) REFERENCES asset(id) ON DELETE CASCADE
);
