Skip to content

Commit 6bd525b

Browse files
authored
Adding schema diagram api. (#2435)
* 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
1 parent 339caad commit 6bd525b

File tree

7 files changed

+518
-0
lines changed

7 files changed

+518
-0
lines changed

src/Microsoft.SqlTools.ServiceLayer/HostLoader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
3535
using Microsoft.SqlTools.ServiceLayer.QueryStore;
3636
using Microsoft.SqlTools.ServiceLayer.SchemaCompare;
37+
using Microsoft.SqlTools.ServiceLayer.SchemaDesigner;
3738
using Microsoft.SqlTools.ServiceLayer.Scripting;
3839
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
3940
using Microsoft.SqlTools.ServiceLayer.SqlAssessment;
@@ -179,6 +180,9 @@ private static void InitializeRequestHandlersAndServices(ServiceHost serviceHost
179180
QueryStoreService.Instance.InitializeService(serviceHost);
180181
serviceProvider.RegisterSingleService(QueryStoreService.Instance);
181182

183+
SchemaDesignerService.Instance.InitializeService(serviceHost);
184+
serviceProvider.RegisterSingleService(SchemaDesignerService.Instance);
185+
182186
serviceHost.InitializeRequestHandlers();
183187
}
184188

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
7+
{
8+
/// <summary>
9+
/// Represents a column in an entity
10+
/// </summary>
11+
public class Column
12+
{
13+
/// <summary>
14+
/// Gets or sets the name of the column
15+
/// </summary>
16+
public string Name { get; set; }
17+
/// <summary>
18+
/// Gets or sets the data type of the column
19+
/// </summary>
20+
public string DataType { get; set; }
21+
/// <summary>
22+
/// Gets or sets if the column is a primary key
23+
/// </summary>
24+
public bool IsPrimaryKey { get; set; }
25+
/// <summary>
26+
/// Gets or sets if the column is an identity column
27+
/// </summary>
28+
public bool IsIdentity { get; set; }
29+
}
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System.Collections.Generic;
7+
8+
namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
9+
{
10+
public class Entity
11+
{
12+
public string Name { get; set; }
13+
public string Schema { get; set; }
14+
public List<Column> Columns { get; set; }
15+
}
16+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
7+
8+
namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
9+
{
10+
public class GetSchemaModelRequestParams
11+
{
12+
/// <summary>
13+
/// URI identifying the connection to perform the action on. Generally the connection is picked from an existing OE connection.
14+
/// </summary>
15+
public string ConnectionUri { get; set; }
16+
/// <summary>
17+
/// Gets or sets the name of the database. Database name is required to get the schema model for the database.
18+
/// </summary>
19+
public string DatabaseName { get; set; }
20+
}
21+
/// <summary>
22+
/// Request to get the schema model
23+
/// </summary>
24+
public class GetSchemaModelRequest
25+
{
26+
public static readonly
27+
RequestType<GetSchemaModelRequestParams, SchemaModel> Type =
28+
RequestType<GetSchemaModelRequestParams, SchemaModel>.Create("schemaDesigner/getSchemaModel");
29+
}
30+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
7+
{
8+
public class Relationship
9+
{
10+
/// <summary>
11+
/// Gets or sets the name of the foreign key
12+
/// </summary>
13+
public string ForeignKeyName { get; set; }
14+
/// <summary>
15+
/// Gets or sets the schema name
16+
/// </summary>
17+
public string SchemaName { get; set; }
18+
/// <summary>
19+
/// Gets or sets the parent entity (Table in MSSQL) name.
20+
/// </summary>
21+
public string Entity { get; set; }
22+
/// <summary>
23+
/// Gets or sets the parent column
24+
/// </summary>
25+
public string Column { get; set; }
26+
/// <summary>
27+
/// Gets or sets the referenced schema
28+
/// </summary>
29+
public string ReferencedSchema { get; set; }
30+
/// <summary>
31+
/// Gets or sets the referenced entity (Table in MSSQL) name.
32+
/// </summary>
33+
public string ReferencedEntity { get; set; }
34+
/// <summary>
35+
/// Gets or sets the referenced column
36+
/// </summary>
37+
public string ReferencedColumn { get; set; }
38+
/// <summary>
39+
/// Gets or sets the delete cascade action. Default is NO_ACTION
40+
/// </summary>
41+
public OnAction OnDeleteAction { get; set; }
42+
/// <summary>
43+
/// Gets or sets the update cascade action. Default is NO_ACTION
44+
/// </summary>
45+
public OnAction OnUpdateAction { get; set; }
46+
}
47+
48+
public enum OnAction
49+
{
50+
/// <summary>
51+
/// 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.
52+
/// </summary>
53+
NO_ACTION = 0,
54+
/// <summary>
55+
/// Cascade action. Delete or update the row from the parent table and automatically delete or update the matching rows in the child table.
56+
/// </summary>
57+
CASCADE = 1,
58+
/// <summary>
59+
/// 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.
60+
/// </summary>
61+
SET_NULL = 2,
62+
/// <summary>
63+
/// 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.
64+
/// </summary>
65+
SET_DEFAULT = 3
66+
}
67+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System.Collections.Generic;
7+
8+
namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
9+
{
10+
public class SchemaModel
11+
{
12+
/// <summary>
13+
/// Gets or sets the entities (Table in MSSQL) in the schema
14+
/// </summary>
15+
public List<Entity> Entities { get; set; }
16+
/// <summary>
17+
/// Gets or sets the relationships in the schema
18+
/// </summary>
19+
public List<Relationship> Relationships { get; set; }
20+
}
21+
}

0 commit comments

Comments
 (0)