Bug #117802 Enable DDL Change Tracking Through Native Triggers with Database Configuration
Submitted: 26 Mar 13:49 Modified: 27 Mar 6:38
Reporter: Luis Calabro Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S4 (Feature request)
Version:8.0.36 OS:Any
Assigned to: CPU Architecture:Any
Tags: change-tracking, database-versioning, DDL, mysql-enhancement, trigger

[26 Mar 13:49] Luis Calabro
Description:
This feature request proposes implementing DDL triggers in MySQL, similar to those available in PostgreSQL, Oracle, and SQL Server. This would allow automatic tracking of database structural changes without external tools.

-- Current MySQL implementation lacks automatic tracking of DDL operations
-- This feature request proposes adding native DDL trigger support
-- Can be enabled/disabled through database configuration

Problem Statement:
-- 1. No built-in way to automatically track structural database changes
-- 2. Cannot capture DDL operations (CREATE, ALTER, DROP) using triggers
-- 3. External tools required for database versioning

How to repeat:
This is a feature request for new functionality. No current way exists to implement DDL triggers in MySQL.

Suggested fix:
-- 1. Add new database configuration parameter
SET GLOBAL enable_ddl_tracking = ON;

-- 2. Create system table for tracking
CREATE TABLE database_ddl_changes (
    id INT AUTO_INCREMENT PRIMARY KEY,
    table_name VARCHAR(64),
    action_type VARCHAR(10),
    change_details JSON,
    changed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    changed_by VARCHAR(100)
);

-- 3. Enable DDL trigger support
CREATE TRIGGER track_ddl_changes
AFTER DDL ON DATABASE
FOR EACH EVENT
BEGIN
    INSERT INTO database_ddl_changes (
        table_name,
        action_type,
        change_details,
        changed_by
    )
    VALUES (
        OBJECT_NAME,
        DDL_TYPE,
        DDL_DETAILS,
        CURRENT_USER()
    );
END;

-- Technical Benefits:
-- 1. Native Version Control:
--    - No need for external tools like Liquibase/Flyway
--    - Automatic tracking without developer intervention
--    - Real-time capture of all structural changes

-- 2. Security & Compliance:
--    - Track who made what changes and when
--    - Audit trail for database structure changes
--    - Helps meet regulatory requirements (SOX, GDPR, etc.)

-- 3. Development Benefits:
--    - Debug structural issues easily
--    - Track changes across environments
--    - Automatic documentation of database evolution
--    - Simplifies database migration processes

-- 4. Performance Considerations:
--    - Minimal overhead (only on DDL operations)
--    - Configurable (can be disabled if needed)
--    - Async logging possible for better performance

-- 5. Business Value:
--    - Reduced development costs
--    - Better change management
--    - Improved debugging capabilities
--    - Enhanced compliance reporting

-- Why this change hasn't been implemented yet?
-- 1. Performance concerns with DDL operations
-- 2. Complexity in implementation across different storage engines
-- 3. Historical focus on DML triggers only
-- 4. Backward compatibility considerations

-- However, modern databases need this feature because:
-- 1. Microservices architectures require better tracking
-- 2. DevOps practices need automated documentation
-- 3. Compliance requirements are stricter
-- 4. Development teams are larger and more distributed

-- Similar Features in Other Databases:
-- 1. PostgreSQL: Event Triggers
-- 2. Oracle: DDL Triggers
-- 3. SQL Server: DDL Triggers
-- MySQL is falling behind in this aspect

-- Implementation Priority:
-- HIGH - This feature would benefit many MySQL users
-- and reduce dependency on external tools
[27 Mar 6:38] MySQL Verification Team
Hello Luis Calabro,

Thank you for the feature request!

regards,
Umesh