Add trigger for audit log #35
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces a comprehensive auditing system for database changes and enhances the script execution framework to support both DDL and trigger scripts. The most significant changes include the addition of an
AuditLogtable, new triggers for auditing changes in key tables, and updates to the script execution logic to handle triggers separately.Auditing System Enhancements:
AuditLogTable: Added a new tableAuditLogto store detailed records of data changes, including the operation type, affected table, primary key value, old and new values, and user ID responsible for the change. This table is designed to support auditing across multiple tables. (src/backend/sql/ddl/014_create_audit_log_table.sql, src/backend/sql/ddl/014_create_audit_log_table.sqlR1-R18)Triggers for Auditing:
Usertable to logINSERT,UPDATE, andDELETEoperations, capturing both old and new values where applicable. (src/backend/sql/trigger/001_user_audit.sql, src/backend/sql/trigger/001_user_audit.sqlR1-R141)UserSessiontable to track session-related changes. (src/backend/sql/trigger/002_user_session_audit.sql, src/backend/sql/trigger/002_user_session_audit.sqlR1-R131)ShippingAddresstable to audit changes to address records. (src/backend/sql/trigger/003_shipping_address_audit.sql, src/backend/sql/trigger/003_shipping_address_audit.sqlR1-R126)Script Execution Framework Updates:
Separation of DDL and Trigger Scripts: Updated the script execution logic to distinguish between DDL scripts (
ddl_scripts_dir) and trigger scripts (trigger_scripts_dir), allowing for independent execution. (src/backend/scripts/reset.py, [1];src/backend/scripts/run_all_ddls.py, [2]New Flags for Script Execution:
--no-ddland--no-triggerflags to themainfunction, enabling selective execution of DDL and trigger scripts. (src/backend/scripts/run_all_ddls.py, [1] [2] [3]Improved Script Handling:
execute_sql_scriptfunction to support optional splitting of SQL statements, which is useful for handling trigger scripts that require execution as a single block. (src/backend/scripts/run_all_ddls.py, src/backend/scripts/run_all_ddls.pyL12-R49)src/backend/scripts/run_all_ddls.py, [1] [2]