Skip to content

Commit

Permalink
Merge pull request #1092 from pkuehnel/fix/duplicateTeslaMateCarIds
Browse files Browse the repository at this point in the history
fix(TSCContext): make TeslaMateCarId unique
  • Loading branch information
pkuehnel authored Jan 27, 2024
2 parents 917d38b + 09d01e2 commit d342106
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<TscConfiguration>()
.HasIndex(c => c.Key)
.IsUnique();

modelBuilder.Entity<Car>()
.HasIndex(c => c.TeslaMateCarId)
.IsUnique();
}

#pragma warning disable CS8618
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TeslaSolarCharger.Model.Migrations
{
/// <inheritdoc />
public partial class MakeCarTeslaMateCarIdUnique : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_Cars_TeslaMateCarId",
table: "Cars",
column: "TeslaMateCarId",
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Cars_TeslaMateCarId",
table: "Cars");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Id");

b.HasIndex("TeslaMateCarId")
.IsUnique();

b.ToTable("Cars");
});

Expand Down

0 comments on commit d342106

Please sign in to comment.