feat(etl): add CommonScripts factory for index and statistics scripts
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using JdeScoping.DataAccess.Interfaces;
|
||||
using JdeScoping.DataSync.Etl.Contracts;
|
||||
|
||||
namespace JdeScoping.DataSync.Etl.Scripts;
|
||||
|
||||
public static class CommonScripts
|
||||
{
|
||||
public static IScriptRunner DisableIndexes(IDbConnectionFactory factory, string tableName)
|
||||
{
|
||||
var sql = $@"
|
||||
DECLARE @sql NVARCHAR(MAX) = '';
|
||||
SELECT @sql = @sql + 'ALTER INDEX [' + i.name + '] ON [{tableName}] DISABLE;' + CHAR(13)
|
||||
FROM sys.indexes i
|
||||
INNER JOIN sys.tables t ON i.object_id = t.object_id
|
||||
WHERE t.name = '{tableName}'
|
||||
AND i.type = 2
|
||||
AND i.is_disabled = 0;
|
||||
IF LEN(@sql) > 0 EXEC sp_executesql @sql;";
|
||||
|
||||
return new SqlScriptRunner(factory, sql, $"DisableIndexes:{tableName}", timeoutSeconds: 300);
|
||||
}
|
||||
|
||||
public static IScriptRunner RebuildIndexes(IDbConnectionFactory factory, string tableName)
|
||||
{
|
||||
var sql = $"ALTER INDEX ALL ON [{tableName}] REBUILD WITH (FILLFACTOR = 95)";
|
||||
return new SqlScriptRunner(factory, sql, $"RebuildIndexes:{tableName}", timeoutSeconds: 3600);
|
||||
}
|
||||
|
||||
public static IScriptRunner UpdateStatistics(IDbConnectionFactory factory, string tableName)
|
||||
{
|
||||
var sql = $"UPDATE STATISTICS [{tableName}]";
|
||||
return new SqlScriptRunner(factory, sql, $"UpdateStats:{tableName}", timeoutSeconds: 600);
|
||||
}
|
||||
|
||||
public static IScriptRunner CustomSql(IDbConnectionFactory factory, string sql, string name)
|
||||
{
|
||||
return new SqlScriptRunner(factory, sql, name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user