mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-17 17:23:48 -05:00
Enabling FILEGROUPS tab experience to the Database Properties (#2182)
* sending dsc values to ADS * modifying dsc method with unsupportable property IsValuedefault * getting the options and added a bool flag to maintian checkbox for secondary to save * sending data to ads * Ready for PR with minimal changes of loading UI as expected, TODO:saving logic * Excluding maxdop and resumable options from primary value conversion for 1/0's * Adding Id to the info, as we cannot depend on names, as names can be altered in future * saving successfully, todo-diff servers, script (secondary - primary compare and dont update),test, send null for unsupported * adding nullable dsc for unsupported servers * fixing script generation for some properties that are not touched. the generated script is unharmed but unnecessary here * adding test conditions for database scoped configurations * adding switch case method to get the values * Removing Loc string for the TSQL options * removing unnecessary using statement * sending required data, verify autogrowth... * using fullTextIndexing to open the files tab for sql server and not to other servers * Adding test case and fixing createDatabase issue * sending files as objecinfo * Update src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype130.cs Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * comment update * preparing filegroup and filetype options * sending required all fields * saving file code changes, need more to work * Saving file is completed, todo:edit & remove * Logic to remove the file * add,edit,save working * cleaning merge conflicts accidentally added code * Adding tests to validates Files by adding, removing, updating files * adding comments * all working including tests, except fileStream size question * code review comments updates * memoryoptimized filegroups should be part of filestream group * Initial commit * failing tests fix * Modify tests by create database using SqlTestDb * Modify tests by create database using SqlTestDb * Update src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Database/DatabaseHandler.cs Co-authored-by: Cory Rivera <corivera@microsoft.com> * preparing filegroup data to model * fixing test * commenting remove file testing as failing pipeline but passing locally * saving filegroups * using enum for type * trying to fix the test in server, removed the complaining file from test * all working but saving needs condition for filestream types * removing fulltext param and test fix * saving filegroups completed, need tests * fixing the path.. * adding test for Filegroups * test fix * fixing filegroups as filestream is not enabled on test server * missing conflict resolving * cleaning unused method * Code review updates for both filegroups and files logic --------- Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> Co-authored-by: Cory Rivera <corivera@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
1f045ba669
commit
c73ab55055
@@ -22,6 +22,7 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using NUnit.Framework;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Admin.AzureSqlDbHelper;
|
||||
using DatabaseFile = Microsoft.SqlTools.ServiceLayer.ObjectManagement.DatabaseFile;
|
||||
using FileGroup = Microsoft.SqlServer.Management.Smo.FileGroup;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
||||
{
|
||||
@@ -305,10 +306,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).PageVerify, Is.EqualTo(testDatabase.PageVerify), $"PageVerify should match with testdata");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).RestrictAccess, Is.EqualTo(testDatabase.RestrictAccess), $"RestrictAccess should match with testdata");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).DatabaseScopedConfigurations, Is.Not.Null, $"DatabaseScopedConfigurations is not null");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).DatabaseScopedConfigurations.Count, Is.GreaterThan(0), $"DatabaseScopedConfigurations should have at least a+ few properties");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).DatabaseScopedConfigurations?.Length, Is.GreaterThan(0), $"DatabaseScopedConfigurations should have at least a+ few properties");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).Files.Count, Is.EqualTo(2), $"Create database should create two database files");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).Files[0].Type, Is.EqualTo("ROWS Data"), $"Database files first file should be Row type database files");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).Files[1].Type, Is.EqualTo("LOG"), $"Database files first file should be Log type database files");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).Filegroups?.Length, Is.GreaterThan(0), $"Database file groups should exists");
|
||||
|
||||
// cleanup
|
||||
await ObjectManagementTestUtils.DropObject(connectionResult.ConnectionInfo.OwnerUri, objUrn, throwIfNotExist: true);
|
||||
@@ -438,6 +440,71 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adding, modifying and deleting database filegroups
|
||||
/// /// </summary>
|
||||
/// <returns></returns>
|
||||
[Test]
|
||||
public async Task VerifyDatabaseFileGroupsTest()
|
||||
{
|
||||
using (var testDatabase = await SqlTestDb.CreateNewAsync(serverType: TestServerType.OnPrem, dbNamePrefix: "VerifyDatabaseFilegeoupsTest"))
|
||||
{
|
||||
var connectionResult = LiveConnectionHelper.InitLiveConnectionInfo(testDatabase.DatabaseName);
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connectionResult.ConnectionInfo))
|
||||
{
|
||||
var testDatabaseInfo = ObjectManagementTestUtils.GetTestDatabaseInfo();
|
||||
testDatabaseInfo.Name = testDatabase.DatabaseName;
|
||||
testDatabaseInfo.CollationName = "";
|
||||
var objUrn = ObjectManagementTestUtils.GetDatabaseURN(testDatabase.DatabaseName);
|
||||
|
||||
// Get database properties and verify
|
||||
var parametersForUpdate = ObjectManagementTestUtils.GetInitializeViewRequestParams(connectionResult.ConnectionInfo.OwnerUri, testDatabase.DatabaseName, false, SqlObjectType.Database, "", objUrn);
|
||||
DatabaseViewInfo databaseViewInfo = await ObjectManagementTestUtils.GetDatabaseObject(parametersForUpdate, testDatabaseInfo);
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).Filegroups?.Length, Is.EqualTo(1), $"Create database should create one default database filegroup");
|
||||
Assert.That(((DatabaseInfo)databaseViewInfo.ObjectInfo).Filegroups[0].Name, Is.EqualTo("PRIMARY"), $"Database default filegroup name should be PRIMARY");
|
||||
|
||||
List<FileGroupSummary> databaseFilegroup = new List<FileGroupSummary>();
|
||||
|
||||
// copy exisitng Row data files to the list
|
||||
databaseFilegroup.Add(((DatabaseInfo)databaseViewInfo.ObjectInfo).Filegroups[0]);
|
||||
|
||||
// Add new Filegroups
|
||||
var testDatabaseFilegroups = ObjectManagementTestUtils.GetTestDatabaseFilegroups();
|
||||
databaseFilegroup.AddRange(testDatabaseFilegroups);
|
||||
|
||||
// Attaching the filegroups to the testdatabase
|
||||
testDatabaseInfo.Filegroups = databaseFilegroup.ToArray();
|
||||
|
||||
// Validate the result
|
||||
await ObjectManagementTestUtils.SaveObject(parametersForUpdate, testDatabaseInfo);
|
||||
DatabaseViewInfo updatedDatabaseViewInfo = await ObjectManagementTestUtils.GetDatabaseObject(parametersForUpdate, testDatabaseInfo);
|
||||
|
||||
// verify the modified properties
|
||||
Assert.That(((DatabaseInfo)updatedDatabaseViewInfo.ObjectInfo).Filegroups?.Length, Is.EqualTo(3), $"Four filegroups should exists, as we created three more");
|
||||
var filegroup = ((DatabaseInfo)updatedDatabaseViewInfo.ObjectInfo).Filegroups.FirstOrDefault(x => x.Name == databaseFilegroup[1].Name);
|
||||
Assert.That(filegroup, Is.Not.Null, $"filegroup should exists");
|
||||
Assert.That(filegroup.Type, Is.EqualTo(FileGroupType.RowsFileGroup), $"Filegroup type should be matched");
|
||||
|
||||
filegroup = ((DatabaseInfo)updatedDatabaseViewInfo.ObjectInfo).Filegroups.FirstOrDefault(x => x.Name == databaseFilegroup[2].Name);
|
||||
Assert.That(filegroup, Is.Not.Null, $"filegroup should exists");
|
||||
Assert.That(filegroup.Type, Is.EqualTo(FileGroupType.MemoryOptimizedDataFileGroup), $"Filegroup type should be matched");
|
||||
|
||||
// Deleting newly created file
|
||||
List<FileGroupSummary> newfilegroups = ((DatabaseInfo)updatedDatabaseViewInfo.ObjectInfo).Filegroups.ToList();
|
||||
var fileIndexTobeRemoved = newfilegroups.FindIndex(x => x.Name == databaseFilegroup[1].Name);
|
||||
newfilegroups.RemoveAt(fileIndexTobeRemoved);
|
||||
testDatabaseInfo.Filegroups = newfilegroups.ToArray();
|
||||
|
||||
// Validate the result files
|
||||
await ObjectManagementTestUtils.SaveObject(parametersForUpdate, testDatabaseInfo);
|
||||
DatabaseViewInfo databaseViewInfoAfterFileDelete = await ObjectManagementTestUtils.GetDatabaseObject(parametersForUpdate, testDatabaseInfo);
|
||||
Assert.That(((DatabaseInfo)databaseViewInfoAfterFileDelete.ObjectInfo).Filegroups.Count, Is.EqualTo(2), $"Should have only 3 filegroups as we removed one");
|
||||
filegroup = ((DatabaseInfo)databaseViewInfoAfterFileDelete.ObjectInfo).Filegroups.FirstOrDefault(x => x.Name == databaseFilegroup[1].Name);
|
||||
Assert.That(filegroup, Is.Null, $"filegroup should exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task DetachDatabaseTest()
|
||||
|
||||
@@ -127,7 +127,28 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
||||
return databaseFiles.ToArray();
|
||||
}
|
||||
|
||||
internal static UserInfo GetTestUserInfo(DatabaseUserType userType, string userName = null, string loginName = null)
|
||||
internal static List<FileGroupSummary> GetTestDatabaseFilegroups()
|
||||
{
|
||||
List<FileGroupSummary> fgs = new List<FileGroupSummary>();
|
||||
fgs.Add(new FileGroupSummary()
|
||||
{
|
||||
Id = -1,
|
||||
Name = "rowFilegroup1",
|
||||
IsDefault = false,
|
||||
IsReadOnly = false,
|
||||
AutogrowAllFiles = true,
|
||||
Type = FileGroupType.RowsFileGroup
|
||||
});
|
||||
fgs.Add(new FileGroupSummary()
|
||||
{
|
||||
Id = -2,
|
||||
Name = "memOptFg1",
|
||||
Type = FileGroupType.MemoryOptimizedDataFileGroup
|
||||
});
|
||||
return fgs;
|
||||
}
|
||||
|
||||
internal static UserInfo GetTestUserInfo(DatabaseUserType userType, string userName = null, string loginName = null)
|
||||
{
|
||||
return new UserInfo()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user