From e6f32c30b4b1bcd4c490bc160d27d0a5b4c299fa Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Wed, 25 Mar 2020 07:56:48 -0700 Subject: [PATCH] Fix Alerts migration. --- ...r.cs => 20200325145606_Alerts.Designer.cs} | 17 ++++---------- ...430_Alerts.cs => 20200325145606_Alerts.cs} | 22 +++++-------------- .../ApplicationDbContextModelSnapshot.cs | 15 +++---------- Tests/DataServiceTests.cs | 14 ++++++++++++ 4 files changed, 26 insertions(+), 42 deletions(-) rename Server/Migrations/{20200325144430_Alerts.Designer.cs => 20200325145606_Alerts.Designer.cs} (98%) rename Server/Migrations/{20200325144430_Alerts.cs => 20200325145606_Alerts.cs} (74%) diff --git a/Server/Migrations/20200325144430_Alerts.Designer.cs b/Server/Migrations/20200325145606_Alerts.Designer.cs similarity index 98% rename from Server/Migrations/20200325144430_Alerts.Designer.cs rename to Server/Migrations/20200325145606_Alerts.Designer.cs index d05341833..de88e810a 100644 --- a/Server/Migrations/20200325144430_Alerts.Designer.cs +++ b/Server/Migrations/20200325145606_Alerts.Designer.cs @@ -9,7 +9,7 @@ namespace Remotely.Server.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20200325144430_Alerts")] + [Migration("20200325145606_Alerts")] partial class Alerts { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -238,10 +238,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("OrganizationID") .HasColumnType("TEXT"); - b.Property("UserIDId") - .HasColumnType("TEXT"); - - b.Property("UserId") + b.Property("UserID") .HasColumnType("TEXT"); b.HasKey("ID"); @@ -250,9 +247,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("OrganizationID"); - b.HasIndex("UserIDId"); - - b.HasIndex("UserId"); + b.HasIndex("UserID"); b.ToTable("Alerts"); }); @@ -633,13 +628,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .WithMany("Alerts") .HasForeignKey("OrganizationID"); - b.HasOne("Remotely.Shared.Models.RemotelyUser", "UserID") - .WithMany() - .HasForeignKey("UserIDId"); - b.HasOne("Remotely.Shared.Models.RemotelyUser", "User") .WithMany("Alerts") - .HasForeignKey("UserId"); + .HasForeignKey("UserID"); }); modelBuilder.Entity("Remotely.Shared.Models.ApiToken", b => diff --git a/Server/Migrations/20200325144430_Alerts.cs b/Server/Migrations/20200325145606_Alerts.cs similarity index 74% rename from Server/Migrations/20200325144430_Alerts.cs rename to Server/Migrations/20200325145606_Alerts.cs index faf097c02..569b8f68f 100644 --- a/Server/Migrations/20200325144430_Alerts.cs +++ b/Server/Migrations/20200325145606_Alerts.cs @@ -15,8 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder) DeviceID = table.Column(nullable: true), Message = table.Column(nullable: true), OrganizationID = table.Column(nullable: true), - UserId = table.Column(nullable: true), - UserIDId = table.Column(nullable: true) + UserID = table.Column(nullable: true) }, constraints: table => { @@ -34,14 +33,8 @@ protected override void Up(MigrationBuilder migrationBuilder) principalColumn: "ID", onDelete: ReferentialAction.Restrict); table.ForeignKey( - name: "FK_Alerts_RemotelyUsers_UserIDId", - column: x => x.UserIDId, - principalTable: "RemotelyUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Alerts_RemotelyUsers_UserId", - column: x => x.UserId, + name: "FK_Alerts_RemotelyUsers_UserID", + column: x => x.UserID, principalTable: "RemotelyUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); @@ -58,14 +51,9 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "OrganizationID"); migrationBuilder.CreateIndex( - name: "IX_Alerts_UserIDId", - table: "Alerts", - column: "UserIDId"); - - migrationBuilder.CreateIndex( - name: "IX_Alerts_UserId", + name: "IX_Alerts_UserID", table: "Alerts", - column: "UserId"); + column: "UserID"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/Server/Migrations/ApplicationDbContextModelSnapshot.cs b/Server/Migrations/ApplicationDbContextModelSnapshot.cs index 1a3d4c027..fd828d394 100644 --- a/Server/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Server/Migrations/ApplicationDbContextModelSnapshot.cs @@ -236,10 +236,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("OrganizationID") .HasColumnType("TEXT"); - b.Property("UserIDId") - .HasColumnType("TEXT"); - - b.Property("UserId") + b.Property("UserID") .HasColumnType("TEXT"); b.HasKey("ID"); @@ -248,9 +245,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("OrganizationID"); - b.HasIndex("UserIDId"); - - b.HasIndex("UserId"); + b.HasIndex("UserID"); b.ToTable("Alerts"); }); @@ -631,13 +626,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) .WithMany("Alerts") .HasForeignKey("OrganizationID"); - b.HasOne("Remotely.Shared.Models.RemotelyUser", "UserID") - .WithMany() - .HasForeignKey("UserIDId"); - b.HasOne("Remotely.Shared.Models.RemotelyUser", "User") .WithMany("Alerts") - .HasForeignKey("UserId"); + .HasForeignKey("UserID"); }); modelBuilder.Entity("Remotely.Shared.Models.ApiToken", b => diff --git a/Tests/DataServiceTests.cs b/Tests/DataServiceTests.cs index 3e24971a0..19b7bec16 100644 --- a/Tests/DataServiceTests.cs +++ b/Tests/DataServiceTests.cs @@ -151,5 +151,19 @@ public async Task UpdateServerAdmins() Assert.AreEqual(1, currentAdmins.Count); Assert.AreEqual(TestData.Admin2.UserName, currentAdmins[0]); } + + [TestMethod] + [DoNotParallelize] + public async Task AddAlert() + { + var alert = new Alert() + { + DeviceID = TestData.Device1.ID, + OrganizationID = TestData.OrganizationID, + Message = "Test Message", + UserID = TestData.Admin1.Id + }; + await DataService.AddAlert(alert); + } } }