Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create.UniqueConstraint API should be as feature complete as Create.Index for creating unique indexes #1259

Closed
jzabroski opened this issue Jun 2, 2020 · 0 comments
Assignees
Labels
feature:syntax feature A new feature (we all like those)
Milestone

Comments

@jzabroski
Copy link
Collaborator

jzabroski commented Jun 2, 2020

See #1081 (review)

At a high level, SQL Server only supports creating unique constraints with included column lists and filter clause using the CREATE INDEX syntax. The goal is to make it so that Create.UniqueConstraint offers the same expressiveness as Create.Index().OnTable().Column().Unique(): filtered indexes, included column lists.

  • For SQL Server, the SqlServer2005Generator has an ABI break: public virtual string GetIncludeString(CreateIndexExpression column) has the parameter renamed to public virtual string GetIncludeString(CreateIndexExpression expression). This is considered a minor break, and unexpected that clients would call this method through reflection.
  • For SQL Server, the extension methods for Create Constraint should no longer return void and return ICreateConstraintOptionsSyntax instead:
    • Clustered:
      • was: public static void Clustered(this ICreateConstraintOptionsSyntax expression)
      • now: public static ICreateConstraintOptionsSyntax Clustered(this ICreateConstraintOptionsSyntax expression)
      • what this enables: Not much. If you write createConstraintExpression.Clustered().Include("Column1"), it will fail, since it is non-sensical to include a column in a clustered index. If you write createConstraintExpression.Clustered().Filter("Column1 IS NOT NULL"), it will fail, since it is not possible to filter a SQL Server clustered index. The benefit of this API is it makes it easier for the user to refactor their code by simply changing createConstraintExpression.Clustered() to createConstraintExpression.NonClustered().
    • NonClustered:
      • was: public static void NonClustered(this ICreateConstraintOptionsSyntax expression)
      • now: public static ICreateConstraintOptionsSyntax NonClustered(this ICreateConstraintOptionsSyntax expression)
      • what this enables: Previously, you could only write: Create.UniqueConstraint("UQ_Foo").OnTable("Foo").Column("Bar").Filter("BAR IS NOT NULL").NonClustered();. Now, you can also write: Create.UniqueConstraint("UQ_Foo").OnTable("Foo").Column("Bar").NonClustered().Filter("BAR IS NOT NULL");
  • Helper extension methods API breaking change:
    • Rename SqlServerExtensions.Include to SqlServerExtensions.CreateIndexInclude
    • Added SqlServerExtensions.CreateUniqueConstraintInclude

Additional Considerations

  • CreateIndexExpressionNonKeyBuilder should remove public ICreateIndexNonKeyColumnSyntax Include(string columnName) in a future release? It's a question. It's relying on SupportAdditionalFeatures, which is a bit weird given the implementation points to SqlServerExtensions.CreateIndexInclude
@jzabroski jzabroski added this to the 4.0.0 milestone Jun 2, 2020
@jzabroski jzabroski added feature A new feature (we all like those) feature:syntax labels Jun 2, 2020
@jzabroski jzabroski modified the milestones: 4.0.0, 5.0.0 Jan 16, 2023
@jzabroski jzabroski modified the milestones: 5.0.0, 5.1.0 Dec 10, 2023
@jzabroski jzabroski self-assigned this Dec 19, 2023
@jzabroski jzabroski changed the title Clean up Unique Constraint API Create.UniqueConstraint API should be as feature complete as Create.Index() for creating unique indexes Dec 19, 2023
@jzabroski jzabroski changed the title Create.UniqueConstraint API should be as feature complete as Create.Index() for creating unique indexes Create.UniqueConstraint API should be as feature complete as Create.Index for creating unique indexes Dec 19, 2023
jzabroski added a commit that referenced this issue Dec 19, 2023
Fixes #1259 Create.UniqueConstraint API should be as feature complete…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:syntax feature A new feature (we all like those)
Projects
None yet
Development

No branches or pull requests

1 participant