mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 17:24:21 -05:00
Support for database references in SqlProjects service (#1832)
* initial checkin * Initial * Adding test * Adding comments * PR feedback
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user