diff --git a/src/Tgstation.Server.Api/Models/ChatChannel.cs b/src/Tgstation.Server.Api/Models/ChatChannel.cs index 80ab80393a..d2c38df45d 100644 --- a/src/Tgstation.Server.Api/Models/ChatChannel.cs +++ b/src/Tgstation.Server.Api/Models/ChatChannel.cs @@ -10,7 +10,7 @@ namespace Tgstation.Server.Api.Models /// /// The IRC channel name /// - [StringLength(Limits.MaximumStringLength)] + [StringLength(Limits.MaximumIndexableStringLength)] public string IrcChannel { get; set; } /// diff --git a/src/Tgstation.Server.Api/Models/Instance.cs b/src/Tgstation.Server.Api/Models/Instance.cs index ba7f662f4d..d0c3f1427d 100644 --- a/src/Tgstation.Server.Api/Models/Instance.cs +++ b/src/Tgstation.Server.Api/Models/Instance.cs @@ -24,7 +24,6 @@ namespace Tgstation.Server.Api.Models /// The path to where the is located. Can only be changed while the is offline. Must not exist when the instance is created /// [Required] - [StringLength(Limits.MaximumStringLength)] public string Path { get; set; } /// diff --git a/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs b/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs index 702bf8e1c8..a49f5f2640 100644 --- a/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs +++ b/src/Tgstation.Server.Api/Models/Internal/ChatBot.cs @@ -17,7 +17,7 @@ namespace Tgstation.Server.Api.Models.Internal /// The name of the connection /// [Required] - [StringLength(Limits.MaximumStringLength)] + [StringLength(Limits.MaximumIndexableStringLength)] public string Name { get; set; } /// diff --git a/src/Tgstation.Server.Api/Models/Limits.cs b/src/Tgstation.Server.Api/Models/Limits.cs index 5b77ca954a..be61530fe7 100644 --- a/src/Tgstation.Server.Api/Models/Limits.cs +++ b/src/Tgstation.Server.Api/Models/Limits.cs @@ -9,5 +9,10 @@ /// Length limit for strings in fields. /// public const int MaximumStringLength = 10000; + + /// + /// Length limit for s. + /// + public const int MaximumIndexableStringLength = 100; } } \ No newline at end of file diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200411164808_MSTonsOfValidation.Designer.cs b/src/Tgstation.Server.Host/Database/Migrations/20200411164808_MSTonsOfValidation.Designer.cs index 730adcf8ea..9291694aa7 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200411164808_MSTonsOfValidation.Designer.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200411164808_MSTonsOfValidation.Designer.cs @@ -37,7 +37,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("Name") .IsRequired() - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("Provider"); @@ -63,7 +63,7 @@ namespace Tgstation.Server.Host.Database.Migrations .HasConversion(new ValueConverter(v => default(decimal), v => default(decimal), new ConverterMappingHints(precision: 20, scale: 0))); b.Property("IrcChannel") - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("IsAdminChannel") .IsRequired(); @@ -207,8 +207,7 @@ namespace Tgstation.Server.Host.Database.Migrations .IsRequired(); b.Property("Path") - .IsRequired() - .HasMaxLength(10000); + .IsRequired(); b.HasKey("Id"); diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200411164808_MSTonsOfValidation.cs b/src/Tgstation.Server.Host/Database/Migrations/20200411164808_MSTonsOfValidation.cs index 81ffd5ccc9..b55e81288e 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200411164808_MSTonsOfValidation.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200411164808_MSTonsOfValidation.cs @@ -14,6 +14,14 @@ namespace Tgstation.Server.Host.Database.Migrations if (migrationBuilder == null) throw new ArgumentNullException(nameof(migrationBuilder)); + migrationBuilder.DropForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots"); + + migrationBuilder.DropIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels"); + migrationBuilder.DropIndex( name: "IX_ChatBots_InstanceId", table: "ChatBots"); @@ -36,17 +44,10 @@ namespace Tgstation.Server.Host.Database.Migrations nullable: false, oldClrType: typeof(string)); - migrationBuilder.AlterColumn( - name: "Path", - table: "Instances", - maxLength: 10000, - nullable: false, - oldClrType: typeof(string)); - migrationBuilder.AlterColumn( name: "IrcChannel", table: "ChatChannels", - maxLength: 10000, + maxLength: 100, nullable: true, oldClrType: typeof(string), oldNullable: true); @@ -61,7 +62,7 @@ namespace Tgstation.Server.Host.Database.Migrations migrationBuilder.AlterColumn( name: "Name", table: "ChatBots", - maxLength: 10000, + maxLength: 100, nullable: false, oldClrType: typeof(string)); @@ -77,6 +78,21 @@ namespace Tgstation.Server.Host.Database.Migrations table: "ChatBots", columns: new[] { "InstanceId", "Name" }, unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels", + columns: new[] { "ChatSettingsId", "IrcChannel" }, + unique: true, + filter: "[IrcChannel] IS NOT NULL"); + + migrationBuilder.AddForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots", + column: "InstanceId", + principalTable: "Instances", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } /// @@ -85,6 +101,14 @@ namespace Tgstation.Server.Host.Database.Migrations if (migrationBuilder == null) throw new ArgumentNullException(nameof(migrationBuilder)); + migrationBuilder.DropForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots"); + + migrationBuilder.DropIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels"); + migrationBuilder.DropIndex( name: "IX_Users_SystemIdentifier", table: "Users"); @@ -107,19 +131,12 @@ namespace Tgstation.Server.Host.Database.Migrations oldClrType: typeof(string), oldMaxLength: 40); - migrationBuilder.AlterColumn( - name: "Path", - table: "Instances", - nullable: false, - oldClrType: typeof(string), - oldMaxLength: 10000); - migrationBuilder.AlterColumn( name: "IrcChannel", table: "ChatChannels", nullable: true, oldClrType: typeof(string), - oldMaxLength: 10000, + oldMaxLength: 100, oldNullable: true); migrationBuilder.AlterColumn( @@ -133,7 +150,7 @@ namespace Tgstation.Server.Host.Database.Migrations table: "ChatBots", nullable: false, oldClrType: typeof(string), - oldMaxLength: 10000); + oldMaxLength: 100); migrationBuilder.CreateIndex( name: "IX_ChatBots_InstanceId", @@ -145,6 +162,21 @@ namespace Tgstation.Server.Host.Database.Migrations table: "ChatBots", column: "Name", unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels", + columns: new[] { "ChatSettingsId", "IrcChannel" }, + unique: true, + filter: "[IrcChannel] IS NOT NULL"); + + migrationBuilder.AddForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots", + column: "InstanceId", + principalTable: "Instances", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } } } diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200411170010_MYTonsOfValidation.Designer.cs b/src/Tgstation.Server.Host/Database/Migrations/20200411170010_MYTonsOfValidation.Designer.cs index 7c74ee16b5..0925fbc84c 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200411170010_MYTonsOfValidation.Designer.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200411170010_MYTonsOfValidation.Designer.cs @@ -33,7 +33,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("Name") .IsRequired() - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("Provider"); @@ -58,7 +58,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("DiscordChannelId"); b.Property("IrcChannel") - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("IsAdminChannel") .IsRequired(); @@ -201,8 +201,7 @@ namespace Tgstation.Server.Host.Database.Migrations .IsRequired(); b.Property("Path") - .IsRequired() - .HasMaxLength(10000); + .IsRequired(); b.HasKey("Id"); diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200411170010_MYTonsOfValidation.cs b/src/Tgstation.Server.Host/Database/Migrations/20200411170010_MYTonsOfValidation.cs index 5e58e4f46b..d9226554ec 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200411170010_MYTonsOfValidation.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200411170010_MYTonsOfValidation.cs @@ -14,6 +14,14 @@ namespace Tgstation.Server.Host.Database.Migrations if (migrationBuilder == null) throw new ArgumentNullException(nameof(migrationBuilder)); + migrationBuilder.DropForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots"); + + migrationBuilder.DropIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels"); + migrationBuilder.DropIndex( name: "IX_ChatBots_InstanceId", table: "ChatBots"); @@ -36,17 +44,10 @@ namespace Tgstation.Server.Host.Database.Migrations nullable: false, oldClrType: typeof(string)); - migrationBuilder.AlterColumn( - name: "Path", - table: "Instances", - maxLength: 10000, - nullable: false, - oldClrType: typeof(string)); - migrationBuilder.AlterColumn( name: "IrcChannel", table: "ChatChannels", - maxLength: 10000, + maxLength: 100, nullable: true, oldClrType: typeof(string), oldNullable: true); @@ -61,7 +62,7 @@ namespace Tgstation.Server.Host.Database.Migrations migrationBuilder.AlterColumn( name: "Name", table: "ChatBots", - maxLength: 10000, + maxLength: 100, nullable: false, oldClrType: typeof(string)); @@ -76,6 +77,21 @@ namespace Tgstation.Server.Host.Database.Migrations table: "ChatBots", columns: new[] { "InstanceId", "Name" }, unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels", + columns: new[] { "ChatSettingsId", "IrcChannel" }, + unique: true, + filter: "[IrcChannel] IS NOT NULL"); + + migrationBuilder.AddForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots", + column: "InstanceId", + principalTable: "Instances", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } /// @@ -84,6 +100,14 @@ namespace Tgstation.Server.Host.Database.Migrations if (migrationBuilder == null) throw new ArgumentNullException(nameof(migrationBuilder)); + migrationBuilder.DropForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots"); + + migrationBuilder.DropIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels"); + migrationBuilder.DropIndex( name: "IX_Users_SystemIdentifier", table: "Users"); @@ -106,19 +130,12 @@ namespace Tgstation.Server.Host.Database.Migrations oldClrType: typeof(string), oldMaxLength: 40); - migrationBuilder.AlterColumn( - name: "Path", - table: "Instances", - nullable: false, - oldClrType: typeof(string), - oldMaxLength: 10000); - migrationBuilder.AlterColumn( name: "IrcChannel", table: "ChatChannels", nullable: true, oldClrType: typeof(string), - oldMaxLength: 10000, + oldMaxLength: 100, oldNullable: true); migrationBuilder.AlterColumn( @@ -132,7 +149,7 @@ namespace Tgstation.Server.Host.Database.Migrations table: "ChatBots", nullable: false, oldClrType: typeof(string), - oldMaxLength: 10000); + oldMaxLength: 100); migrationBuilder.CreateIndex( name: "IX_ChatBots_InstanceId", @@ -144,6 +161,21 @@ namespace Tgstation.Server.Host.Database.Migrations table: "ChatBots", column: "Name", unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels", + columns: new[] { "ChatSettingsId", "IrcChannel" }, + unique: true, + filter: "[IrcChannel] IS NOT NULL"); + + migrationBuilder.AddForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots", + column: "InstanceId", + principalTable: "Instances", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } } } diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200411171140_SLTonsOfValidation.Designer.cs b/src/Tgstation.Server.Host/Database/Migrations/20200411171140_SLTonsOfValidation.Designer.cs index 47371e9872..318a200bb6 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200411171140_SLTonsOfValidation.Designer.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200411171140_SLTonsOfValidation.Designer.cs @@ -32,7 +32,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("Name") .IsRequired() - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("Provider"); @@ -57,7 +57,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("DiscordChannelId"); b.Property("IrcChannel") - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("IsAdminChannel") .IsRequired(); diff --git a/src/Tgstation.Server.Host/Database/Migrations/20200411171140_SLTonsOfValidation.cs b/src/Tgstation.Server.Host/Database/Migrations/20200411171140_SLTonsOfValidation.cs index 055d301d13..a039102a60 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/20200411171140_SLTonsOfValidation.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/20200411171140_SLTonsOfValidation.cs @@ -14,6 +14,14 @@ namespace Tgstation.Server.Host.Database.Migrations if (migrationBuilder == null) throw new ArgumentNullException(nameof(migrationBuilder)); + migrationBuilder.DropForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots"); + + migrationBuilder.DropIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels"); + migrationBuilder.DropIndex( name: "IX_ChatBots_InstanceId", table: "ChatBots"); @@ -40,6 +48,21 @@ namespace Tgstation.Server.Host.Database.Migrations table: "ChatBots", columns: new[] { "InstanceId", "Name" }, unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels", + columns: new[] { "ChatSettingsId", "IrcChannel" }, + unique: true, + filter: "[IrcChannel] IS NOT NULL"); + + migrationBuilder.AddForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots", + column: "InstanceId", + principalTable: "Instances", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } /// @@ -48,6 +71,14 @@ namespace Tgstation.Server.Host.Database.Migrations if (migrationBuilder == null) throw new ArgumentNullException(nameof(migrationBuilder)); + migrationBuilder.DropForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots"); + + migrationBuilder.DropIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels"); + migrationBuilder.DropIndex( name: "IX_Users_SystemIdentifier", table: "Users"); @@ -72,6 +103,21 @@ namespace Tgstation.Server.Host.Database.Migrations table: "ChatBots", column: "Name", unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ChatChannels_ChatSettingsId_IrcChannel", + table: "ChatChannels", + columns: new[] { "ChatSettingsId", "IrcChannel" }, + unique: true, + filter: "[IrcChannel] IS NOT NULL"); + + migrationBuilder.AddForeignKey( + name: "FK_ChatBots_Instances_InstanceId", + table: "ChatBots", + column: "InstanceId", + principalTable: "Instances", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } } } diff --git a/src/Tgstation.Server.Host/Database/Migrations/MySqlDatabaseContextModelSnapshot.cs b/src/Tgstation.Server.Host/Database/Migrations/MySqlDatabaseContextModelSnapshot.cs index 3cbf873a23..495a245164 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/MySqlDatabaseContextModelSnapshot.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/MySqlDatabaseContextModelSnapshot.cs @@ -34,7 +34,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("Name") .IsRequired() - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("Provider"); @@ -59,7 +59,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("DiscordChannelId"); b.Property("IrcChannel") - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("IsAdminChannel") .IsRequired(); @@ -202,8 +202,7 @@ namespace Tgstation.Server.Host.Database.Migrations .IsRequired(); b.Property("Path") - .IsRequired() - .HasMaxLength(10000); + .IsRequired(); b.HasKey("Id"); diff --git a/src/Tgstation.Server.Host/Database/Migrations/SqlServerDatabaseContextModelSnapshot.cs b/src/Tgstation.Server.Host/Database/Migrations/SqlServerDatabaseContextModelSnapshot.cs index ace8d79d9a..1c333f9663 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/SqlServerDatabaseContextModelSnapshot.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/SqlServerDatabaseContextModelSnapshot.cs @@ -38,7 +38,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("Name") .IsRequired() - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("Provider"); @@ -64,7 +64,7 @@ namespace Tgstation.Server.Host.Database.Migrations .HasConversion(new ValueConverter(v => default(decimal), v => default(decimal), new ConverterMappingHints(precision: 20, scale: 0))); b.Property("IrcChannel") - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("IsAdminChannel") .IsRequired(); @@ -208,8 +208,7 @@ namespace Tgstation.Server.Host.Database.Migrations .IsRequired(); b.Property("Path") - .IsRequired() - .HasMaxLength(10000); + .IsRequired(); b.HasKey("Id"); diff --git a/src/Tgstation.Server.Host/Database/Migrations/SqliteDatabaseContextModelSnapshot.cs b/src/Tgstation.Server.Host/Database/Migrations/SqliteDatabaseContextModelSnapshot.cs index 9f6859dd3a..1b75f11e5d 100644 --- a/src/Tgstation.Server.Host/Database/Migrations/SqliteDatabaseContextModelSnapshot.cs +++ b/src/Tgstation.Server.Host/Database/Migrations/SqliteDatabaseContextModelSnapshot.cs @@ -33,7 +33,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("Name") .IsRequired() - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("Provider"); @@ -58,7 +58,7 @@ namespace Tgstation.Server.Host.Database.Migrations b.Property("DiscordChannelId"); b.Property("IrcChannel") - .HasMaxLength(10000); + .HasMaxLength(100); b.Property("IsAdminChannel") .IsRequired(); @@ -201,8 +201,7 @@ namespace Tgstation.Server.Host.Database.Migrations .IsRequired(); b.Property("Path") - .IsRequired() - .HasMaxLength(10000); + .IsRequired(); b.HasKey("Id"); diff --git a/tests/Tgstation.Server.Tests/TestingServer.cs b/tests/Tgstation.Server.Tests/TestingServer.cs index 527cdb283c..09de358599 100644 --- a/tests/Tgstation.Server.Tests/TestingServer.cs +++ b/tests/Tgstation.Server.Tests/TestingServer.cs @@ -60,7 +60,9 @@ namespace Tgstation.Server.Tests String.Format(CultureInfo.InvariantCulture, "Database:DatabaseType={0}", databaseType), 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:SetupWizardMode={0}", SetupWizardMode.Never), + String.Format(CultureInfo.InvariantCulture, "General:InstanceLimit={0}", 10), + String.Format(CultureInfo.InvariantCulture, "General:UserLimit={0}", 150) }; if (!String.IsNullOrEmpty(gitHubAccessToken))