Skip to content

Commit

Permalink
Adding schema diagram api. (#2435)
Browse files Browse the repository at this point in the history
* Adding schema designer files

* More fixes

* Fixing code

* Fixing contracts

* Cleaning up code

* cleaning up code

* Fixing query

* Fixing database for connection

* removing unused file

* Fixing typo

* Making some PR fixes

* reordering enum

* Fixing comments
  • Loading branch information
aasimkhan30 authored Jan 15, 2025
1 parent 339caad commit 6bd525b
Show file tree
Hide file tree
Showing 7 changed files with 518 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/HostLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
using Microsoft.SqlTools.ServiceLayer.QueryStore;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare;
using Microsoft.SqlTools.ServiceLayer.SchemaDesigner;
using Microsoft.SqlTools.ServiceLayer.Scripting;
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
using Microsoft.SqlTools.ServiceLayer.SqlAssessment;
Expand Down Expand Up @@ -179,6 +180,9 @@ private static void InitializeRequestHandlersAndServices(ServiceHost serviceHost
QueryStoreService.Instance.InitializeService(serviceHost);
serviceProvider.RegisterSingleService(QueryStoreService.Instance);

SchemaDesignerService.Instance.InitializeService(serviceHost);
serviceProvider.RegisterSingleService(SchemaDesignerService.Instance);

serviceHost.InitializeRequestHandlers();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// 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.SchemaDesigner
{
/// <summary>
/// Represents a column in an entity
/// </summary>
public class Column
{
/// <summary>
/// Gets or sets the name of the column
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets the data type of the column
/// </summary>
public string DataType { get; set; }
/// <summary>
/// Gets or sets if the column is a primary key
/// </summary>
public bool IsPrimaryKey { get; set; }
/// <summary>
/// Gets or sets if the column is an identity column
/// </summary>
public bool IsIdentity { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System.Collections.Generic;

namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
{
public class Entity
{
public string Name { get; set; }
public string Schema { get; set; }
public List<Column> Columns { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// 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;

namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
{
public class GetSchemaModelRequestParams
{
/// <summary>
/// URI identifying the connection to perform the action on. Generally the connection is picked from an existing OE connection.
/// </summary>
public string ConnectionUri { get; set; }
/// <summary>
/// Gets or sets the name of the database. Database name is required to get the schema model for the database.
/// </summary>
public string DatabaseName { get; set; }
}
/// <summary>
/// Request to get the schema model
/// </summary>
public class GetSchemaModelRequest
{
public static readonly
RequestType<GetSchemaModelRequestParams, SchemaModel> Type =
RequestType<GetSchemaModelRequestParams, SchemaModel>.Create("schemaDesigner/getSchemaModel");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// 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.SchemaDesigner
{
public class Relationship
{
/// <summary>
/// Gets or sets the name of the foreign key
/// </summary>
public string ForeignKeyName { get; set; }
/// <summary>
/// Gets or sets the schema name
/// </summary>
public string SchemaName { get; set; }
/// <summary>
/// Gets or sets the parent entity (Table in MSSQL) name.
/// </summary>
public string Entity { get; set; }
/// <summary>
/// Gets or sets the parent column
/// </summary>
public string Column { get; set; }
/// <summary>
/// Gets or sets the referenced schema
/// </summary>
public string ReferencedSchema { get; set; }
/// <summary>
/// Gets or sets the referenced entity (Table in MSSQL) name.
/// </summary>
public string ReferencedEntity { get; set; }
/// <summary>
/// Gets or sets the referenced column
/// </summary>
public string ReferencedColumn { get; set; }
/// <summary>
/// Gets or sets the delete cascade action. Default is NO_ACTION
/// </summary>
public OnAction OnDeleteAction { get; set; }
/// <summary>
/// Gets or sets the update cascade action. Default is NO_ACTION
/// </summary>
public OnAction OnUpdateAction { get; set; }
}

public enum OnAction
{
/// <summary>
/// No action. Do not allow the delete or update of the row from the parent table if there are matching rows in the child table.
/// </summary>
NO_ACTION = 0,
/// <summary>
/// Cascade action. Delete or update the row from the parent table and automatically delete or update the matching rows in the child table.
/// </summary>
CASCADE = 1,
/// <summary>
/// Set null action. Delete or update the row from the parent table and set the foreign key column or columns in the child table to NULL.
/// </summary>
SET_NULL = 2,
/// <summary>
/// Set default action. Delete or update the row from the parent table and set the foreign key column or columns in the child table to their default values.
/// </summary>
SET_DEFAULT = 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System.Collections.Generic;

namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
{
public class SchemaModel
{
/// <summary>
/// Gets or sets the entities (Table in MSSQL) in the schema
/// </summary>
public List<Entity> Entities { get; set; }
/// <summary>
/// Gets or sets the relationships in the schema
/// </summary>
public List<Relationship> Relationships { get; set; }
}
}
Loading

0 comments on commit 6bd525b

Please sign in to comment.