Skip to content

Commit 31a9f6f

Browse files
authored
Fixing update script for schema (#2463)
* Add DefaultValue property to SchemaDesignerColumn and update related logic * Refactor SchemaDesigner session handling and update method calls for clarity * Improve session disposal handling and validate connection in SchemaDesignerSession constructor * Refactor SchemaDesigner session handling and improve report generation logic * Update DacFx package version to 170.0.81 and comment out unused code in SqlProjectsService * Adding ref to latest sql proj nuget to get rid of compile errors * Fix handling of NULL default values in SchemaDesignerModelProvider * wip sd * Implement enhancements to improve performance in data processing * Remove UpdateScript property from SchemaDesignerReportObject * Rename SchemaDesignerReportObject to SchemaDesignerChangeReport and update references in GetReportResponse * Refactor SchemaDesigner: remove EventSchemaReady, update column types, and streamline session handling * Sort available schemas and data types for improved organization * Remove obsolete NuGet packages: Microsoft.SqlServer.DacFx, Microsoft.SqlServer.DacFx.Projects, and Microsoft.SqlServer.DacFx.Tools * Refactor SqlProjectsService: update CreateSqlProjectParams and TargetPlatform utility references * Refactor SchemaDesignerSession: simplify schema designer initialization logic
1 parent 4d999fd commit 31a9f6f

File tree

10 files changed

+655
-660
lines changed

10 files changed

+655
-660
lines changed

src/Microsoft.SqlTools.ServiceLayer/SchemaDesigner/Contracts/EventSchemaReady.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Microsoft.SqlTools.ServiceLayer/SchemaDesigner/Contracts/RequestGetReport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class GetReportRequest
2525
/// </summary>
2626
public class GetReportResponse
2727
{
28-
public List<SchemaDesignerReportObject>? Reports { get; set; }
28+
public List<SchemaDesignerChangeReport>? Reports { get; set; }
2929
public string? UpdateScript { get; set; }
3030
}
3131

src/Microsoft.SqlTools.ServiceLayer/SchemaDesigner/Contracts/SchemaDesignerColumn.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SchemaDesignerColumn
2727
/// <summary>
2828
/// Gets or sets the max length of the column
2929
/// </summary>
30-
public int? MaxLength { get; set; }
30+
public string? MaxLength { get; set; }
3131
/// <summary>
3232
/// Gets or sets the precision of the column
3333
/// </summary>
@@ -47,22 +47,18 @@ public class SchemaDesignerColumn
4747
/// <summary>
4848
/// Gets or sets identity seed of the column
4949
/// </summary>
50-
public int? IdentitySeed { get; set; }
50+
public decimal? IdentitySeed { get; set; }
5151
/// <summary>
5252
/// Gets or sets identity increment of the column
5353
/// </summary>
54-
public int? IdentityIncrement { get; set; }
54+
public decimal? IdentityIncrement { get; set; }
5555
/// <summary>
5656
/// Gets or sets if the column is a nullable column
5757
/// </summary>
5858
public bool IsNullable { get; set; }
5959
/// <summary>
60-
/// Get or sets if the column is has unique constraint
61-
/// </summary>
62-
public bool IsUnique { get; set; }
63-
/// <summary>
6460
/// Gets or sets the default value of the column
6561
/// </summary>
66-
public string Collation { get; set; }
62+
public string? DefaultValue { get; set; }
6763
}
6864
}

src/Microsoft.SqlTools.ServiceLayer/SchemaDesigner/Contracts/SchemaDesignerReportObject.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
namespace Microsoft.SqlTools.ServiceLayer.SchemaDesigner
1010
{
11-
public class SchemaDesignerReportObject
11+
public class SchemaDesignerChangeReport
1212
{
1313
public Guid? TableId { get; set; }
1414
public string TableName { get; set; } = string.Empty;
15-
public string UpdateScript { get; set; } = string.Empty;
1615
public SchemaDesignerReportTableState TableState { get; set; } = SchemaDesignerReportTableState.CREATED;
1716
public List<string> ActionsPerformed { get; set; } = new List<string>();
1817
}

src/Microsoft.SqlTools.ServiceLayer/SchemaDesigner/SchemaDesignerModelProvider.cs

Lines changed: 0 additions & 229 deletions
This file was deleted.

src/Microsoft.SqlTools.ServiceLayer/SchemaDesigner/SchemaDesignerScriptGenerator.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,9 @@ public static string GenerateColumnDefinition(SchemaDesignerColumn column)
105105
StringBuilder sb = new StringBuilder();
106106
sb.Append($"[{column.Name}] {column.DataType}");
107107

108-
// Handle length specification for applicable data types
109-
if (column.MaxLength.HasValue && column.MaxLength != -1)
108+
if (column.MaxLength != null && column.MaxLength == "0")
110109
{
111-
if (IsLengthBasedType(column.DataType))
112-
{
113-
if (IsBytePairDatatype(column.DataType))
114-
{
115-
sb.Append($"({column.MaxLength / 2})");
116-
}
117-
else
118-
{
119-
sb.Append($"({column.MaxLength})");
120-
}
121-
}
122-
}
123-
else if (column.MaxLength == -1 && IsLengthBasedType(column.DataType))
124-
{
125-
sb.Append("(MAX)");
110+
sb.Append("(0)");
126111
}
127112

128113
// Handle precision and scale only for decimal/numeric types
@@ -138,22 +123,11 @@ public static string GenerateColumnDefinition(SchemaDesignerColumn column)
138123
}
139124
}
140125

141-
if (!string.IsNullOrEmpty(column.Collation) && column.Collation != "NULL")
142-
{
143-
sb.Append($" COLLATE {column.Collation}");
144-
}
145-
146-
147126
if (!column.IsNullable)
148127
{
149128
sb.Append(" NOT NULL");
150129
}
151130

152-
if (column.IsUnique)
153-
{
154-
sb.Append(" UNIQUE");
155-
}
156-
157131
if (column.IsIdentity)
158132
{
159133
sb.Append($" IDENTITY({column.IdentitySeed},{column.IdentityIncrement})");

0 commit comments

Comments
 (0)