I Created a Custom Macro on Toad Data Modeler, Version 8.0
This macro is suppose to generate Audit tables for all the entities I have in the Model, when I run the macro it does nothing. Any help on this will be greatly appreciated.
Here is my Macro
function main() {
var App = System.GetInterface("Application");
var Model = App.ActiveModel;
var WS = App.ActiveWorkSpace;
var Log = System.CreateObject("Log");
Log.Information("Audit tables created for all tables.");
if (Model == null)
return;
for (var i = 0; i < Model.Tables.Count; i++) {
var origTable = Model.Tables.GetObject(i);
var auditTableName = origTable.Name + "_AUDIT";
// Skip if audit table already exists
if (Model.Tables.GetObjectByName(auditTableName)) continue;
var auditTable = Model.Tables.CreateNew();
auditTable.Name = auditTableName;
auditTable.Caption = origTable.Caption + " Audit";
// Copy columns from original table
for (var j = 0; j < origTable.Columns.Count; j++) {
var col = origTable.Columns.GetObject(j);
var newCol = auditTable.CreateColumn();
newCol.Name = col.Name;
newCol.DataType = col.DataType;
newCol.Length = col.Length;
newCol.Precision = col.Precision;
newCol.Scale = col.Scale;
newCol.Mandatory = false; // Set to nullable for audit
}
// Add audit columns
var auditId = auditTable.CreateColumn();
auditId.Name = "audit_id";
auditId.DataType = "NUMBER";
auditId.Mandatory = true;
var auditDts = auditTable.CreateColumn();
auditDts.Name = "audit_dts";
auditDts.DataType = "TIMESTAMP";
auditDts.Mandatory = true;
var auditOp = auditTable.CreateColumn();
auditOp.Name = "audit_op";
auditOp.DataType = "CHAR";
auditOp.Length = 20;
auditOp.Mandatory = true;
var auditUser = auditTable.CreateColumn();
auditUser.Name = "audit_user";
auditUser.DataType = "VARCHAR2";
auditUser.Length = 20;
auditUser.Mandatory = true;
// Add the new audit table to the model
Model.Tables.Add(auditTable);
}
}