Skip to content

Commit 4c86da3

Browse files
committed
Add support for specifying non-clustered index sort direction
1 parent 4db075a commit 4c86da3

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/SqlCreateTableWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public string GetSql()
5454

5555
// collect non-PK indexes for separate output after the table DDL
5656
if (common != null && common.NonClusteredIndex && common != _columnOptions.PrimaryKey)
57-
ix.AppendLine(Invariant($"CREATE NONCLUSTERED INDEX [IX{indexCount++}_{_tableName}] ON [{_schemaName}].[{_tableName}] ([{common.ColumnName}]);"));
57+
ix.AppendLine(Invariant($"CREATE NONCLUSTERED INDEX [IX{indexCount++}_{_tableName}] ON [{_schemaName}].[{_tableName}] ([{common.ColumnName}] {common.NonClusteredIndexDirection});"));
5858
}
5959
}
6060

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/SqlColumn.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ public SqlDbType DataType
100100
/// </summary>
101101
public bool NonClusteredIndex { get; set; }
102102

103+
/// <summary>
104+
/// Specifies the sort direction for a non-clustered index on the SQL column.
105+
/// The default value is <see cref="SqlIndexDirection.Asc"/>. This property is only used when auto-creating a log table.
106+
/// </summary>
107+
public SqlIndexDirection NonClusteredIndexDirection { get; set; }
108+
103109
/// <summary>
104110
/// The name of the Serilog property to use as the value when filling the DataTable.
105111
/// If not specified, the ColumnName and PropertyName are the same.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Serilog.Sinks.MSSqlServer
2+
{
3+
/// <summary>
4+
/// Defines the sort order for an SQL index.
5+
/// </summary>
6+
public enum SqlIndexDirection
7+
{
8+
/// <summary>
9+
/// Represents the ascending direction for SQL indexing.
10+
/// </summary>
11+
Asc,
12+
13+
/// <summary>
14+
/// Represents the descending direction for SQL indexing.
15+
/// </summary>
16+
Desc
17+
}
18+
}

0 commit comments

Comments
 (0)