Skip to content

Commit 1d12348

Browse files
authored
Create tableGrowthAnalysis.js
Script to assess the given table growth in the instance
1 parent 81ef846 commit 1d12348

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// === TABLE SIZE ANALYSIS SCRIPT ===
2+
// Log the start of the analysis
3+
gs.info('=== TABLE SIZE ANALYSIS ===');
4+
5+
// Define the list of tables to analyze
6+
var tablesToCheck = ['task', 'cmdb_ci', 'sc_cat_item'];
7+
8+
// Loop through each table in the list
9+
for (var i = 0; i < tablesToCheck.length; i++) {
10+
var tableName = tablesToCheck[i]; // Get current table name
11+
12+
// Create a GlideAggregate object to count total records in the table
13+
var grCount = new GlideAggregate(tableName);
14+
grCount.addAggregate('COUNT'); // Add COUNT aggregate
15+
grCount.query(); // Execute the query
16+
17+
// If the query returns a result
18+
if (grCount.next()) {
19+
var recordCount = grCount.getAggregate('COUNT'); // Get total record count
20+
gs.info('Table: ' + tableName + ' | Record count: ' + recordCount); // Log the count
21+
22+
// Optional: Analyze growth by checking records created in the last 30 days
23+
var grRecent = new GlideAggregate(tableName);
24+
grRecent.addAggregate('COUNT'); // Add COUNT aggregate
25+
grRecent.addQuery('sys_created_on', '>=', gs.daysAgo(30)); // Filter records created in last 30 days
26+
grRecent.query(); // Execute the query
27+
28+
// If the query returns a result
29+
if (grRecent.next()) {
30+
var recentCount = grRecent.getAggregate('COUNT'); // Get count of recent records
31+
gs.info(' - Records created last 30 days: ' + recentCount); // Log the recent count
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)