tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
DatabaseContext.cs
Go to the documentation of this file.
1using System;
2using System.Globalization;
3using System.Linq;
4using System.Reflection;
5using System.Threading;
6using System.Threading.Tasks;
7
8using Microsoft.EntityFrameworkCore;
9using Microsoft.EntityFrameworkCore.Infrastructure;
10using Microsoft.EntityFrameworkCore.Migrations;
11using Microsoft.Extensions.DependencyInjection;
12using Microsoft.Extensions.Logging;
13
17
19{
23#pragma warning disable CA1506 // TODO: Decomplexify
25 {
29 public DbSet<User> Users { get; set; }
30
34 public DbSet<Instance> Instances { get; set; }
35
39 public DbSet<CompileJob> CompileJobs { get; set; }
40
44 public DbSet<RevisionInformation> RevisionInformations { get; set; }
45
49 public DbSet<DreamMakerSettings> DreamMakerSettings { get; set; }
50
54 public DbSet<ChatBot> ChatBots { get; set; }
55
59 public DbSet<DreamDaemonSettings> DreamDaemonSettings { get; set; }
60
64 public DbSet<RepositorySettings> RepositorySettings { get; set; }
65
69 public DbSet<InstancePermissionSet> InstancePermissionSets { get; set; }
70
74 public DbSet<ChatChannel> ChatChannels { get; set; }
75
79 public DbSet<Job> Jobs { get; set; }
80
84 public DbSet<ReattachInformation> ReattachInformations { get; set; }
85
89 public DbSet<TestMerge> TestMerges { get; set; }
90
94 public DbSet<RevInfoTestMerge> RevInfoTestMerges { get; set; }
95
99 public DbSet<OAuthConnection> OAuthConnections { get; set; }
100
104 public DbSet<PermissionSet> PermissionSets { get; set; }
105
109 public DbSet<UserGroup> Groups { get; set; }
110
113
116
119
121 IDatabaseCollection<Job> IDatabaseContext.Jobs => jobsCollection;
122
125
128
131
134
137
140
143
146
149
152
154 IDatabaseCollection<OAuthConnection> IDatabaseContext.OAuthConnections => oAuthConnections;
155
157 IDatabaseCollection<UserGroup> IDatabaseContext.Groups => groups;
158
160 IDatabaseCollection<PermissionSet> IDatabaseContext.PermissionSets => permissionSets;
161
165 protected virtual DeleteBehavior RevInfoCompileJobDeleteBehavior => DeleteBehavior.ClientNoAction;
166
171
176
181
186
191
196
201
206
211
216
221
226
231
236
241
246
251
257 public static Action<DbContextOptionsBuilder, DatabaseConfiguration> GetConfigureAction<TDatabaseContext>()
258 where TDatabaseContext : DatabaseContext
259 {
260 // HACK HACK HACK HACK HACK
261 const string ConfigureMethodName = nameof(SqlServerDatabaseContext.ConfigureWith);
262 var configureFunction = typeof(TDatabaseContext).GetMethod(
263 ConfigureMethodName,
264 BindingFlags.Public | BindingFlags.Static)
265 ?? throw new InvalidOperationException($"Context type {typeof(TDatabaseContext).FullName} missing static {ConfigureMethodName} function!");
266 return (optionsBuilder, config) => configureFunction.Invoke(null, [optionsBuilder, config]);
267 }
268
273 protected DatabaseContext(DbContextOptions dbContextOptions)
274 : base(dbContextOptions)
275 {
293 }
294
296 public Task Save(CancellationToken cancellationToken) => SaveChangesAsync(cancellationToken);
297
299 public Task Drop(CancellationToken cancellationToken) => Database.EnsureDeletedAsync(cancellationToken);
300
302 public async ValueTask<bool> Migrate(ILogger<DatabaseContext> logger, CancellationToken cancellationToken)
303 {
304 ArgumentNullException.ThrowIfNull(logger);
305 var migrations = await Database.GetAppliedMigrationsAsync(cancellationToken);
306 var wasEmpty = !migrations.Any();
307
308 if (wasEmpty || (await Database.GetPendingMigrationsAsync(cancellationToken)).Any())
309 {
310 logger.LogInformation("Migrating database...");
311 await Database.MigrateAsync(cancellationToken);
312 }
313 else
314 logger.LogDebug("No migrations to apply");
315
316 wasEmpty |= !await Users.AsQueryable().AnyAsync(cancellationToken);
317
318 return wasEmpty;
319 }
320
322 public async ValueTask SchemaDowngradeForServerVersion(
323 ILogger<DatabaseContext> logger,
324 Version targetVersion,
325 DatabaseType currentDatabaseType,
326 CancellationToken cancellationToken)
327 {
328 ArgumentNullException.ThrowIfNull(logger);
329 ArgumentNullException.ThrowIfNull(targetVersion);
330 if (targetVersion < new Version(4, 0))
331 throw new ArgumentOutOfRangeException(nameof(targetVersion), targetVersion, "Cannot migrate below version 4.0.0!");
332
333 if (currentDatabaseType == DatabaseType.PostgresSql && targetVersion < new Version(4, 3, 0))
334 throw new NotSupportedException("Cannot migrate below version 4.3.0 with PostgresSql!");
335
336 if (currentDatabaseType == DatabaseType.MariaDB)
337 currentDatabaseType = DatabaseType.MySql; // Keeping switch expressions while avoiding `or` syntax from C#9
338
339 if (targetVersion < new Version(4, 1, 0))
340 throw new NotSupportedException("Cannot migrate below version 4.1.0!");
341
342 var targetMigration = GetTargetMigration(targetVersion, currentDatabaseType);
343
344 if (targetMigration == null)
345 {
346 logger.LogDebug("No down migration required.");
347 return;
348 }
349
350 // already setup
351 var migrationSubstitution = currentDatabaseType switch
352 {
353 DatabaseType.SqlServer => null, // already setup
354 DatabaseType.MySql => "MY{0}",
355 DatabaseType.Sqlite => "SL{0}",
356 DatabaseType.PostgresSql => "PG{0}",
357 _ => throw new InvalidOperationException($"Invalid DatabaseType: {currentDatabaseType}"),
358 };
359
360 if (migrationSubstitution != null)
361 targetMigration = String.Format(CultureInfo.InvariantCulture, migrationSubstitution, targetMigration[2..]);
362
363 // even though it clearly implements it in the DatabaseFacade definition this won't work without casting (╯ಠ益ಠ)╯︵ ┻━┻
364 var dbServiceProvider = ((IInfrastructure<IServiceProvider>)Database).Instance;
365 var migrator = dbServiceProvider.GetRequiredService<IMigrator>();
366
367 logger.LogInformation("Migrating down to version {targetVersion}. Target: {targetMigration}", targetVersion, targetMigration);
368 try
369 {
370 await migrator.MigrateAsync(targetMigration, cancellationToken);
371 }
372 catch (Exception e)
373 {
374 logger.LogCritical(e, "Failed to migrate!");
375 }
376 }
377
379 protected override void OnModelCreating(ModelBuilder modelBuilder)
380 {
381 ArgumentNullException.ThrowIfNull(modelBuilder);
382
383 base.OnModelCreating(modelBuilder);
384
385 var userModel = modelBuilder.Entity<User>();
386 userModel.HasIndex(x => x.CanonicalName).IsUnique();
387 userModel.HasIndex(x => x.SystemIdentifier).IsUnique();
388 userModel.HasMany(x => x.TestMerges).WithOne(x => x.MergedBy).OnDelete(DeleteBehavior.Restrict);
389 userModel.HasMany(x => x.OAuthConnections).WithOne(x => x.User).OnDelete(DeleteBehavior.Cascade);
390
391 modelBuilder.Entity<OAuthConnection>().HasIndex(x => new { x.Provider, x.ExternalUserId }).IsUnique();
392
393 var groupsModel = modelBuilder.Entity<UserGroup>();
394 groupsModel.HasIndex(x => x.Name).IsUnique();
395 groupsModel.HasMany(x => x.Users).WithOne(x => x.Group).OnDelete(DeleteBehavior.ClientSetNull);
396
397 var permissionSetModel = modelBuilder.Entity<PermissionSet>();
398 permissionSetModel.HasOne(x => x.Group).WithOne(x => x.PermissionSet).OnDelete(DeleteBehavior.Cascade);
399 permissionSetModel.HasOne(x => x.User).WithOne(x => x.PermissionSet).OnDelete(DeleteBehavior.Cascade);
400 permissionSetModel.HasMany(x => x.InstancePermissionSets).WithOne(x => x.PermissionSet).OnDelete(DeleteBehavior.Cascade);
401
402 modelBuilder.Entity<InstancePermissionSet>().HasIndex(x => new { x.PermissionSetId, x.InstanceId }).IsUnique();
403
404 var revInfo = modelBuilder.Entity<RevisionInformation>();
405 revInfo.HasMany(x => x.ActiveTestMerges).WithOne(x => x.RevisionInformation).OnDelete(DeleteBehavior.Cascade);
406 revInfo.HasOne(x => x.PrimaryTestMerge).WithOne(x => x.PrimaryRevisionInformation).OnDelete(DeleteBehavior.Cascade);
407 revInfo.HasIndex(x => new { x.InstanceId, x.CommitSha }).IsUnique();
408
409 // IMPORTANT: When an instance is deleted (detached) it cascades into the maze of revinfo/testmerge/ritm/compilejob/job/ri relations
410 // This maze starts at revInfo and jobs
411 // jobs takes care of deleting compile jobs and ris
412 // rev info takes care of the rest
413 // Break the link here so the db doesn't shit itself complaining about cascading deletes
414 // EF will handle making the right query to destroy everything
415 // UPDATE: I fuck with this constantly in hopes of eliminating FK issues on instance detack
416 revInfo.HasMany(x => x.CompileJobs).WithOne(x => x.RevisionInformation).OnDelete(RevInfoCompileJobDeleteBehavior);
417
418 // Also break the link between ritm and testmerge so it doesn't cycle in a triangle with rev info
419 modelBuilder.Entity<TestMerge>().HasMany(x => x.RevisonInformations).WithOne(x => x.TestMerge).OnDelete(DeleteBehavior.ClientNoAction);
420
421 var compileJob = modelBuilder.Entity<CompileJob>();
422 compileJob.HasIndex(x => x.DirectoryName);
423 compileJob.HasOne(x => x.Job).WithOne().OnDelete(DeleteBehavior.Cascade);
424
425 modelBuilder.Entity<ReattachInformation>().HasOne(x => x.CompileJob).WithMany().OnDelete(DeleteBehavior.Cascade);
426
427 var chatChannel = modelBuilder.Entity<ChatChannel>();
428 chatChannel.HasIndex(x => new { x.ChatSettingsId, x.IrcChannel }).IsUnique();
429 chatChannel.HasIndex(x => new { x.ChatSettingsId, x.DiscordChannelId }).IsUnique();
430 chatChannel.HasOne(x => x.ChatSettings).WithMany(x => x.Channels).HasForeignKey(x => x.ChatSettingsId).OnDelete(DeleteBehavior.Cascade);
431
432 modelBuilder.Entity<ChatBot>().HasIndex(x => new { x.InstanceId, x.Name }).IsUnique();
433
434 var instanceModel = modelBuilder.Entity<Instance>();
435 instanceModel.HasIndex(x => new { x.Path, x.SwarmIdentifer }).IsUnique();
436 instanceModel.HasMany(x => x.ChatSettings).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
437 instanceModel.HasOne(x => x.DreamDaemonSettings).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
438 instanceModel.HasOne(x => x.DreamMakerSettings).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
439 instanceModel.HasOne(x => x.RepositorySettings).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
440 instanceModel.HasMany(x => x.RevisionInformations).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
441 instanceModel.HasMany(x => x.InstancePermissionSets).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
442 instanceModel.HasMany(x => x.Jobs).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
443 }
444
445 // HEY YOU
446 // IF YOU HAVE A TEST THAT'S CREATING ERRORS BECAUSE THESE VALUES AREN'T SET CORRECTLY THERE'S MORE TO FIXING IT THAN JUST UPDATING THEM
447 // IN THE FUNCTION BELOW YOU ALSO NEED TO CORRECTLY SET THE RIGHT MIGRATION TO DOWNGRADE TO FOR THE LAST TGS VERSION
448 // YOU ALSO NEED TO UPDATE THE SWARM PROTOCOL MAJOR VERSION
449 // IF THIS BREAKS AGAIN I WILL PERSONALLY HAUNT YOUR ASS WHEN I DIE
450
454 internal static readonly Type MSLatestMigration = typeof(MSAddAutoStartAndStop);
455
459 internal static readonly Type MYLatestMigration = typeof(MYAddAutoStartAndStop);
460
464 internal static readonly Type PGLatestMigration = typeof(PGAddAutoStartAndStop);
465
469 internal static readonly Type SLLatestMigration = typeof(SLAddAutoStartAndStop);
470
477 private string? GetTargetMigration(Version targetVersion, DatabaseType currentDatabaseType)
478 {
479 // Update this with new migrations as they are made
480 string? targetMigration = null;
481
482 string BadDatabaseType() => throw new ArgumentException($"Invalid DatabaseType: {currentDatabaseType}", nameof(currentDatabaseType));
483
484 // !!! DON'T FORGET TO UPDATE THE SWARM PROTOCOL MAJOR VERSION !!!
485 if (targetVersion < new Version(6, 12, 0))
486 targetMigration = currentDatabaseType switch
487 {
488 DatabaseType.MySql => nameof(MYAddDMApiValidationMode),
489 DatabaseType.PostgresSql => nameof(PGAddDMApiValidationMode),
490 DatabaseType.SqlServer => nameof(MSAddDMApiValidationMode),
491 DatabaseType.Sqlite => nameof(SLAddDMApiValidationMode),
492 _ => BadDatabaseType(),
493 };
494
495 if (targetVersion < new Version(6, 7, 0))
496 targetMigration = currentDatabaseType switch
497 {
498 DatabaseType.MySql => nameof(MYAddCronAutoUpdates),
499 DatabaseType.PostgresSql => nameof(PGAddCronAutoUpdates),
500 DatabaseType.SqlServer => nameof(MSAddCronAutoUpdates),
501 DatabaseType.Sqlite => nameof(SLAddCronAutoUpdates),
502 _ => BadDatabaseType(),
503 };
504
505 if (targetVersion < new Version(6, 6, 0))
506 targetMigration = currentDatabaseType switch
507 {
508 DatabaseType.MySql => nameof(MYAddCompilerAdditionalArguments),
509 DatabaseType.PostgresSql => nameof(PGAddCompilerAdditionalArguments),
510 DatabaseType.SqlServer => nameof(MSAddCompilerAdditionalArguments),
511 DatabaseType.Sqlite => nameof(SLAddCompilerAdditionalArguments),
512 _ => BadDatabaseType(),
513 };
514
515 if (targetVersion < new Version(6, 5, 0))
516 targetMigration = currentDatabaseType switch
517 {
518 DatabaseType.MySql => nameof(MYAddMinidumpsOption),
519 DatabaseType.PostgresSql => nameof(PGAddMinidumpsOption),
520 DatabaseType.SqlServer => nameof(MSAddMinidumpsOption),
521 DatabaseType.Sqlite => nameof(SLAddMinidumpsOption),
522 _ => BadDatabaseType(),
523 };
524
525 if (targetVersion < new Version(6, 2, 0))
526 targetMigration = currentDatabaseType switch
527 {
528 DatabaseType.MySql => nameof(MYAddTopicPort),
529 DatabaseType.PostgresSql => nameof(PGAddTopicPort),
530 DatabaseType.SqlServer => nameof(MSAddTopicPort),
531 DatabaseType.Sqlite => nameof(SLAddTopicPort),
532 _ => BadDatabaseType(),
533 };
534
535 if (targetVersion < new Version(6, 0, 0))
536 targetMigration = currentDatabaseType switch
537 {
538 DatabaseType.MySql => nameof(MYAddJobCodes),
539 DatabaseType.PostgresSql => nameof(PGAddJobCodes),
540 DatabaseType.SqlServer => nameof(MSAddJobCodes),
541 DatabaseType.Sqlite => nameof(SLAddJobCodes),
542 _ => BadDatabaseType(),
543 };
544 if (targetVersion < new Version(5, 17, 0))
545 targetMigration = currentDatabaseType switch
546 {
547 DatabaseType.MySql => nameof(MYAddMapThreads),
548 DatabaseType.PostgresSql => nameof(PGAddMapThreads),
549 DatabaseType.SqlServer => nameof(MSAddMapThreads),
550 DatabaseType.Sqlite => nameof(SLAddMapThreads),
551 _ => BadDatabaseType(),
552 };
553 if (targetVersion < new Version(5, 13, 0))
554 targetMigration = currentDatabaseType switch
555 {
556 DatabaseType.MySql => nameof(MYAddReattachInfoInitialCompileJob),
557 DatabaseType.PostgresSql => nameof(PGAddReattachInfoInitialCompileJob),
558 DatabaseType.SqlServer => nameof(MSAddReattachInfoInitialCompileJob),
559 DatabaseType.Sqlite => nameof(SLAddReattachInfoInitialCompileJob),
560 _ => BadDatabaseType(),
561 };
562 if (targetVersion < new Version(5, 7, 3))
563 targetMigration = currentDatabaseType switch
564 {
565 DatabaseType.MySql => nameof(MYAddDreamDaemonLogOutput),
566 DatabaseType.PostgresSql => nameof(PGAddDreamDaemonLogOutput),
567 DatabaseType.SqlServer => nameof(MSAddDreamDaemonLogOutput),
568 DatabaseType.Sqlite => nameof(SLAddDreamDaemonLogOutput),
569 _ => BadDatabaseType(),
570 };
571 if (targetVersion < new Version(5, 7, 0))
572 targetMigration = currentDatabaseType switch
573 {
574 DatabaseType.MySql => nameof(MYAddProfiler),
575 DatabaseType.PostgresSql => nameof(PGAddProfiler),
576 DatabaseType.SqlServer => nameof(MSAddProfiler),
577 DatabaseType.Sqlite => nameof(SLAddProfiler),
578 _ => BadDatabaseType(),
579 };
580 if (targetVersion < new Version(4, 19, 0))
581 targetMigration = currentDatabaseType switch
582 {
583 DatabaseType.MySql => nameof(MYAddDumpOnHeartbeatRestart),
584 DatabaseType.PostgresSql => nameof(PGAddDumpOnHeartbeatRestart),
585 DatabaseType.SqlServer => nameof(MSAddDumpOnHeartbeatRestart),
586 DatabaseType.Sqlite => nameof(SLAddDumpOnHeartbeatRestart),
587 _ => BadDatabaseType(),
588 };
589 if (targetVersion < new Version(4, 18, 0))
590 targetMigration = currentDatabaseType switch
591 {
592 DatabaseType.MySql => nameof(MYAddUpdateSubmodules),
593 DatabaseType.PostgresSql => nameof(PGAddUpdateSubmodules),
594 DatabaseType.SqlServer => nameof(MSAddUpdateSubmodules),
595 DatabaseType.Sqlite => nameof(SLAddUpdateSubmodules),
596 _ => BadDatabaseType(),
597 };
598 if (targetVersion < new Version(4, 14, 0))
599 targetMigration = currentDatabaseType switch
600 {
601 DatabaseType.MySql => nameof(MYTruncateInstanceNames),
602 DatabaseType.PostgresSql => nameof(PGTruncateInstanceNames),
603 DatabaseType.SqlServer => nameof(MSTruncateInstanceNames),
604 DatabaseType.Sqlite => nameof(SLAddRevInfoTimestamp),
605 _ => BadDatabaseType(),
606 };
607 if (targetVersion < new Version(4, 10, 0))
608 targetMigration = currentDatabaseType switch
609 {
610 DatabaseType.MySql => nameof(MSAddRevInfoTimestamp),
611 DatabaseType.PostgresSql => nameof(PGAddRevInfoTimestamp),
612 DatabaseType.SqlServer => nameof(MSAddRevInfoTimestamp),
613 DatabaseType.Sqlite => nameof(SLAddRevInfoTimestamp),
614 _ => BadDatabaseType(),
615 };
616 if (targetVersion < new Version(4, 8, 0))
617 targetMigration = currentDatabaseType switch
618 {
619 DatabaseType.MySql => nameof(MYAddSwarmIdentifer),
620 DatabaseType.PostgresSql => nameof(PGAddSwarmIdentifer),
621 DatabaseType.SqlServer => nameof(MSAddSwarmIdentifer),
622 DatabaseType.Sqlite => nameof(SLAddSwarmIdentifer),
623 _ => BadDatabaseType(),
624 };
625 if (targetVersion < new Version(4, 7, 0))
626 targetMigration = currentDatabaseType switch
627 {
628 DatabaseType.MySql => nameof(MYAddAdditionalDDParameters),
629 DatabaseType.PostgresSql => nameof(PGAddAdditionalDDParameters),
630 DatabaseType.SqlServer => nameof(MSAddAdditionalDDParameters),
631 DatabaseType.Sqlite => nameof(SLAddAdditionalDDParameters),
632 _ => BadDatabaseType(),
633 };
634 if (targetVersion < new Version(4, 6, 0))
635 targetMigration = currentDatabaseType switch
636 {
637 DatabaseType.MySql => nameof(MYAddDeploymentColumns),
638 DatabaseType.PostgresSql => nameof(PGAddDeploymentColumns),
639 DatabaseType.SqlServer => nameof(MSAddDeploymentColumns),
640 DatabaseType.Sqlite => nameof(SLAddDeploymentColumns),
641 _ => BadDatabaseType(),
642 };
643 if (targetVersion < new Version(4, 5, 0))
644 targetMigration = currentDatabaseType switch
645 {
646 DatabaseType.MySql => nameof(MYAllowNullDMApi),
647 DatabaseType.PostgresSql => nameof(PGAllowNullDMApi),
648 DatabaseType.SqlServer => nameof(MSAllowNullDMApi),
649 DatabaseType.Sqlite => nameof(SLAllowNullDMApi),
650 _ => BadDatabaseType(),
651 };
652 if (targetVersion < new Version(4, 4, 0))
653 targetMigration = currentDatabaseType switch
654 {
655 DatabaseType.MySql => nameof(MYFixForeignKey),
656 DatabaseType.PostgresSql => nameof(PGCreate),
657 DatabaseType.SqlServer => nameof(MSRemoveSoftColumns),
658 DatabaseType.Sqlite => nameof(SLRemoveSoftColumns),
659 _ => BadDatabaseType(),
660 };
661
662 if (targetVersion < new Version(4, 2, 0))
663 targetMigration = currentDatabaseType == DatabaseType.Sqlite ? nameof(SLRebuild) : nameof(MSFixCascadingDelete);
664
665 return targetMigration;
666 }
667 }
668}
Backend abstract implementation of IDatabaseContext.
DbSet< ReattachInformation > ReattachInformations
The ReattachInformations in the DatabaseContext.
readonly IDatabaseCollection< UserGroup > groups
Backing field for IDatabaseContext.Groups.
DbSet< Job > Jobs
The Jobs in the DatabaseContext.
DbSet< Instance > Instances
The Instances in the DatabaseContext.
readonly IDatabaseCollection< RevInfoTestMerge > revInfoTestMergesCollection
Backing field for IDatabaseContext.RevInfoTestMerges.
readonly IDatabaseCollection< DreamMakerSettings > dreamMakerSettingsCollection
Backing field for IDatabaseContext.DreamMakerSettings.
virtual DeleteBehavior RevInfoCompileJobDeleteBehavior
The DeleteBehavior for the CompileJob/RevisionInformation foreign key.
readonly IDatabaseCollection< RepositorySettings > repositorySettingsCollection
Backing field for IDatabaseContext.RepositorySettings.
DbSet< OAuthConnection > OAuthConnections
The OAuthConnections in the DatabaseContext.
readonly IDatabaseCollection< User > usersCollection
Backing field for IDatabaseContext.Users.
readonly IDatabaseCollection< Job > jobsCollection
Backing field for IDatabaseContext.Jobs.
override void OnModelCreating(ModelBuilder modelBuilder)
DbSet< ChatChannel > ChatChannels
The ChatChannels in the DatabaseContext.
DatabaseContext(DbContextOptions dbContextOptions)
Initializes a new instance of the DatabaseContext class.
readonly IDatabaseCollection< DreamDaemonSettings > dreamDaemonSettingsCollection
Backing field for IDatabaseContext.DreamDaemonSettings.
readonly IDatabaseCollection< Instance > instancesCollection
Backing field for IDatabaseContext.Instances.
DbSet< InstancePermissionSet > InstancePermissionSets
The InstancePermissionSets in the DatabaseContext.
DbSet< PermissionSet > PermissionSets
The PermissionSets in the DatabaseContext.
readonly IDatabaseCollection< ChatChannel > chatChannelsCollection
Backing field for IDatabaseContext.ChatChannels.
DbSet< CompileJob > CompileJobs
The CompileJobs in the DatabaseContext.
async ValueTask< bool > Migrate(ILogger< DatabaseContext > logger, CancellationToken cancellationToken)
Creates and migrates the IDatabaseContext.A ValueTask<TResult> resulting in true if the database shou...
readonly IDatabaseCollection< RevisionInformation > revisionInformationsCollection
Backing field for IDatabaseContext.RevisionInformations.
DbSet< TestMerge > TestMerges
The TestMerges in the DatabaseContext.
async ValueTask SchemaDowngradeForServerVersion(ILogger< DatabaseContext > logger, Version targetVersion, DatabaseType currentDatabaseType, CancellationToken cancellationToken)
Attempt to downgrade the schema to the migration used for a given server targetVersion ....
readonly IDatabaseCollection< InstancePermissionSet > instancePermissionSetsCollection
Backing field for IDatabaseContext.InstancePermissionSets.
Task Drop(CancellationToken cancellationToken)
Attempts to delete all tables and drop the database in use.A Task representing the running operation.
readonly IDatabaseCollection< ReattachInformation > reattachInformationsCollection
Backing field for IDatabaseContext.ReattachInformations.
Task Save(CancellationToken cancellationToken)
Saves changes made to the IDatabaseContext.A Task representing the running operation.
readonly IDatabaseCollection< PermissionSet > permissionSets
Backing field for IDatabaseContext.PermissionSets.
readonly IDatabaseCollection< ChatBot > chatBotsCollection
Backing field for IDatabaseContext.ChatBots.
readonly IDatabaseCollection< CompileJob > compileJobsCollection
Backing field for IDatabaseContext.CompileJobs.
string? GetTargetMigration(Version targetVersion, DatabaseType currentDatabaseType)
Gets the name of the migration to run for migrating down to a given targetVersion for the currentDat...
DbSet< User > Users
The Users in the DatabaseContext.
DbSet< ChatBot > ChatBots
The ChatBots in the DatabaseContext.
DbSet< RevInfoTestMerge > RevInfoTestMerges
The RevInfoTestMerges in the DatabaseContext.
readonly IDatabaseCollection< OAuthConnection > oAuthConnections
Backing field for IDatabaseContext.OAuthConnections.
readonly IDatabaseCollection< TestMerge > testMergesCollection
Backing field for IDatabaseContext.TestMerges.
static Action< DbContextOptionsBuilder, DatabaseConfiguration > GetConfigureAction< TDatabaseContext >()
Gets the configure action for a given TDatabaseContext .
DbSet< RevisionInformation > RevisionInformations
The RevisionInformations in the DatabaseContext.
DbSet< UserGroup > Groups
The UserGroups in the DatabaseContext.
Adds the DreamMakerSettings DumpOnHeartbeatRestart column for MSSQL.
Adds the MapThreads DreamDaemonSettings column for MSSQL.
Adds the option to start the profiler with DreamDaemon for MSSQL.
Add the Timestamp column to RevisionInformations for MSSQL.
Update models for making the DMAPI optional for MSSQL.
Adds the DreamMakerSettings DumpOnHeartbeatRestart column for MYSQL.
Adds the MapThreads DreamDaemonSettings column for MYSQL.
Adds the option to start the profiler with DreamDaemon for MYSQL.
Update models for making the DMAPI optional for MYSQL.
Fix the CompileJob/RevisionInformation foreign key for MySQL.
Adds the DreamMakerSettings DumpOnHeartbeatRestart column for PostgresSQL.
Adds the MapThreads DreamDaemonSettings column for PostgresSQL.
Adds the option to start the profiler with DreamDaemon for PostgresSQL.
Adds the InitialCompileJobId to the ReattachInformations table for PostgresSQL.
Add the Timestamp column to RevisionInformations for PostgresSQL.
Adds the UpdateSubmodules repository setting for PostgresSQL.
Update models for making the DMAPI optional for PostgresSQL.
Adds the DreamMakerSettings DumpOnHeartbeatRestart column for SQLite.
Adds the MapThreads DreamDaemonSettings column for SQLite.
Adds the option to start the profiler with DreamDaemon for SQLite.
Add the Timestamp column to RevisionInformations for SQLite.
Update models for making the DMAPI optional for SQLite.
static void ConfigureWith(DbContextOptionsBuilder options, DatabaseConfiguration databaseConfiguration)
Configure the SqlServerDatabaseContext.
Represents an Api.Models.Instance in the database.
Definition Instance.cs:11
Database representation of Components.Session.ReattachInformation.
Represents a group of Users.
Definition UserGroup.cs:16
DatabaseType
Type of database to user.