Support for database references in SqlProjects service (#1832)

* initial checkin

* Initial

* Adding test

* Adding comments

* PR feedback
This commit is contained in:
Benjin Dubishar
2023-01-31 16:52:07 -08:00
committed by GitHub
parent 036ce9b527
commit 9fe3aeddc3
16 changed files with 289 additions and 10 deletions

View File

@@ -0,0 +1,32 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
/// <summary>
/// Parameters for adding a Dacpac reference to a SQL project
/// </summary>
public class AddDacpacReferenceParams : AddDatabaseReferenceParams
{
/// <summary>
/// Path to the .dacpac file
/// </summary>
public string DacpacPath { get; set; }
/// <summary>
/// SQLCMD variable name for specifying the other server this reference is to, if different from that of the current project.
/// If this is set, DatabaseVariable must also be set.
/// </summary>
public string? ServerVariable { get; set; }
}
public class AddDacpacReferenceRequest
{
public static readonly RequestType<AddDacpacReferenceParams, ResultStatus> Type = RequestType<AddDacpacReferenceParams, ResultStatus>.Create("sqlprojects/addDacpacReference");
}
}

View File

@@ -0,0 +1,23 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
/// <summary>
/// Base class for add database reference request paramaters
/// </summary>
public abstract class AddDatabaseReferenceParams : SqlProjectParams
{
/// <summary>
/// Whether to suppress missing dependencies
/// </summary>
public bool SuppressMissingDependencies { get; set; }
/// <summary>
/// SQLCMD variable name for specifying the other database this reference is to, if different from that of the current project
/// </summary>
public string? DatabaseVariable { get; set; }
}
}

View File

@@ -0,0 +1,38 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
/// <summary>
/// Parameters for adding a reference to another SQL project
/// </summary>
public class AddSqlProjectReferenceParams : AddDatabaseReferenceParams
{
/// <summary>
/// Path to the referenced .sqlproj file
/// </summary>
public string ProjectPath { get; set; }
/// <summary>
/// GUID for the referenced SQL project
/// </summary>
public string? ProjectGuid { get; set; }
/// <summary>
/// SQLCMD variable name for specifying the other server this reference is to, if different from that of the current project.
/// If this is set, DatabaseVariable must also be set.
/// </summary>
public string? ServerVariable { get; set; }
}
public class AddSqlProjectReferenceRequest
{
public static readonly RequestType<AddSqlProjectReferenceParams, ResultStatus> Type = RequestType<AddSqlProjectReferenceParams, ResultStatus>.Create("sqlprojects/addSqlProjectReference");
}
}

View File

@@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlServer.Dac.Projects;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
/// <summary>
/// Parameters for adding a reference to a system database
/// </summary>
public class AddSystemDatabaseReferenceParams : AddDatabaseReferenceParams
{
/// <summary>
/// Type of system database
/// </summary>
public SystemDatabase SystemDatabase { get; set; }
}
public class AddSystemDatabaseReferenceRequest
{
public static readonly RequestType<SqlProjectScriptParams, ResultStatus> Type = RequestType<SqlProjectScriptParams, ResultStatus>.Create("sqlprojects/addSystemDatabaseReference");
}
}

View File

@@ -0,0 +1,26 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
/// <summary>
/// Parameters for deleting a database reference
/// </summary>
public class DeleteDatabaseReferenceParams : SqlProjectParams
{
/// <summary>
/// Name of the reference to be deleted. Name of the System DB, path of the sqlproj, or path of the dacpac
/// </summary>
public string Name { get; set; }
}
public class DeleteDatabaseReferenceRequest
{
public static readonly RequestType<SqlProjectScriptParams, ResultStatus> Type = RequestType<SqlProjectScriptParams, ResultStatus>.Create("sqlprojects/deleteDatabaseReference");
}
}

View File

@@ -10,6 +10,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
public class CloseSqlProjectRequest
{
public static readonly RequestType<SqlProjectParams, ResultStatus> Type = RequestType<SqlProjectParams, ResultStatus>.Create("sqlprojects/closeProject");
public static readonly RequestType<SqlProjectParams, ResultStatus> Type = RequestType<SqlProjectParams, ResultStatus>.Create("sqlProjects/closeProject");
}
}

View File

@@ -34,6 +34,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
public class NewSqlProjectRequest
{
public static readonly RequestType<NewSqlProjectParams, ResultStatus> Type = RequestType<NewSqlProjectParams, ResultStatus>.Create("sqlprojects/newProject");
public static readonly RequestType<NewSqlProjectParams, ResultStatus> Type = RequestType<NewSqlProjectParams, ResultStatus>.Create("sqlProjects/newProject");
}
}

View File

@@ -10,6 +10,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
public class OpenSqlProjectRequest
{
public static readonly RequestType<SqlProjectParams, ResultStatus> Type = RequestType<SqlProjectParams, ResultStatus>.Create("sqlprojects/openProject");
public static readonly RequestType<SqlProjectParams, ResultStatus> Type = RequestType<SqlProjectParams, ResultStatus>.Create("sqlProjects/openProject");
}
}

View File

@@ -31,6 +31,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
public class AddSqlCmdVariableRequest
{
public static readonly RequestType<AddSqlCmdVariableParams, ResultStatus> Type = RequestType<AddSqlCmdVariableParams, ResultStatus>.Create("sqlprojects/addSqlCmdVariable");
public static readonly RequestType<AddSqlCmdVariableParams, ResultStatus> Type = RequestType<AddSqlCmdVariableParams, ResultStatus>.Create("sqlProjects/addSqlCmdVariable");
}
}

View File

@@ -21,6 +21,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
public class DeleteSqlCmdVariableRequest
{
public static readonly RequestType<DeleteSqlCmdVariableParams, ResultStatus> Type = RequestType<DeleteSqlCmdVariableParams, ResultStatus>.Create("sqlprojects/deleteSqlCmdVariable");
public static readonly RequestType<DeleteSqlCmdVariableParams, ResultStatus> Type = RequestType<DeleteSqlCmdVariableParams, ResultStatus>.Create("sqlProjects/deleteSqlCmdVariable");
}
}

View File

@@ -10,6 +10,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
public class UpdateSqlCmdVariableRequest
{
public static readonly RequestType<AddSqlCmdVariableParams, ResultStatus> Type = RequestType<AddSqlCmdVariableParams, ResultStatus>.Create("sqlprojects/updateSqlCmdVariable");
public static readonly RequestType<AddSqlCmdVariableParams, ResultStatus> Type = RequestType<AddSqlCmdVariableParams, ResultStatus>.Create("sqlProjects/updateSqlCmdVariable");
}
}

View File

@@ -10,6 +10,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
public class AddSqlObjectScriptRequest
{
public static readonly RequestType<SqlProjectScriptParams, ResultStatus> Type = RequestType<SqlProjectScriptParams, ResultStatus>.Create("sqlprojects/addSqlObjectScript");
public static readonly RequestType<SqlProjectScriptParams, ResultStatus> Type = RequestType<SqlProjectScriptParams, ResultStatus>.Create("sqlProjects/addSqlObjectScript");
}
}

View File

@@ -10,6 +10,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
public class DeleteSqlObjectScriptRequest
{
public static readonly RequestType<SqlProjectScriptParams, ResultStatus> Type = RequestType<SqlProjectScriptParams, ResultStatus>.Create("sqlprojects/deleteSqlObjectScript");
public static readonly RequestType<SqlProjectScriptParams, ResultStatus> Type = RequestType<SqlProjectScriptParams, ResultStatus>.Create("sqlProjects/deleteSqlObjectScript");
}
}

View File

@@ -10,6 +10,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
{
public class ExcludeSqlObjectScriptRequest
{
public static readonly RequestType<SqlProjectScriptParams, ResultStatus> Type = RequestType<SqlProjectScriptParams, ResultStatus>.Create("sqlprojects/excludeSqlObjectScript");
public static readonly RequestType<SqlProjectScriptParams, ResultStatus> Type = RequestType<SqlProjectScriptParams, ResultStatus>.Create("sqlProjects/excludeSqlObjectScript");
}
}

View File

@@ -99,6 +99,48 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects
#endregion
#region Database Reference calls
internal async Task HandleAddSystemDatabaseReferenceRequest(AddSystemDatabaseReferenceParams requestParams, RequestContext<ResultStatus> requestContext)
{
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).DatabaseReferences.Add(
new SystemDatabaseReference(
requestParams.SystemDatabase,
requestParams.SuppressMissingDependencies,
requestParams.DatabaseVariable)),
requestContext);
}
internal async Task HandleAddDacpacReferenceRequest(AddDacpacReferenceParams requestParams, RequestContext<ResultStatus> requestContext)
{
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).DatabaseReferences.Add(
new DacpacReference(
requestParams.DacpacPath,
requestParams.SuppressMissingDependencies,
requestParams.DatabaseVariable,
requestParams.ServerVariable)),
requestContext);
}
internal async Task HandleAddSqlProjectReferenceRequest(AddSqlProjectReferenceParams requestParams, RequestContext<ResultStatus> requestContext)
{
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).DatabaseReferences.Add(
new SqlProjectReference(
requestParams.ProjectPath,
requestParams.ProjectGuid,
requestParams.SuppressMissingDependencies,
requestParams.DatabaseVariable,
requestParams.ServerVariable)),
requestContext);
}
internal async Task HandleDeleteDatabaseReferenceRequest(DeleteDatabaseReferenceParams requestParams, RequestContext<ResultStatus> requestContext)
{
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).DatabaseReferences.Delete(requestParams.Name), requestContext);
}
#endregion
#region SQLCMD variable functions
internal async Task HandleAddSqlCmdVariableRequest(AddSqlCmdVariableParams requestParams, RequestContext<ResultStatus> requestContext)