Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
Update this document for externally visible changes. Put most recent changes first.
Once we push a new version to nuget.org add a double hash header for that version.

## 180.10.0

- Change SMO collections to implement IEnumerator<T>
- Create a C# source generator to emit SMO collection class implementations
- Create a C# source generator to emit code that replaces reflection calls for finding collection and single properties on SqlSmoObject implementations
- Increment package major version to 180

## 172.87.0

- Add Json index support
- Add Vector index support
- Use vector_dimensions instead of max_length for Vector columns
- Support Order Clause for NonClustered Columnstore Indexes
Expand Down Expand Up @@ -71,14 +79,12 @@ Once we push a new version to nuget.org add a double hash header for that versio
- Add `OwnerLoginName` property to `JobSchedule` per [issue 120](https://github.com/microsoft/sqlmanagementobjects/issues/120)
- Fixed the `Database.AvailabilityDatabaseSynchronizationState` property to reflect the correct synchronization state of MI databases in Managed Instance Link

## 170.18.0
## 170.18.0, 161.48044.0

- Add `SearchPropertyList` support for Azure SQL Database

## 170.17.0, 161.48044.0

- Fix issue where `Table.Create` and `View.Create` were querying the server for indexes
- Add option to generate scripts exclusively for Data Classification, Create a new SMO object `SensitivityClassification` under `Database`
- Add option to generate scripts exclusively for Data Classification
- Create a new SMO object `SensitivityClassification` under `Database`
- Add support for creating Certificate objects using binary-encoded certificate bytes (https://github.com/microsoft/sqlmanagementobjects/issues/132)
- Fix for incorrect scripting of Database objects targeting SQL Managed Instances

Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<PackageVersion Include="Azure.Storage.Blobs" Version="12.20.0" />
<PackageVersion Include="Azure.Security.KeyVault.Secrets" Version="4.4.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="$(SqlClientPackageVersion)" />
<PackageVersion Include="Microsoft.Data.Tools.StringResourceTool" Version="3.2.0" />
<PackageVersion Include="Microsoft.Identity.Client" Version="4.61.3" />
Expand Down
4 changes: 2 additions & 2 deletions SmoBuild/Version.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<AssemblyMajorVersion Condition="'$(AssemblyMajorVersion)'==''">17</AssemblyMajorVersion>
<AssemblyMajorVersion Condition="'$(AssemblyMajorVersion)'==''">18</AssemblyMajorVersion>
<AssemblyMinorVersion Condition="'$(AssemblyMinorVersion)'=='' and '$(GacVersion)' == 'true'">0</AssemblyMinorVersion>
<AssemblyMinorVersion Condition="'$(AssemblyMinorVersion)'==''">100</AssemblyMinorVersion>
<AssemblyBuildVersion Condition="'$(LocalBuildVersion)'!=''">$(LocalBuildVersion)</AssemblyBuildVersion>
Expand All @@ -13,7 +13,7 @@
<InformationalVersion>$(AssemblyFileVersion)</InformationalVersion>
<FileVersion>$(AssemblyFileVersion)</FileVersion>
<Version>$(AssemblyFileVersion)</Version>
<PackageMajorVersionIncrement Condition="'$(PackageMajorVersionIncrement)'==''">2</PackageMajorVersionIncrement>
<PackageMajorVersionIncrement Condition="'$(PackageMajorVersionIncrement)'==''">0</PackageMajorVersionIncrement>
<PackageVersion Condition="'$(PackageVersion)' == ''">$(AssemblyMajorVersion)$(PackageMajorVersionIncrement).$(AssemblyBuildVersion).$(AssemblyBuildRevision)</PackageVersion>
<AssemblyVersion Condition="'$(AssemblyVersion)'==''">$(AssemblyMajorVersion).$(AssemblyMinorVersion).0.0</AssemblyVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.414",
"version": "8.0.415",
"rollForward": "latestMinor"
},
"msbuild-sdks": {
Expand Down
2 changes: 2 additions & 0 deletions src/Codegen/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,15 @@ private enum CloudSupportedVersionFlags
v10_0 = 1,
v11_0 = 2,
v12_0 = 4,
// VBUMP - Note: Cloud versions have different versioning than on-prem
}

private static KeyValuePair<ServerVersion, int>[] m_CloudSupportedVersion =
{
new KeyValuePair<ServerVersion, int>(new ServerVersion(10,0), (int)CloudSupportedVersionFlags.v10_0),
new KeyValuePair<ServerVersion, int>(new ServerVersion(11,0), (int)CloudSupportedVersionFlags.v11_0),
new KeyValuePair<ServerVersion, int>(new ServerVersion(12,0), (int)CloudSupportedVersionFlags.v12_0)
// VBUMP
};

//Note - Datawarehouse is a special case since it doesn't currently actually have
Expand Down
10 changes: 10 additions & 0 deletions src/Codegen/cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@
</object>
<object class_name="Index" collection_name="Indexes" urn="Server[@Name='']/Database/Table/Index" is_design_mode="true" parent_type="SqlSmoObject" parent_mode="Design" possible_parents="Table;UserDefinedTableType;UserDefinedFunction;View" gen_body="index,server_events" support_xschema="true">
<collection element_type="IndexedColumn" />
<collection element_type="IndexedJsonPath" />
<collection element_type="IndexedXmlPath" />
<collection element_type="IndexedXmlPathNamespace" />
<collection element_type="ExtendedProperty" />
Expand Down Expand Up @@ -1120,6 +1121,9 @@
<property name="VectorIndexMetric" generate="true" is_intrinsic="true" />
<property name="VectorIndexType" generate="true" is_intrinsic="true" />

<!--JSON Index properties-->
<property name="OptimizeForArraySearch" generate="true" is_intrinsic="false" />

<!--Hekaton properties-->
<property name="BucketCount" generate="true" is_intrinsic="false"/>
<property name="IndexedXmlPathName" generate="true" is_intrinsic="true" />
Expand Down Expand Up @@ -1171,6 +1175,12 @@

</object>

<object class_name="IndexedJsonPath" collection_name="IndexedJsonPaths" urn="Server[@Name='']/Database/Table/Index/IndexedJsonPath" parent_type="Index" parent_mode="Design" is_design_mode="true" has_constructors="false">
<property name="Path" generate="true" is_intrinsic="true" />
<property name="TableID" generate="true" is_intrinsic="true" />
<property name="IndexID" generate="true" is_intrinsic="true" />
</object>

<object class_name="DistributionColumn" collection_name="DistributionColumnCollection" urn="Server[@Name='']/Database/Table/Index/DistributionColumn" is_design_mode="true" parent_type="Index" has_constructors="true" support_xschema="true">
<property name="ID" generate="true" is_intrinsic="false" />
</object>
Expand Down
7 changes: 7 additions & 0 deletions src/CollectionGenerator/AnalyzerReleases.Shipped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Shipped analyzer releases
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

## Release 1.0

### New Rules

9 changes: 9 additions & 0 deletions src/CollectionGenerator/AnalyzerReleases.Unshipped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md


### New Rules

Rule ID | Category | Severity | Notes
--------|----------|----------|--------------------
SMOCOLL001 | SmoCollection | Error |
17 changes: 17 additions & 0 deletions src/CollectionGenerator/CollectionGenerator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<DefineConstants Condition="'$(DebugCollectionGenerator)' != ''">$(DefineConstants);DEBUGCOLLECTIONGENERATOR</DefineConstants>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
</ItemGroup>
</Project>
112 changes: 112 additions & 0 deletions src/CollectionGenerator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Source Generators for SMO

We have two source generators in this project.

## SmoCollectionGenerator

To simplify adding new object types and their corresponding collections to SMO, we have strongly typed base collection classes and a code generator that emits the body of the collection classes.
To add a new collection, a code author can simply declare the new collection class and specify which of the base classes it uses.

The source generator looks at the `UrnSuffix` and other properties of the generic type arguments to emit the body of the new collection class at build time. There are 4 base classes to choose from:

- `SimpleObjectCollectionBase` is the base of the other collections and should be used if your object type doesn't match the criteria for one of the other base classes.
- `RemovableCollectionBase` derives from `SimpleObjectCollectionBase` and can be used when your collection allows removal of elements when the parent of the collection is in `Creating` state. For example, an app can add or remove elements to `Database.FileGroups` before calling `Database.Create`, but afterward it can only call `Database.FileGroups.Add`.
- `SchemaCollectionBase` contains objects that are part of a database schema.
- `ParameterCollectionBase` contains elements whose enumeration order is based on their `ID` instead of on their `Name`

### Examples

Input:

```C#
public sealed partial class FileGroupCollection : RemovableCollectionBase<FileGroup, Database>
{
}
```

Output:

```C#
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
namespace Microsoft.SqlServer.Management.Smo
{
///<summary>
///Collection of FileGroup objects associated with an instance of Database
///</summary>
public partial class FileGroupCollection
{
internal FileGroupCollection(SqlSmoObject parentInstance) : base((Database)parentInstance)
{
}

protected override string UrnSuffix => FileGroup.UrnSuffix;

internal override FileGroup GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new FileGroup(this, key, state);
}
}
```



## SqlSmoObjectGenerator

This source generator uses `SfcObject` attributes in the declaration of a `SqlSmoObject`-derived class to build switch statements that enable the scripting engine to map URN components to child property names without using reflection. Attributes using `SfcContainerRelationship` arguments identify child collections, while attributes using `SfcObjectRelationship` arguments identify child singletons.

### Examples:

Input:

```C#

[SfcObject(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny, typeof(Index), SfcObjectFlags.Design | SfcObjectFlags.Deploy)]
public override IndexCollection Indexes
{
get { return base.Indexes; }
}

[SfcObject(SfcObjectRelationship.ChildObject, SfcObjectCardinality.One)]
public DatabaseOptions DatabaseOptions
{
get
{
CheckObjectStateImpl(false);
if (null == m_DatabaseOptions)
{
m_DatabaseOptions = new DatabaseOptions(this, new ObjectKeyBase(), this.State/*SqlSmoState.Existing*/);
}
return m_DatabaseOptions;
}
}
```

Output:

```C#
namespace Microsoft.SqlServer.Management.Smo
{
public partial class Database
{
protected override SqlSmoObject GetSingletonInstance(string childTypeName)
{
switch (childTypeName)
{
case "Option":
case "DatabaseOptions":
return DatabaseOptions;
case "QueryStoreOptions":
return QueryStoreOptions;
case "DatabaseEncryptionKey":
return DatabaseEncryptionKey;
case "MasterKey":
return MasterKey;
case "ServiceBroker":
return ServiceBroker;

default:
return base.GetSingletonInstance(childTypeName);
}
}
}
}
```
Loading