Skip to content

Commit cbac644

Browse files
authored
feat(file): size-growth (#104)
* feat/file/size-growth * feat(field): conversion factors * fix(review): consistency * feat(AgDb): MB consistency
1 parent e542fe8 commit cbac644

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/AgDatabase.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ void Restore(IEnumerable<BackupMetadata> backupOrder, Func<int, TimeSpan> retryD
4444
void AddRole(LoginProperties login, RoleProperties role);
4545
IEnumerable<RoleProperties> AssociatedRoles();
4646
void ContainsLogin(string loginName);
47+
void SetSizeLimit(int maxMB);
48+
void SetGrowthRate(int growthMB);
49+
void SetLogGrowthRate(int growthMB);
4750
}
4851

4952

@@ -294,6 +297,21 @@ public void MultiUserMode()
294297
_listener.Primary.Database(Name).MultiUserMode();
295298
}
296299

300+
public void SetSizeLimit(int maxMB)
301+
{
302+
_listener.Primary.Database(Name).SetSizeLimit(maxMB);
303+
}
304+
305+
public void SetGrowthRate(int growthMB)
306+
{
307+
_listener.Primary.Database(Name).SetGrowthRate(growthMB);
308+
}
309+
310+
public void SetLogGrowthRate(int growthMB)
311+
{
312+
_listener.Primary.Database(Name).SetLogGrowthRate(growthMB);
313+
}
314+
297315
public void CheckDBConnections(int connectionTimeout)
298316
{
299317
_listener.ForEachAgInstance(server => server.CheckDBConnection(Name, connectionTimeout));

src/SmoFacade/Database.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class Database
1414
{
1515
internal readonly Microsoft.SqlServer.Management.Smo.Database _database;
1616
private readonly Server _server;
17+
private const int MB_TO_KB = 1024;
1718

1819
internal Database(Microsoft.SqlServer.Management.Smo.Database database, Server server)
1920
{
@@ -237,6 +238,35 @@ public void MultiUserMode()
237238
_database.Alter(TerminationClause.RollbackTransactionsImmediately);
238239
}
239240

241+
public void SetSizeLimit(int maxMB)
242+
{
243+
var dataFile = _database.FileGroups[_database.DefaultFileGroup].Files.Cast<DataFile>()
244+
.Single(d => d.IsPrimaryFile);
245+
246+
dataFile.MaxSize = maxMB * MB_TO_KB;
247+
dataFile.Alter();
248+
}
249+
250+
public void SetGrowthRate(int growthMB)
251+
{
252+
var dataFile = _database.FileGroups[_database.DefaultFileGroup].Files.Cast<DataFile>()
253+
.Single(d => d.IsPrimaryFile);
254+
255+
dataFile.GrowthType = FileGrowthType.KB;
256+
dataFile.Growth = growthMB * MB_TO_KB;
257+
dataFile.Alter();
258+
}
259+
260+
public void SetLogGrowthRate(int growthMB)
261+
{
262+
foreach (var logFile in _database.LogFiles.Cast<LogFile>())
263+
{
264+
logFile.GrowthType = FileGrowthType.KB;
265+
logFile.Growth = growthMB * MB_TO_KB;
266+
logFile.Alter();
267+
}
268+
}
269+
240270
private void ThrowIfUnreadyToDrop()
241271
{
242272
// Deleting the database while it is initializing will leave it in a state where system redo threads are stuck.

0 commit comments

Comments
 (0)