From 9560a383b60f81c9f45732cccdac71617a5be180 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 11:48:54 -0400 Subject: [PATCH 1/9] Re-enabled instance manager detach test --- tests/Tgstation.Server.Tests/InstanceManagerTest.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Tgstation.Server.Tests/InstanceManagerTest.cs b/tests/Tgstation.Server.Tests/InstanceManagerTest.cs index 6d69d8e5cc..91c492dd2a 100644 --- a/tests/Tgstation.Server.Tests/InstanceManagerTest.cs +++ b/tests/Tgstation.Server.Tests/InstanceManagerTest.cs @@ -147,9 +147,6 @@ namespace Tgstation.Server.Tests firstTest.Online = false; firstTest = await instanceManagerClient.Update(firstTest, cancellationToken).ConfigureAwait(false); - // TODO: Re-enable the rest of these tests once https://github.com/tgstation/tgstation-server/issues/860 is dealt with - return; - await instanceManagerClient.Detach(firstTest, cancellationToken).ConfigureAwait(false); var instanceAttachFileName = (string)typeof(InstanceController).GetField("InstanceAttachFileName", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); From 4985d776abb08dc401322f1c161ef626d16b3ed1 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 13:34:56 -0400 Subject: [PATCH 2/9] Fix integration test values being overwritten by dev json --- tests/Tgstation.Server.Tests/IntegrationTest.cs | 4 ++-- tests/Tgstation.Server.Tests/TestingServer.cs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Tgstation.Server.Tests/IntegrationTest.cs b/tests/Tgstation.Server.Tests/IntegrationTest.cs index da497fd679..d1976de93e 100644 --- a/tests/Tgstation.Server.Tests/IntegrationTest.cs +++ b/tests/Tgstation.Server.Tests/IntegrationTest.cs @@ -213,8 +213,8 @@ namespace Tgstation.Server.Tests Assert.AreEqual(ApiHeaders.Version, serverInfo.ApiVersion); var assemblyVersion = typeof(IServer).Assembly.GetName().Version.Semver(); Assert.AreEqual(assemblyVersion, serverInfo.Version); - Assert.AreEqual(15U, serverInfo.MinimumPasswordLength); - Assert.AreEqual(10U, serverInfo.InstanceLimit); + Assert.AreEqual(10U, serverInfo.MinimumPasswordLength); + Assert.AreEqual(11U, serverInfo.InstanceLimit); Assert.AreEqual(150U, serverInfo.UserLimit); //check that modifying the token even slightly fucks up the auth diff --git a/tests/Tgstation.Server.Tests/TestingServer.cs b/tests/Tgstation.Server.Tests/TestingServer.cs index 2f8943cba5..d2e864d782 100644 --- a/tests/Tgstation.Server.Tests/TestingServer.cs +++ b/tests/Tgstation.Server.Tests/TestingServer.cs @@ -66,7 +66,8 @@ namespace Tgstation.Server.Tests String.Format(CultureInfo.InvariantCulture, "Database:ConnectionString={0}", connectionString), String.Format(CultureInfo.InvariantCulture, "Database:DropDatabase={0}", true), String.Format(CultureInfo.InvariantCulture, "General:SetupWizardMode={0}", SetupWizardMode.Never), - String.Format(CultureInfo.InvariantCulture, "General:InstanceLimit={0}", 10), + String.Format(CultureInfo.InvariantCulture, "General:MinimumPasswordLength={0}", 10), + String.Format(CultureInfo.InvariantCulture, "General:InstanceLimit={0}", 11), String.Format(CultureInfo.InvariantCulture, "General:UserLimit={0}", 150), String.Format(CultureInfo.InvariantCulture, "General:ValidInstancePaths:0={0}", Directory) }; From e295fa3568422e4c7c82d08a85d2ef9c014727f5 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 13:37:40 -0400 Subject: [PATCH 3/9] FINALLY figure out the cascading delete issue --- .../Database/DatabaseContext.cs | 22 +- .../20200425024539_SLAddJobErrorCodes.cs | 34 - ...427173852_MSFixCascadingDelete.Designer.cs | 830 ++++++++++++++++++ .../20200427173852_MSFixCascadingDelete.cs | 119 +++ ...27180159_MYFixCascadingDelete.Designer.cs} | 270 +++--- .../20200427180159_MYFixCascadingDelete.cs | 119 +++ ...s => 20200427180904_SLRebuild.Designer.cs} | 12 +- ...Rebuild.cs => 20200427180904_SLRebuild.cs} | 14 +- .../MySqlDatabaseContextModelSnapshot.cs | 10 +- .../SqlServerDatabaseContextModelSnapshot.cs | 8 +- .../SqliteDatabaseContextModelSnapshot.cs | 8 +- 11 files changed, 1244 insertions(+), 202 deletions(-) delete mode 100644 src/Tgstation.Server.Host/Database/Migrations/20200425024539_SLAddJobErrorCodes.cs create mode 100644 src/Tgstation.Server.Host/Database/Migrations/20200427173852_MSFixCascadingDelete.Designer.cs create mode 100644 src/Tgstation.Server.Host/Database/Migrations/20200427173852_MSFixCascadingDelete.cs rename src/Tgstation.Server.Host/Database/Migrations/{20200423053214_SLRebuild.Designer.cs => 20200427180159_MYFixCascadingDelete.Designer.cs} (75%) create mode 100644 src/Tgstation.Server.Host/Database/Migrations/20200427180159_MYFixCascadingDelete.cs rename src/Tgstation.Server.Host/Database/Migrations/{20200425024539_SLAddJobErrorCodes.Designer.cs => 20200427180904_SLRebuild.Designer.cs} (99%) rename src/Tgstation.Server.Host/Database/Migrations/{20200423053214_SLRebuild.cs => 20200427180904_SLRebuild.cs} (99%) diff --git a/src/Tgstation.Server.Host/Database/DatabaseContext.cs b/src/Tgstation.Server.Host/Database/DatabaseContext.cs index 173b0f6eb6..5c11fb0862 100644 --- a/src/Tgstation.Server.Host/Database/DatabaseContext.cs +++ b/src/Tgstation.Server.Host/Database/DatabaseContext.cs @@ -257,17 +257,25 @@ namespace Tgstation.Server.Host.Database modelBuilder.Entity().HasIndex(x => new { x.UserId, x.InstanceId }).IsUnique(); - modelBuilder.Entity().HasMany(x => x.RevisonInformations).WithOne(x => x.TestMerge).OnDelete(DeleteBehavior.Cascade); - var revInfo = modelBuilder.Entity(); - revInfo.HasMany(x => x.CompileJobs).WithOne(x => x.RevisionInformation).OnDelete(DeleteBehavior.Cascade); revInfo.HasMany(x => x.ActiveTestMerges).WithOne(x => x.RevisionInformation).OnDelete(DeleteBehavior.Cascade); - revInfo.HasOne(x => x.PrimaryTestMerge).WithOne(x => x.PrimaryRevisionInformation).OnDelete(DeleteBehavior.Restrict); + revInfo.HasOne(x => x.PrimaryTestMerge).WithOne(x => x.PrimaryRevisionInformation).OnDelete(DeleteBehavior.Cascade); revInfo.HasIndex(x => new { x.InstanceId, x.CommitSha }).IsUnique(); - modelBuilder.Entity().HasIndex(x => x.DirectoryName); + // IMPORTANT: When an instance is deleted (detached) it cascades into the maze of revinfo/testmerge/ritm/compilejob/job/ri relations + // This maze starts at revInfo and jobs + // jobs takes care of deleting compile jobs and ris + // rev info takes care of the rest + // Break the link here so the db doesn't shit itself complaining about cascading deletes + // EF will handle making the right query to destroy everything + revInfo.HasMany(x => x.CompileJobs).WithOne(x => x.RevisionInformation).OnDelete(DeleteBehavior.ClientNoAction); - modelBuilder.Entity().HasOne().WithOne(x => x.Job).OnDelete(DeleteBehavior.Restrict); + // Also break the link between ritm and testmerge so it doesn't cycle in a triangle with rev info + modelBuilder.Entity().HasMany(x => x.RevisonInformations).WithOne(x => x.TestMerge).OnDelete(DeleteBehavior.ClientNoAction); + + var compileJob = modelBuilder.Entity(); + compileJob.HasIndex(x => x.DirectoryName); + compileJob.HasOne(x => x.Job).WithOne().OnDelete(DeleteBehavior.Cascade); var chatChannel = modelBuilder.Entity(); chatChannel.HasIndex(x => new { x.ChatSettingsId, x.IrcChannel }).IsUnique(); @@ -305,7 +313,7 @@ namespace Tgstation.Server.Host.Database if (wasEmpty || (await Database.GetPendingMigrationsAsync(cancellationToken).ConfigureAwait(false)).Any()) { Logger.LogInformation("Migrating database..."); - await Database.MigrateAsync(cancellationToken).ConfigureAwait(false); + await Database.EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); } else Logger.LogDebug("No migrations to apply."); diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200425024539_SLAddJobErrorCodes.cs b/src/Tgstation.Server.Host/Database/Migrations/20200425024539_SLAddJobErrorCodes.cs deleted file mode 100644 index 36672e4575..0000000000 --- a/src/Tgstation.Server.Host/Database/Migrations/20200425024539_SLAddJobErrorCodes.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using System; - -namespace Tgstation.Server.Host.Database.Migrations -{ - /// - /// Adds the column for SQLite. - /// - public partial class SLAddJobErrorCodes : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - if (migrationBuilder == null) - throw new ArgumentNullException(nameof(migrationBuilder)); - - migrationBuilder.AddColumn( - name: "ErrorCode", - table: "Jobs", - nullable: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - if (migrationBuilder == null) - throw new ArgumentNullException(nameof(migrationBuilder)); - - migrationBuilder.DropColumn( - name: "ErrorCode", - table: "Jobs"); - } - } -} diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200427173852_MSFixCascadingDelete.Designer.cs b/src/Tgstation.Server.Host/Database/Migrations/20200427173852_MSFixCascadingDelete.Designer.cs new file mode 100644 index 0000000000..715dc9465c --- /dev/null +++ b/src/Tgstation.Server.Host/Database/Migrations/20200427173852_MSFixCascadingDelete.Designer.cs @@ -0,0 +1,830 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Tgstation.Server.Host.Database.Migrations +{ + [DbContext(typeof(SqlServerDatabaseContext))] + [Migration("20200427173852_MSFixCascadingDelete")] + partial class MSFixCascadingDelete + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Tgstation.Server.Host.Models.ChatBot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ChannelLimit") + .HasColumnType("int"); + + b.Property("ConnectionString") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("InstanceId") + .HasColumnType("bigint"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(100)") + .HasMaxLength(100); + + b.Property("Provider") + .HasColumnType("int"); + + b.Property("ReconnectionInterval") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("InstanceId", "Name") + .IsUnique(); + + b.ToTable("ChatBots"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.ChatChannel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ChatSettingsId") + .HasColumnType("bigint"); + + b.Property("DiscordChannelId") + .HasColumnType("decimal(20,0)"); + + b.Property("IrcChannel") + .HasColumnType("nvarchar(100)") + .HasMaxLength(100); + + b.Property("IsAdminChannel") + .IsRequired() + .HasColumnType("bit"); + + b.Property("IsUpdatesChannel") + .IsRequired() + .HasColumnType("bit"); + + b.Property("IsWatchdogChannel") + .IsRequired() + .HasColumnType("bit"); + + b.Property("Tag") + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.HasKey("Id"); + + b.HasIndex("ChatSettingsId", "DiscordChannelId") + .IsUnique() + .HasFilter("[DiscordChannelId] IS NOT NULL"); + + b.HasIndex("ChatSettingsId", "IrcChannel") + .IsUnique() + .HasFilter("[IrcChannel] IS NOT NULL"); + + b.ToTable("ChatChannels"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.CompileJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ByondVersion") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DMApiMajorVersion") + .HasColumnType("int"); + + b.Property("DMApiMinorVersion") + .HasColumnType("int"); + + b.Property("DMApiPatchVersion") + .HasColumnType("int"); + + b.Property("DirectoryName") + .IsRequired() + .HasColumnType("uniqueidentifier"); + + b.Property("DmeName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("JobId") + .HasColumnType("bigint"); + + b.Property("MinimumSecurityLevel") + .HasColumnType("int"); + + b.Property("Output") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("RevisionInformationId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("DirectoryName"); + + b.HasIndex("JobId") + .IsUnique(); + + b.HasIndex("RevisionInformationId"); + + b.ToTable("CompileJobs"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.DreamDaemonSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("AccessToken") + .HasColumnType("nvarchar(max)"); + + b.Property("AllowWebClient") + .IsRequired() + .HasColumnType("bit"); + + b.Property("AutoStart") + .IsRequired() + .HasColumnType("bit"); + + b.Property("InstanceId") + .HasColumnType("bigint"); + + b.Property("PrimaryPort") + .HasColumnType("int"); + + b.Property("ProcessId") + .HasColumnType("int"); + + b.Property("SecondaryPort") + .HasColumnType("int"); + + b.Property("SecurityLevel") + .HasColumnType("int"); + + b.Property("SoftRestart") + .IsRequired() + .HasColumnType("bit"); + + b.Property("SoftShutdown") + .IsRequired() + .HasColumnType("bit"); + + b.Property("StartupTimeout") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("InstanceId") + .IsUnique(); + + b.ToTable("DreamDaemonSettings"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.DreamMakerSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ApiValidationPort") + .HasColumnType("int"); + + b.Property("ApiValidationSecurityLevel") + .HasColumnType("int"); + + b.Property("InstanceId") + .HasColumnType("bigint"); + + b.Property("ProjectName") + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.HasKey("Id"); + + b.HasIndex("InstanceId") + .IsUnique(); + + b.ToTable("DreamMakerSettings"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.Instance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("AutoUpdateInterval") + .HasColumnType("bigint"); + + b.Property("ChatBotLimit") + .HasColumnType("int"); + + b.Property("ConfigurationType") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.Property("Online") + .IsRequired() + .HasColumnType("bit"); + + b.Property("Path") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("Path") + .IsUnique(); + + b.ToTable("Instances"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.InstanceUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ByondRights") + .HasColumnType("decimal(20,0)"); + + b.Property("ChatBotRights") + .HasColumnType("decimal(20,0)"); + + b.Property("ConfigurationRights") + .HasColumnType("decimal(20,0)"); + + b.Property("DreamDaemonRights") + .HasColumnType("decimal(20,0)"); + + b.Property("DreamMakerRights") + .HasColumnType("decimal(20,0)"); + + b.Property("InstanceId") + .HasColumnType("bigint"); + + b.Property("InstanceUserRights") + .HasColumnType("decimal(20,0)"); + + b.Property("RepositoryRights") + .HasColumnType("decimal(20,0)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("InstanceId"); + + b.HasIndex("UserId", "InstanceId") + .IsUnique(); + + b.ToTable("InstanceUsers"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.Job", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("CancelRight") + .HasColumnType("decimal(20,0)"); + + b.Property("CancelRightsType") + .HasColumnType("decimal(20,0)"); + + b.Property("Cancelled") + .IsRequired() + .HasColumnType("bit"); + + b.Property("CancelledById") + .HasColumnType("bigint"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ErrorCode") + .HasColumnType("bigint"); + + b.Property("ExceptionDetails") + .HasColumnType("nvarchar(max)"); + + b.Property("InstanceId") + .HasColumnType("bigint"); + + b.Property("StartedAt") + .IsRequired() + .HasColumnType("datetimeoffset"); + + b.Property("StartedById") + .HasColumnType("bigint"); + + b.Property("StoppedAt") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("CancelledById"); + + b.HasIndex("InstanceId"); + + b.HasIndex("StartedById"); + + b.ToTable("Jobs"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.ReattachInformation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("AccessIdentifier") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CompileJobId") + .HasColumnType("bigint"); + + b.Property("IsPrimary") + .HasColumnType("bit"); + + b.Property("LaunchSecurityLevel") + .HasColumnType("int"); + + b.Property("Port") + .HasColumnType("int"); + + b.Property("ProcessId") + .HasColumnType("int"); + + b.Property("RebootState") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CompileJobId"); + + b.ToTable("ReattachInformations"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.RepositorySettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("AccessToken") + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.Property("AccessUser") + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.Property("AutoUpdatesKeepTestMerges") + .IsRequired() + .HasColumnType("bit"); + + b.Property("AutoUpdatesSynchronize") + .IsRequired() + .HasColumnType("bit"); + + b.Property("CommitterEmail") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.Property("CommitterName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.Property("InstanceId") + .HasColumnType("bigint"); + + b.Property("PostTestMergeComment") + .IsRequired() + .HasColumnType("bit"); + + b.Property("PushTestMergeCommits") + .IsRequired() + .HasColumnType("bit"); + + b.Property("ShowTestMergeCommitters") + .IsRequired() + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.HasIndex("InstanceId") + .IsUnique(); + + b.ToTable("RepositorySettings"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.RevInfoTestMerge", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("RevisionInformationId") + .HasColumnType("bigint"); + + b.Property("TestMergeId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("RevisionInformationId"); + + b.HasIndex("TestMergeId"); + + b.ToTable("RevInfoTestMerges"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.RevisionInformation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("CommitSha") + .IsRequired() + .HasColumnType("nvarchar(40)") + .HasMaxLength(40); + + b.Property("InstanceId") + .HasColumnType("bigint"); + + b.Property("OriginCommitSha") + .IsRequired() + .HasColumnType("nvarchar(40)") + .HasMaxLength(40); + + b.HasKey("Id"); + + b.HasIndex("InstanceId", "CommitSha") + .IsUnique(); + + b.ToTable("RevisionInformations"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.TestMerge", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Author") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("BodyAtMerge") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Comment") + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.Property("MergedAt") + .HasColumnType("datetimeoffset"); + + b.Property("MergedById") + .HasColumnType("bigint"); + + b.Property("Number") + .HasColumnType("int"); + + b.Property("PrimaryRevisionInformationId") + .IsRequired() + .HasColumnType("bigint"); + + b.Property("PullRequestRevision") + .IsRequired() + .HasColumnType("nvarchar(40)") + .HasMaxLength(40); + + b.Property("TitleAtMerge") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Url") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("MergedById"); + + b.HasIndex("PrimaryRevisionInformationId") + .IsUnique(); + + b.ToTable("TestMerges"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("AdministrationRights") + .HasColumnType("decimal(20,0)"); + + b.Property("CanonicalName") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("CreatedAt") + .IsRequired() + .HasColumnType("datetimeoffset"); + + b.Property("CreatedById") + .HasColumnType("bigint"); + + b.Property("Enabled") + .IsRequired() + .HasColumnType("bit"); + + b.Property("InstanceManagerRights") + .HasColumnType("decimal(20,0)"); + + b.Property("LastPasswordUpdate") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasMaxLength(10000); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("SystemIdentifier") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("CanonicalName") + .IsUnique(); + + b.HasIndex("CreatedById"); + + b.HasIndex("SystemIdentifier") + .IsUnique() + .HasFilter("[SystemIdentifier] IS NOT NULL"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.WatchdogReattachInformation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("AlphaId") + .HasColumnType("bigint"); + + b.Property("AlphaIsActive") + .HasColumnType("bit"); + + b.Property("BravoId") + .HasColumnType("bigint"); + + b.Property("InstanceId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("AlphaId"); + + b.HasIndex("BravoId"); + + b.HasIndex("InstanceId") + .IsUnique(); + + b.ToTable("WatchdogReattachInformations"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.ChatBot", b => + { + b.HasOne("Tgstation.Server.Host.Models.Instance", "Instance") + .WithMany("ChatSettings") + .HasForeignKey("InstanceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.ChatChannel", b => + { + b.HasOne("Tgstation.Server.Host.Models.ChatBot", "ChatSettings") + .WithMany("Channels") + .HasForeignKey("ChatSettingsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.CompileJob", b => + { + b.HasOne("Tgstation.Server.Host.Models.Job", "Job") + .WithOne() + .HasForeignKey("Tgstation.Server.Host.Models.CompileJob", "JobId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "RevisionInformation") + .WithMany("CompileJobs") + .HasForeignKey("RevisionInformationId") + .OnDelete(DeleteBehavior.ClientNoAction) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.DreamDaemonSettings", b => + { + b.HasOne("Tgstation.Server.Host.Models.Instance", "Instance") + .WithOne("DreamDaemonSettings") + .HasForeignKey("Tgstation.Server.Host.Models.DreamDaemonSettings", "InstanceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.DreamMakerSettings", b => + { + b.HasOne("Tgstation.Server.Host.Models.Instance", "Instance") + .WithOne("DreamMakerSettings") + .HasForeignKey("Tgstation.Server.Host.Models.DreamMakerSettings", "InstanceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.InstanceUser", b => + { + b.HasOne("Tgstation.Server.Host.Models.Instance", "Instance") + .WithMany("InstanceUsers") + .HasForeignKey("InstanceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tgstation.Server.Host.Models.User", null) + .WithMany("InstanceUsers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.Job", b => + { + b.HasOne("Tgstation.Server.Host.Models.User", "CancelledBy") + .WithMany() + .HasForeignKey("CancelledById"); + + b.HasOne("Tgstation.Server.Host.Models.Instance", "Instance") + .WithMany("Jobs") + .HasForeignKey("InstanceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tgstation.Server.Host.Models.User", "StartedBy") + .WithMany() + .HasForeignKey("StartedById") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.ReattachInformation", b => + { + b.HasOne("Tgstation.Server.Host.Models.CompileJob", "CompileJob") + .WithMany() + .HasForeignKey("CompileJobId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.RepositorySettings", b => + { + b.HasOne("Tgstation.Server.Host.Models.Instance", "Instance") + .WithOne("RepositorySettings") + .HasForeignKey("Tgstation.Server.Host.Models.RepositorySettings", "InstanceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.RevInfoTestMerge", b => + { + b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "RevisionInformation") + .WithMany("ActiveTestMerges") + .HasForeignKey("RevisionInformationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tgstation.Server.Host.Models.TestMerge", "TestMerge") + .WithMany("RevisonInformations") + .HasForeignKey("TestMergeId") + .OnDelete(DeleteBehavior.ClientNoAction) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.RevisionInformation", b => + { + b.HasOne("Tgstation.Server.Host.Models.Instance", "Instance") + .WithMany("RevisionInformations") + .HasForeignKey("InstanceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.TestMerge", b => + { + b.HasOne("Tgstation.Server.Host.Models.User", "MergedBy") + .WithMany("TestMerges") + .HasForeignKey("MergedById") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "PrimaryRevisionInformation") + .WithOne("PrimaryTestMerge") + .HasForeignKey("Tgstation.Server.Host.Models.TestMerge", "PrimaryRevisionInformationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.User", b => + { + b.HasOne("Tgstation.Server.Host.Models.User", "CreatedBy") + .WithMany("CreatedUsers") + .HasForeignKey("CreatedById"); + }); + + modelBuilder.Entity("Tgstation.Server.Host.Models.WatchdogReattachInformation", b => + { + b.HasOne("Tgstation.Server.Host.Models.ReattachInformation", "Alpha") + .WithMany() + .HasForeignKey("AlphaId"); + + b.HasOne("Tgstation.Server.Host.Models.ReattachInformation", "Bravo") + .WithMany() + .HasForeignKey("BravoId"); + + b.HasOne("Tgstation.Server.Host.Models.Instance", null) + .WithOne("WatchdogReattachInformation") + .HasForeignKey("Tgstation.Server.Host.Models.WatchdogReattachInformation", "InstanceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200427173852_MSFixCascadingDelete.cs b/src/Tgstation.Server.Host/Database/Migrations/20200427173852_MSFixCascadingDelete.cs new file mode 100644 index 0000000000..b8d845e7d0 --- /dev/null +++ b/src/Tgstation.Server.Host/Database/Migrations/20200427173852_MSFixCascadingDelete.cs @@ -0,0 +1,119 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using System; + +namespace Tgstation.Server.Host.Database.Migrations +{ + /// + /// Fix cascading data deletes for s on MSSQL. + /// + public partial class MSFixCascadingDelete : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + if (migrationBuilder == null) + throw new ArgumentNullException(nameof(migrationBuilder)); + + migrationBuilder.DropForeignKey( + name: "FK_CompileJobs_Jobs_JobId", + table: "CompileJobs"); + + migrationBuilder.DropForeignKey( + name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", + table: "CompileJobs"); + + migrationBuilder.DropForeignKey( + name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", + table: "RevInfoTestMerges"); + + migrationBuilder.DropForeignKey( + name: "FK_TestMerges_RevisionInformations_PrimaryRevisionInformationId", + table: "TestMerges"); + + migrationBuilder.AddForeignKey( + name: "FK_CompileJobs_Jobs_JobId", + table: "CompileJobs", + column: "JobId", + principalTable: "Jobs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", + table: "CompileJobs", + column: "RevisionInformationId", + principalTable: "RevisionInformations", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", + table: "RevInfoTestMerges", + column: "TestMergeId", + principalTable: "TestMerges", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_TestMerges_RevisionInformations_PrimaryRevisionInformationId", + table: "TestMerges", + column: "PrimaryRevisionInformationId", + principalTable: "RevisionInformations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + if (migrationBuilder == null) + throw new ArgumentNullException(nameof(migrationBuilder)); + + migrationBuilder.DropForeignKey( + name: "FK_CompileJobs_Jobs_JobId", + table: "CompileJobs"); + + migrationBuilder.DropForeignKey( + name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", + table: "CompileJobs"); + + migrationBuilder.DropForeignKey( + name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", + table: "RevInfoTestMerges"); + + migrationBuilder.DropForeignKey( + name: "FK_TestMerges_RevisionInformations_PrimaryRevisionInformationId", + table: "TestMerges"); + + migrationBuilder.AddForeignKey( + name: "FK_CompileJobs_Jobs_JobId", + table: "CompileJobs", + column: "JobId", + principalTable: "Jobs", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", + table: "CompileJobs", + column: "RevisionInformationId", + principalTable: "RevisionInformations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", + table: "RevInfoTestMerges", + column: "TestMergeId", + principalTable: "TestMerges", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_TestMerges_RevisionInformations_PrimaryRevisionInformationId", + table: "TestMerges", + column: "PrimaryRevisionInformationId", + principalTable: "RevisionInformations", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200423053214_SLRebuild.Designer.cs b/src/Tgstation.Server.Host/Database/Migrations/20200427180159_MYFixCascadingDelete.Designer.cs similarity index 75% rename from src/Tgstation.Server.Host/Database/Migrations/20200423053214_SLRebuild.Designer.cs rename to src/Tgstation.Server.Host/Database/Migrations/20200427180159_MYFixCascadingDelete.Designer.cs index 89ce73ca21..1f708a964b 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200423053214_SLRebuild.Designer.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200427180159_MYFixCascadingDelete.Designer.cs @@ -6,49 +6,50 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Tgstation.Server.Host.Database.Migrations { - [DbContext(typeof(SqliteDatabaseContext))] - [Migration("20200423053214_SLRebuild")] - partial class SLRebuild + [DbContext(typeof(MySqlDatabaseContext))] + [Migration("20200427180159_MYFixCascadingDelete")] + partial class MYFixCascadingDelete { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.3"); + .HasAnnotation("ProductVersion", "3.1.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); modelBuilder.Entity("Tgstation.Server.Host.Models.ChatBot", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("ChannelLimit") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("smallint unsigned"); b.Property("ConnectionString") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.Property("Enabled") - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("InstanceId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("Name") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("varchar(100) CHARACTER SET utf8mb4") .HasMaxLength(100); b.Property("Provider") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("ReconnectionInterval") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("int unsigned"); b.HasKey("Id"); @@ -62,32 +63,32 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("ChatSettingsId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("DiscordChannelId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("IrcChannel") - .HasColumnType("TEXT") + .HasColumnType("varchar(100) CHARACTER SET utf8mb4") .HasMaxLength(100); b.Property("IsAdminChannel") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("IsUpdatesChannel") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("IsWatchdogChannel") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("Tag") - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.HasKey("Id"); @@ -105,41 +106,41 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("ByondVersion") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("DMApiMajorVersion") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("DMApiMinorVersion") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("DMApiPatchVersion") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("DirectoryName") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("char(36)"); b.Property("DmeName") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("JobId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("MinimumSecurityLevel") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("Output") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("RevisionInformationId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.HasKey("Id"); @@ -157,47 +158,47 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("AccessToken") - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("AllowWebClient") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("AutoStart") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("InstanceId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("PrimaryPort") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("smallint unsigned"); b.Property("ProcessId") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("SecondaryPort") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("smallint unsigned"); b.Property("SecurityLevel") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("SoftRestart") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("SoftShutdown") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("StartupTimeout") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("int unsigned"); b.HasKey("Id"); @@ -211,20 +212,20 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("ApiValidationPort") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("smallint unsigned"); b.Property("ApiValidationSecurityLevel") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("InstanceId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("ProjectName") - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.HasKey("Id"); @@ -239,31 +240,31 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("AutoUpdateInterval") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("int unsigned"); b.Property("ChatBotLimit") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("smallint unsigned"); b.Property("ConfigurationType") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("Name") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.Property("Online") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("Path") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -277,35 +278,35 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("ByondRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("ChatBotRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("ConfigurationRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("DreamDaemonRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("DreamMakerRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("InstanceId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("InstanceUserRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("RepositoryRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("UserId") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.HasKey("Id"); @@ -321,40 +322,43 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("CancelRight") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("CancelRightsType") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("Cancelled") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("CancelledById") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("Description") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("ErrorCode") + .HasColumnType("int unsigned"); b.Property("ExceptionDetails") - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("InstanceId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("StartedAt") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("datetime(6)"); b.Property("StartedById") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("StoppedAt") - .HasColumnType("TEXT"); + .HasColumnType("datetime(6)"); b.HasKey("Id"); @@ -371,29 +375,29 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("AccessIdentifier") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("CompileJobId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("IsPrimary") - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("LaunchSecurityLevel") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("Port") - .HasColumnType("INTEGER"); + .HasColumnType("smallint unsigned"); b.Property("ProcessId") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("RebootState") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.HasKey("Id"); @@ -406,48 +410,48 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("AccessToken") - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.Property("AccessUser") - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.Property("AutoUpdatesKeepTestMerges") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("AutoUpdatesSynchronize") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("CommitterEmail") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.Property("CommitterName") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.Property("InstanceId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("PostTestMergeComment") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("PushTestMergeCommits") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("ShowTestMergeCommitters") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.HasKey("Id"); @@ -461,13 +465,13 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("RevisionInformationId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("TestMergeId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.HasKey("Id"); @@ -482,19 +486,19 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("CommitSha") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("varchar(40) CHARACTER SET utf8mb4") .HasMaxLength(40); b.Property("InstanceId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("OriginCommitSha") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("varchar(40) CHARACTER SET utf8mb4") .HasMaxLength(40); b.HasKey("Id"); @@ -509,45 +513,45 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("Author") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("BodyAtMerge") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Comment") - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.Property("MergedAt") - .HasColumnType("TEXT"); + .HasColumnType("datetime(6)"); b.Property("MergedById") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("Number") - .HasColumnType("INTEGER"); + .HasColumnType("int"); b.Property("PrimaryRevisionInformationId") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("PullRequestRevision") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("varchar(40) CHARACTER SET utf8mb4") .HasMaxLength(40); b.Property("TitleAtMerge") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Url") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -563,42 +567,42 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("AdministrationRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("CanonicalName") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("CreatedAt") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("datetime(6)"); b.Property("CreatedById") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("Enabled") .IsRequired() - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("InstanceManagerRights") - .HasColumnType("INTEGER"); + .HasColumnType("bigint unsigned"); b.Property("LastPasswordUpdate") - .HasColumnType("TEXT"); + .HasColumnType("datetime(6)"); b.Property("Name") .IsRequired() - .HasColumnType("TEXT") + .HasColumnType("longtext CHARACTER SET utf8mb4") .HasMaxLength(10000); b.Property("PasswordHash") - .HasColumnType("TEXT"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("SystemIdentifier") - .HasColumnType("TEXT"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -617,19 +621,19 @@ namespace Tgstation.Server.Host.Database.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("AlphaId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("AlphaIsActive") - .HasColumnType("INTEGER"); + .HasColumnType("tinyint(1)"); b.Property("BravoId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.Property("InstanceId") - .HasColumnType("INTEGER"); + .HasColumnType("bigint"); b.HasKey("Id"); @@ -666,13 +670,13 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.Job", "Job") .WithOne() .HasForeignKey("Tgstation.Server.Host.Models.CompileJob", "JobId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "RevisionInformation") .WithMany("CompileJobs") .HasForeignKey("RevisionInformationId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -757,7 +761,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.TestMerge", "TestMerge") .WithMany("RevisonInformations") .HasForeignKey("TestMergeId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -781,7 +785,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "PrimaryRevisionInformation") .WithOne("PrimaryTestMerge") .HasForeignKey("Tgstation.Server.Host.Models.TestMerge", "PrimaryRevisionInformationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200427180159_MYFixCascadingDelete.cs b/src/Tgstation.Server.Host/Database/Migrations/20200427180159_MYFixCascadingDelete.cs new file mode 100644 index 0000000000..2a293c4477 --- /dev/null +++ b/src/Tgstation.Server.Host/Database/Migrations/20200427180159_MYFixCascadingDelete.cs @@ -0,0 +1,119 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using System; + +namespace Tgstation.Server.Host.Database.Migrations +{ + /// + /// Fix cascading data deletes for s on MYSQL. + /// + public partial class MYFixCascadingDelete : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + if (migrationBuilder == null) + throw new ArgumentNullException(nameof(migrationBuilder)); + + migrationBuilder.DropForeignKey( + name: "FK_CompileJobs_Jobs_JobId", + table: "CompileJobs"); + + migrationBuilder.DropForeignKey( + name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", + table: "CompileJobs"); + + migrationBuilder.DropForeignKey( + name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", + table: "RevInfoTestMerges"); + + migrationBuilder.DropForeignKey( + name: "FK_TestMerges_RevisionInformations_PrimaryRevisionInformationId", + table: "TestMerges"); + + migrationBuilder.AddForeignKey( + name: "FK_CompileJobs_Jobs_JobId", + table: "CompileJobs", + column: "JobId", + principalTable: "Jobs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", + table: "CompileJobs", + column: "RevisionInformationId", + principalTable: "RevisionInformations", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", + table: "RevInfoTestMerges", + column: "TestMergeId", + principalTable: "TestMerges", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_TestMerges_RevisionInformations_PrimaryRevisionInformationId", + table: "TestMerges", + column: "PrimaryRevisionInformationId", + principalTable: "RevisionInformations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + if (migrationBuilder == null) + throw new ArgumentNullException(nameof(migrationBuilder)); + + migrationBuilder.DropForeignKey( + name: "FK_CompileJobs_Jobs_JobId", + table: "CompileJobs"); + + migrationBuilder.DropForeignKey( + name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", + table: "CompileJobs"); + + migrationBuilder.DropForeignKey( + name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", + table: "RevInfoTestMerges"); + + migrationBuilder.DropForeignKey( + name: "FK_TestMerges_RevisionInformations_PrimaryRevisionInformationId", + table: "TestMerges"); + + migrationBuilder.AddForeignKey( + name: "FK_CompileJobs_Jobs_JobId", + table: "CompileJobs", + column: "JobId", + principalTable: "Jobs", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", + table: "CompileJobs", + column: "RevisionInformationId", + principalTable: "RevisionInformations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", + table: "RevInfoTestMerges", + column: "TestMergeId", + principalTable: "TestMerges", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_TestMerges_RevisionInformations_PrimaryRevisionInformationId", + table: "TestMerges", + column: "PrimaryRevisionInformationId", + principalTable: "RevisionInformations", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200425024539_SLAddJobErrorCodes.Designer.cs b/src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.Designer.cs similarity index 99% rename from src/Tgstation.Server.Host/Database/Migrations/20200425024539_SLAddJobErrorCodes.Designer.cs rename to src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.Designer.cs index 9c438a0b88..adc6df0eb6 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200425024539_SLAddJobErrorCodes.Designer.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.Designer.cs @@ -7,8 +7,8 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Tgstation.Server.Host.Database.Migrations { [DbContext(typeof(SqliteDatabaseContext))] - [Migration("20200425024539_SLAddJobErrorCodes")] - partial class SLAddJobErrorCodes + [Migration("20200427180904_SLRebuild")] + partial class SLRebuild { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -669,13 +669,13 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.Job", "Job") .WithOne() .HasForeignKey("Tgstation.Server.Host.Models.CompileJob", "JobId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "RevisionInformation") .WithMany("CompileJobs") .HasForeignKey("RevisionInformationId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -760,7 +760,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.TestMerge", "TestMerge") .WithMany("RevisonInformations") .HasForeignKey("TestMergeId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -784,7 +784,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "PrimaryRevisionInformation") .WithOne("PrimaryTestMerge") .HasForeignKey("Tgstation.Server.Host.Models.TestMerge", "PrimaryRevisionInformationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200423053214_SLRebuild.cs b/src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.cs similarity index 99% rename from src/Tgstation.Server.Host/Database/Migrations/20200423053214_SLRebuild.cs rename to src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.cs index 1792585a1d..afe27a2a88 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200423053214_SLRebuild.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.cs @@ -1,9 +1,6 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -#pragma warning disable CA1502 -#pragma warning disable CA1506 - namespace Tgstation.Server.Host.Database.Migrations { /// @@ -228,6 +225,7 @@ namespace Tgstation.Server.Host.Database.Migrations Id = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), Description = table.Column(nullable: false), + ErrorCode = table.Column(nullable: true), ExceptionDetails = table.Column(nullable: true), StartedAt = table.Column(nullable: false), StoppedAt = table.Column(nullable: true), @@ -317,7 +315,7 @@ namespace Tgstation.Server.Host.Database.Migrations column: x => x.PrimaryRevisionInformationId, principalTable: "RevisionInformations", principalColumn: "Id", - onDelete: ReferentialAction.Restrict); + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -345,13 +343,12 @@ namespace Tgstation.Server.Host.Database.Migrations column: x => x.JobId, principalTable: "Jobs", principalColumn: "Id", - onDelete: ReferentialAction.Restrict); + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_CompileJobs_RevisionInformations_RevisionInformationId", column: x => x.RevisionInformationId, principalTable: "RevisionInformations", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); }); migrationBuilder.CreateTable( @@ -376,8 +373,7 @@ namespace Tgstation.Server.Host.Database.Migrations name: "FK_RevInfoTestMerges_TestMerges_TestMergeId", column: x => x.TestMergeId, principalTable: "TestMerges", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); }); migrationBuilder.CreateTable( diff --git a/src/Tgstation.Server.Host/Database/Migrations/MySqlDatabaseContextModelSnapshot.cs b/src/Tgstation.Server.Host/Database/Migrations/MySqlDatabaseContextModelSnapshot.cs index 2574c2c3e0..75d1dbf8de 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/MySqlDatabaseContextModelSnapshot.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/MySqlDatabaseContextModelSnapshot.cs @@ -3,7 +3,7 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -namespace Tgstation.Server.Host.Database +namespace Tgstation.Server.Host.Database.Migrations { [DbContext(typeof(MySqlDatabaseContext))] partial class MySqlDatabaseContextModelSnapshot : ModelSnapshot @@ -667,13 +667,13 @@ namespace Tgstation.Server.Host.Database b.HasOne("Tgstation.Server.Host.Models.Job", "Job") .WithOne() .HasForeignKey("Tgstation.Server.Host.Models.CompileJob", "JobId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "RevisionInformation") .WithMany("CompileJobs") .HasForeignKey("RevisionInformationId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -758,7 +758,7 @@ namespace Tgstation.Server.Host.Database b.HasOne("Tgstation.Server.Host.Models.TestMerge", "TestMerge") .WithMany("RevisonInformations") .HasForeignKey("TestMergeId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -782,7 +782,7 @@ namespace Tgstation.Server.Host.Database b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "PrimaryRevisionInformation") .WithOne("PrimaryTestMerge") .HasForeignKey("Tgstation.Server.Host.Models.TestMerge", "PrimaryRevisionInformationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); diff --git a/src/Tgstation.Server.Host/Database/Migrations/SqlServerDatabaseContextModelSnapshot.cs b/src/Tgstation.Server.Host/Database/Migrations/SqlServerDatabaseContextModelSnapshot.cs index c853baad97..f7a1c90396 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/SqlServerDatabaseContextModelSnapshot.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/SqlServerDatabaseContextModelSnapshot.cs @@ -679,13 +679,13 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.Job", "Job") .WithOne() .HasForeignKey("Tgstation.Server.Host.Models.CompileJob", "JobId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "RevisionInformation") .WithMany("CompileJobs") .HasForeignKey("RevisionInformationId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -770,7 +770,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.TestMerge", "TestMerge") .WithMany("RevisonInformations") .HasForeignKey("TestMergeId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -794,7 +794,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "PrimaryRevisionInformation") .WithOne("PrimaryTestMerge") .HasForeignKey("Tgstation.Server.Host.Models.TestMerge", "PrimaryRevisionInformationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); diff --git a/src/Tgstation.Server.Host/Database/Migrations/SqliteDatabaseContextModelSnapshot.cs b/src/Tgstation.Server.Host/Database/Migrations/SqliteDatabaseContextModelSnapshot.cs index 6521266802..dfc97e9809 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/SqliteDatabaseContextModelSnapshot.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/SqliteDatabaseContextModelSnapshot.cs @@ -666,13 +666,13 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.Job", "Job") .WithOne() .HasForeignKey("Tgstation.Server.Host.Models.CompileJob", "JobId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "RevisionInformation") .WithMany("CompileJobs") .HasForeignKey("RevisionInformationId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -757,7 +757,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.TestMerge", "TestMerge") .WithMany("RevisonInformations") .HasForeignKey("TestMergeId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientNoAction) .IsRequired(); }); @@ -781,7 +781,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.HasOne("Tgstation.Server.Host.Models.RevisionInformation", "PrimaryRevisionInformation") .WithOne("PrimaryTestMerge") .HasForeignKey("Tgstation.Server.Host.Models.TestMerge", "PrimaryRevisionInformationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); From 04b398fa25dc1bc8353025e08bd1360b1f94568f Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 14:13:31 -0400 Subject: [PATCH 4/9] Fix development appsettings not always getting copied --- src/Tgstation.Server.Host/Tgstation.Server.Host.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj index 20b2fc2fbd..c87c8f62fd 100644 --- a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj +++ b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj @@ -122,6 +122,9 @@ + + Always + PreserveNewest From 33e40d43c4049ed3726ad555ae49c662b26ec94a Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 14:13:45 -0400 Subject: [PATCH 5/9] Fix cancelling the setup wizard crashing the program --- src/Tgstation.Server.Host/Program.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Program.cs b/src/Tgstation.Server.Host/Program.cs index ded8ef0744..8666ac642f 100644 --- a/src/Tgstation.Server.Host/Program.cs +++ b/src/Tgstation.Server.Host/Program.cs @@ -58,7 +58,17 @@ namespace Tgstation.Server.Host using (var shutdownNotifier = new ProgramShutdownTokenSource()) { var cancellationToken = shutdownNotifier.Token; - var server = await ServerFactory.CreateServer(updatedArgsArray, updatePath, cancellationToken).ConfigureAwait(false); + IServer server; + try + { + server = await ServerFactory.CreateServer(updatedArgsArray, updatePath, cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // Console cancelled + return 0; + } + if (server == null) return 0; From 408f6e23b21213a3a46ec773532ea3f728f946ff Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 14:17:55 -0400 Subject: [PATCH 6/9] Fix codecov ignored paths --- .codecov.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.codecov.yml b/.codecov.yml index 420d5d9607..c82fe4fb61 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,7 +1,8 @@ codecov: strict_yaml_branch: master ignore: - - "src/Tgstation.Server.Host/Models/Migrations" + - "src/Tgstation.Server.Host/Database/Migrations" + - "src/Tgstation.Server.Host/Database/Design" coverage: status: project: From 07fef1038250a4191aa6c0bdff22ab06b846735e Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 14:20:19 -0400 Subject: [PATCH 7/9] How did this get left in? --- src/Tgstation.Server.Host/Database/DatabaseContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Database/DatabaseContext.cs b/src/Tgstation.Server.Host/Database/DatabaseContext.cs index 5c11fb0862..bc22c30c95 100644 --- a/src/Tgstation.Server.Host/Database/DatabaseContext.cs +++ b/src/Tgstation.Server.Host/Database/DatabaseContext.cs @@ -313,7 +313,7 @@ namespace Tgstation.Server.Host.Database if (wasEmpty || (await Database.GetPendingMigrationsAsync(cancellationToken).ConfigureAwait(false)).Any()) { Logger.LogInformation("Migrating database..."); - await Database.EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); + await Database.MigrateAsync(cancellationToken).ConfigureAwait(false); } else Logger.LogDebug("No migrations to apply."); From 9214357946b192aa70445420fae330f804ebe3b6 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 14:41:02 -0400 Subject: [PATCH 8/9] Suppress SQLite migration warning --- .../Database/Migrations/20200427180904_SLRebuild.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.cs b/src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.cs index afe27a2a88..2ee5bafeb4 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200427180904_SLRebuild.cs @@ -1,6 +1,8 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; +#pragma warning disable CA1506 + namespace Tgstation.Server.Host.Database.Migrations { /// From 8ee3d69f1c8e79b2f833b18f746a76564ff99259 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 27 Apr 2020 14:49:01 -0400 Subject: [PATCH 9/9] Remove save delay from SetupWizard - Fix test namespace --- src/Tgstation.Server.Host/Setup/SetupWizard.cs | 5 ----- .../{Core => Setup}/TestSetupWizard.cs | 5 ++--- 2 files changed, 2 insertions(+), 8 deletions(-) rename tests/Tgstation.Server.Host.Tests/{Core => Setup}/TestSetupWizard.cs (99%) diff --git a/src/Tgstation.Server.Host/Setup/SetupWizard.cs b/src/Tgstation.Server.Host/Setup/SetupWizard.cs index 65eb830ec8..369287ff9f 100644 --- a/src/Tgstation.Server.Host/Setup/SetupWizard.cs +++ b/src/Tgstation.Server.Host/Setup/SetupWizard.cs @@ -737,11 +737,6 @@ namespace Tgstation.Server.Host.Setup await console.PressAnyKeyAsync(cancellationToken).ConfigureAwait(false); throw new OperationCanceledException(); } - - await console.WriteAsync("Waiting for configuration changes to reload...", true, cancellationToken).ConfigureAwait(false); - - // we need to wait for the configuration's file system watcher to read and reload the changes - await asyncDelayer.Delay(TimeSpan.FromSeconds(5), cancellationToken).ConfigureAwait(false); } /// diff --git a/tests/Tgstation.Server.Host.Tests/Core/TestSetupWizard.cs b/tests/Tgstation.Server.Host.Tests/Setup/TestSetupWizard.cs similarity index 99% rename from tests/Tgstation.Server.Host.Tests/Core/TestSetupWizard.cs rename to tests/Tgstation.Server.Host.Tests/Setup/TestSetupWizard.cs index 679073a229..847a81fb49 100644 --- a/tests/Tgstation.Server.Host.Tests/Core/TestSetupWizard.cs +++ b/tests/Tgstation.Server.Host.Tests/Setup/TestSetupWizard.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -12,12 +11,12 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Configuration; +using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.IO; -using Tgstation.Server.Host.Setup; using Tgstation.Server.Host.System; -namespace Tgstation.Server.Host.Core.Tests +namespace Tgstation.Server.Host.Setup.Tests { [TestClass] public sealed class TestSetupWizard