tgstation-server 6.16.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<OidcConnection> OidcConnections { get; set; }
105
109 public DbSet<PermissionSet> PermissionSets { get; set; }
110
114 public DbSet<UserGroup> Groups { get; set; }
115
118
121
124
126 IDatabaseCollection<Job> IDatabaseContext.Jobs => jobsCollection;
127
130
133
136
139
142
145
148
151
154
157
159 IDatabaseCollection<OAuthConnection> IDatabaseContext.OAuthConnections => oAuthConnections;
160
162 IDatabaseCollection<OidcConnection> IDatabaseContext.OidcConnections => oidcConnections;
163
165 IDatabaseCollection<UserGroup> IDatabaseContext.Groups => groups;
166
168 IDatabaseCollection<PermissionSet> IDatabaseContext.PermissionSets => permissionSets;
169
173 protected virtual DeleteBehavior RevInfoCompileJobDeleteBehavior => DeleteBehavior.ClientNoAction;
174
179
184
189
194
199
204
209
214
219
224
229
234
239
244
249
254
259
264
270 public static Action<DbContextOptionsBuilder, DatabaseConfiguration> GetConfigureAction<TDatabaseContext>()
271 where TDatabaseContext : DatabaseContext
272 {
273 // HACK HACK HACK HACK HACK
274 const string ConfigureMethodName = nameof(SqlServerDatabaseContext.ConfigureWith);
275 var configureFunction = typeof(TDatabaseContext).GetMethod(
276 ConfigureMethodName,
277 BindingFlags.Public | BindingFlags.Static)
278 ?? throw new InvalidOperationException($"Context type {typeof(TDatabaseContext).FullName} missing static {ConfigureMethodName} function!");
279 return (optionsBuilder, config) => configureFunction.Invoke(null, [optionsBuilder, config]);
280 }
281
286 protected DatabaseContext(DbContextOptions dbContextOptions)
287 : base(dbContextOptions)
288 {
307 }
308
310 public Task Save(CancellationToken cancellationToken) => SaveChangesAsync(cancellationToken);
311
313 public Task Drop(CancellationToken cancellationToken) => Database.EnsureDeletedAsync(cancellationToken);
314
316 public async ValueTask<bool> Migrate(ILogger<DatabaseContext> logger, CancellationToken cancellationToken)
317 {
318 ArgumentNullException.ThrowIfNull(logger);
319 var migrations = await Database.GetAppliedMigrationsAsync(cancellationToken);
320 var wasEmpty = !migrations.Any();
321
322 if (wasEmpty || (await Database.GetPendingMigrationsAsync(cancellationToken)).Any())
323 {
324 logger.LogInformation("Migrating database...");
325 await Database.MigrateAsync(cancellationToken);
326 }
327 else
328 logger.LogDebug("No migrations to apply");
329
330 wasEmpty |= !await Users.AsQueryable().AnyAsync(cancellationToken);
331
332 return wasEmpty;
333 }
334
336 public async ValueTask SchemaDowngradeForServerVersion(
337 ILogger<DatabaseContext> logger,
338 Version targetVersion,
339 DatabaseType currentDatabaseType,
340 CancellationToken cancellationToken)
341 {
342 ArgumentNullException.ThrowIfNull(logger);
343 ArgumentNullException.ThrowIfNull(targetVersion);
344 if (targetVersion < new Version(4, 0))
345 throw new ArgumentOutOfRangeException(nameof(targetVersion), targetVersion, "Cannot migrate below version 4.0.0!");
346
347 if (currentDatabaseType == DatabaseType.PostgresSql && targetVersion < new Version(4, 3, 0))
348 throw new NotSupportedException("Cannot migrate below version 4.3.0 with PostgresSql!");
349
350 if (currentDatabaseType == DatabaseType.MariaDB)
351 currentDatabaseType = DatabaseType.MySql; // Keeping switch expressions while avoiding `or` syntax from C#9
352
353 if (targetVersion < new Version(4, 1, 0))
354 throw new NotSupportedException("Cannot migrate below version 4.1.0!");
355
356 var targetMigration = GetTargetMigration(targetVersion, currentDatabaseType);
357
358 if (targetMigration == null)
359 {
360 logger.LogDebug("No down migration required.");
361 return;
362 }
363
364 // already setup
365 var migrationSubstitution = currentDatabaseType switch
366 {
367 DatabaseType.SqlServer => null, // already setup
368 DatabaseType.MySql => "MY{0}",
369 DatabaseType.Sqlite => "SL{0}",
370 DatabaseType.PostgresSql => "PG{0}",
371 _ => throw new InvalidOperationException($"Invalid DatabaseType: {currentDatabaseType}"),
372 };
373
374 if (migrationSubstitution != null)
375 targetMigration = String.Format(CultureInfo.InvariantCulture, migrationSubstitution, targetMigration[2..]);
376
377 // even though it clearly implements it in the DatabaseFacade definition this won't work without casting (╯ಠ益ಠ)╯︵ ┻━┻
378 var dbServiceProvider = ((IInfrastructure<IServiceProvider>)Database).Instance;
379 var migrator = dbServiceProvider.GetRequiredService<IMigrator>();
380
381 logger.LogInformation("Migrating down to version {targetVersion}. Target: {targetMigration}", targetVersion, targetMigration);
382 try
383 {
384 await migrator.MigrateAsync(targetMigration, cancellationToken);
385 }
386 catch (Exception e)
387 {
388 logger.LogCritical(e, "Failed to migrate!");
389 }
390 }
391
393 protected override void OnModelCreating(ModelBuilder modelBuilder)
394 {
395 ArgumentNullException.ThrowIfNull(modelBuilder);
396
397 base.OnModelCreating(modelBuilder);
398
399 var userModel = modelBuilder.Entity<User>();
400 userModel.HasIndex(x => x.CanonicalName).IsUnique();
401 userModel.HasIndex(x => x.SystemIdentifier).IsUnique();
402 userModel.HasMany(x => x.TestMerges).WithOne(x => x.MergedBy).OnDelete(DeleteBehavior.Restrict);
403 userModel.HasMany(x => x.OAuthConnections).WithOne(x => x.User).OnDelete(DeleteBehavior.Cascade);
404 userModel.HasMany(x => x.OidcConnections).WithOne(x => x.User).OnDelete(DeleteBehavior.Cascade);
405
406 modelBuilder.Entity<OAuthConnection>().HasIndex(x => new { x.Provider, x.ExternalUserId }).IsUnique();
407 modelBuilder.Entity<OidcConnection>().HasIndex(x => new { x.SchemeKey, x.ExternalUserId }).IsUnique();
408
409 var groupsModel = modelBuilder.Entity<UserGroup>();
410 groupsModel.HasIndex(x => x.Name).IsUnique();
411 groupsModel.HasMany(x => x.Users).WithOne(x => x.Group).OnDelete(DeleteBehavior.ClientSetNull);
412
413 var permissionSetModel = modelBuilder.Entity<PermissionSet>();
414 permissionSetModel.HasOne(x => x.Group).WithOne(x => x.PermissionSet).OnDelete(DeleteBehavior.Cascade);
415 permissionSetModel.HasOne(x => x.User).WithOne(x => x.PermissionSet).OnDelete(DeleteBehavior.Cascade);
416 permissionSetModel.HasMany(x => x.InstancePermissionSets).WithOne(x => x.PermissionSet).OnDelete(DeleteBehavior.Cascade);
417
418 modelBuilder.Entity<InstancePermissionSet>().HasIndex(x => new { x.PermissionSetId, x.InstanceId }).IsUnique();
419
420 var revInfo = modelBuilder.Entity<RevisionInformation>();
421 revInfo.HasMany(x => x.ActiveTestMerges).WithOne(x => x.RevisionInformation).OnDelete(DeleteBehavior.Cascade);
422 revInfo.HasOne(x => x.PrimaryTestMerge).WithOne(x => x.PrimaryRevisionInformation).OnDelete(DeleteBehavior.Cascade);
423 revInfo.HasIndex(x => new { x.InstanceId, x.CommitSha }).IsUnique();
424
425 // IMPORTANT: When an instance is deleted (detached) it cascades into the maze of revinfo/testmerge/ritm/compilejob/job/ri relations
426 // This maze starts at revInfo and jobs
427 // jobs takes care of deleting compile jobs and ris
428 // rev info takes care of the rest
429 // Break the link here so the db doesn't shit itself complaining about cascading deletes
430 // EF will handle making the right query to destroy everything
431 // UPDATE: I fuck with this constantly in hopes of eliminating FK issues on instance detack
432 revInfo.HasMany(x => x.CompileJobs).WithOne(x => x.RevisionInformation).OnDelete(RevInfoCompileJobDeleteBehavior);
433
434 // Also break the link between ritm and testmerge so it doesn't cycle in a triangle with rev info
435 modelBuilder.Entity<TestMerge>().HasMany(x => x.RevisonInformations).WithOne(x => x.TestMerge).OnDelete(DeleteBehavior.ClientNoAction);
436
437 var compileJob = modelBuilder.Entity<CompileJob>();
438 compileJob.HasIndex(x => x.DirectoryName);
439 compileJob.HasOne(x => x.Job).WithOne().OnDelete(DeleteBehavior.Cascade);
440
441 modelBuilder.Entity<ReattachInformation>().HasOne(x => x.CompileJob).WithMany().OnDelete(DeleteBehavior.Cascade);
442
443 var chatChannel = modelBuilder.Entity<ChatChannel>();
444 chatChannel.HasIndex(x => new { x.ChatSettingsId, x.IrcChannel }).IsUnique();
445 chatChannel.HasIndex(x => new { x.ChatSettingsId, x.DiscordChannelId }).IsUnique();
446 chatChannel.HasOne(x => x.ChatSettings).WithMany(x => x.Channels).HasForeignKey(x => x.ChatSettingsId).OnDelete(DeleteBehavior.Cascade);
447
448 modelBuilder.Entity<ChatBot>().HasIndex(x => new { x.InstanceId, x.Name }).IsUnique();
449
450 var instanceModel = modelBuilder.Entity<Instance>();
451 instanceModel.HasIndex(x => new { x.Path, x.SwarmIdentifer }).IsUnique();
452 instanceModel.HasMany(x => x.ChatSettings).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
453 instanceModel.HasOne(x => x.DreamDaemonSettings).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
454 instanceModel.HasOne(x => x.DreamMakerSettings).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
455 instanceModel.HasOne(x => x.RepositorySettings).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
456 instanceModel.HasMany(x => x.RevisionInformations).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
457 instanceModel.HasMany(x => x.InstancePermissionSets).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
458 instanceModel.HasMany(x => x.Jobs).WithOne(x => x.Instance).OnDelete(DeleteBehavior.Cascade);
459 }
460
461 // HEY YOU
462 // 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
463 // IN THE FUNCTION BELOW YOU ALSO NEED TO CORRECTLY SET THE RIGHT MIGRATION TO DOWNGRADE TO FOR THE LAST TGS VERSION
464 // YOU ALSO NEED TO UPDATE THE SWARM PROTOCOL MAJOR VERSION
465 // IF THIS BREAKS AGAIN I WILL PERSONALLY HAUNT YOUR ASS WHEN I DIE
466
470 internal static readonly Type MSLatestMigration = typeof(MSAddOidcConnections);
471
475 internal static readonly Type MYLatestMigration = typeof(MYAddOidcConnections);
476
480 internal static readonly Type PGLatestMigration = typeof(PGAddOidcConnections);
481
485 internal static readonly Type SLLatestMigration = typeof(SLAddOidcConnections);
486
493 private string? GetTargetMigration(Version targetVersion, DatabaseType currentDatabaseType)
494 {
495 // Update this with new migrations as they are made
496 string? targetMigration = null;
497
498 string BadDatabaseType() => throw new ArgumentException($"Invalid DatabaseType: {currentDatabaseType}", nameof(currentDatabaseType));
499
500 // !!! DON'T FORGET TO UPDATE THE SWARM PROTOCOL MAJOR VERSION !!!
501 if (targetVersion < new Version(6, 15, 0))
502 targetMigration = currentDatabaseType switch
503 {
504 DatabaseType.MySql => nameof(MYAddAutoStartAndStop),
505 DatabaseType.PostgresSql => nameof(PGAddAutoStartAndStop),
506 DatabaseType.SqlServer => nameof(MSAddAutoStartAndStop),
507 DatabaseType.Sqlite => nameof(SLAddAutoStartAndStop),
508 _ => BadDatabaseType(),
509 };
510
511 if (targetVersion < new Version(6, 12, 0))
512 targetMigration = currentDatabaseType switch
513 {
514 DatabaseType.MySql => nameof(MYAddDMApiValidationMode),
515 DatabaseType.PostgresSql => nameof(PGAddDMApiValidationMode),
516 DatabaseType.SqlServer => nameof(MSAddDMApiValidationMode),
517 DatabaseType.Sqlite => nameof(SLAddDMApiValidationMode),
518 _ => BadDatabaseType(),
519 };
520
521 if (targetVersion < new Version(6, 7, 0))
522 targetMigration = currentDatabaseType switch
523 {
524 DatabaseType.MySql => nameof(MYAddCronAutoUpdates),
525 DatabaseType.PostgresSql => nameof(PGAddCronAutoUpdates),
526 DatabaseType.SqlServer => nameof(MSAddCronAutoUpdates),
527 DatabaseType.Sqlite => nameof(SLAddCronAutoUpdates),
528 _ => BadDatabaseType(),
529 };
530
531 if (targetVersion < new Version(6, 6, 0))
532 targetMigration = currentDatabaseType switch
533 {
534 DatabaseType.MySql => nameof(MYAddCompilerAdditionalArguments),
535 DatabaseType.PostgresSql => nameof(PGAddCompilerAdditionalArguments),
536 DatabaseType.SqlServer => nameof(MSAddCompilerAdditionalArguments),
537 DatabaseType.Sqlite => nameof(SLAddCompilerAdditionalArguments),
538 _ => BadDatabaseType(),
539 };
540
541 if (targetVersion < new Version(6, 5, 0))
542 targetMigration = currentDatabaseType switch
543 {
544 DatabaseType.MySql => nameof(MYAddMinidumpsOption),
545 DatabaseType.PostgresSql => nameof(PGAddMinidumpsOption),
546 DatabaseType.SqlServer => nameof(MSAddMinidumpsOption),
547 DatabaseType.Sqlite => nameof(SLAddMinidumpsOption),
548 _ => BadDatabaseType(),
549 };
550
551 if (targetVersion < new Version(6, 2, 0))
552 targetMigration = currentDatabaseType switch
553 {
554 DatabaseType.MySql => nameof(MYAddTopicPort),
555 DatabaseType.PostgresSql => nameof(PGAddTopicPort),
556 DatabaseType.SqlServer => nameof(MSAddTopicPort),
557 DatabaseType.Sqlite => nameof(SLAddTopicPort),
558 _ => BadDatabaseType(),
559 };
560
561 if (targetVersion < new Version(6, 0, 0))
562 targetMigration = currentDatabaseType switch
563 {
564 DatabaseType.MySql => nameof(MYAddJobCodes),
565 DatabaseType.PostgresSql => nameof(PGAddJobCodes),
566 DatabaseType.SqlServer => nameof(MSAddJobCodes),
567 DatabaseType.Sqlite => nameof(SLAddJobCodes),
568 _ => BadDatabaseType(),
569 };
570 if (targetVersion < new Version(5, 17, 0))
571 targetMigration = currentDatabaseType switch
572 {
573 DatabaseType.MySql => nameof(MYAddMapThreads),
574 DatabaseType.PostgresSql => nameof(PGAddMapThreads),
575 DatabaseType.SqlServer => nameof(MSAddMapThreads),
576 DatabaseType.Sqlite => nameof(SLAddMapThreads),
577 _ => BadDatabaseType(),
578 };
579 if (targetVersion < new Version(5, 13, 0))
580 targetMigration = currentDatabaseType switch
581 {
582 DatabaseType.MySql => nameof(MYAddReattachInfoInitialCompileJob),
583 DatabaseType.PostgresSql => nameof(PGAddReattachInfoInitialCompileJob),
584 DatabaseType.SqlServer => nameof(MSAddReattachInfoInitialCompileJob),
585 DatabaseType.Sqlite => nameof(SLAddReattachInfoInitialCompileJob),
586 _ => BadDatabaseType(),
587 };
588 if (targetVersion < new Version(5, 7, 3))
589 targetMigration = currentDatabaseType switch
590 {
591 DatabaseType.MySql => nameof(MYAddDreamDaemonLogOutput),
592 DatabaseType.PostgresSql => nameof(PGAddDreamDaemonLogOutput),
593 DatabaseType.SqlServer => nameof(MSAddDreamDaemonLogOutput),
594 DatabaseType.Sqlite => nameof(SLAddDreamDaemonLogOutput),
595 _ => BadDatabaseType(),
596 };
597 if (targetVersion < new Version(5, 7, 0))
598 targetMigration = currentDatabaseType switch
599 {
600 DatabaseType.MySql => nameof(MYAddProfiler),
601 DatabaseType.PostgresSql => nameof(PGAddProfiler),
602 DatabaseType.SqlServer => nameof(MSAddProfiler),
603 DatabaseType.Sqlite => nameof(SLAddProfiler),
604 _ => BadDatabaseType(),
605 };
606 if (targetVersion < new Version(4, 19, 0))
607 targetMigration = currentDatabaseType switch
608 {
609 DatabaseType.MySql => nameof(MYAddDumpOnHeartbeatRestart),
610 DatabaseType.PostgresSql => nameof(PGAddDumpOnHeartbeatRestart),
611 DatabaseType.SqlServer => nameof(MSAddDumpOnHeartbeatRestart),
612 DatabaseType.Sqlite => nameof(SLAddDumpOnHeartbeatRestart),
613 _ => BadDatabaseType(),
614 };
615 if (targetVersion < new Version(4, 18, 0))
616 targetMigration = currentDatabaseType switch
617 {
618 DatabaseType.MySql => nameof(MYAddUpdateSubmodules),
619 DatabaseType.PostgresSql => nameof(PGAddUpdateSubmodules),
620 DatabaseType.SqlServer => nameof(MSAddUpdateSubmodules),
621 DatabaseType.Sqlite => nameof(SLAddUpdateSubmodules),
622 _ => BadDatabaseType(),
623 };
624 if (targetVersion < new Version(4, 14, 0))
625 targetMigration = currentDatabaseType switch
626 {
627 DatabaseType.MySql => nameof(MYTruncateInstanceNames),
628 DatabaseType.PostgresSql => nameof(PGTruncateInstanceNames),
629 DatabaseType.SqlServer => nameof(MSTruncateInstanceNames),
630 DatabaseType.Sqlite => nameof(SLAddRevInfoTimestamp),
631 _ => BadDatabaseType(),
632 };
633 if (targetVersion < new Version(4, 10, 0))
634 targetMigration = currentDatabaseType switch
635 {
636 DatabaseType.MySql => nameof(MSAddRevInfoTimestamp),
637 DatabaseType.PostgresSql => nameof(PGAddRevInfoTimestamp),
638 DatabaseType.SqlServer => nameof(MSAddRevInfoTimestamp),
639 DatabaseType.Sqlite => nameof(SLAddRevInfoTimestamp),
640 _ => BadDatabaseType(),
641 };
642 if (targetVersion < new Version(4, 8, 0))
643 targetMigration = currentDatabaseType switch
644 {
645 DatabaseType.MySql => nameof(MYAddSwarmIdentifer),
646 DatabaseType.PostgresSql => nameof(PGAddSwarmIdentifer),
647 DatabaseType.SqlServer => nameof(MSAddSwarmIdentifer),
648 DatabaseType.Sqlite => nameof(SLAddSwarmIdentifer),
649 _ => BadDatabaseType(),
650 };
651 if (targetVersion < new Version(4, 7, 0))
652 targetMigration = currentDatabaseType switch
653 {
654 DatabaseType.MySql => nameof(MYAddAdditionalDDParameters),
655 DatabaseType.PostgresSql => nameof(PGAddAdditionalDDParameters),
656 DatabaseType.SqlServer => nameof(MSAddAdditionalDDParameters),
657 DatabaseType.Sqlite => nameof(SLAddAdditionalDDParameters),
658 _ => BadDatabaseType(),
659 };
660 if (targetVersion < new Version(4, 6, 0))
661 targetMigration = currentDatabaseType switch
662 {
663 DatabaseType.MySql => nameof(MYAddDeploymentColumns),
664 DatabaseType.PostgresSql => nameof(PGAddDeploymentColumns),
665 DatabaseType.SqlServer => nameof(MSAddDeploymentColumns),
666 DatabaseType.Sqlite => nameof(SLAddDeploymentColumns),
667 _ => BadDatabaseType(),
668 };
669 if (targetVersion < new Version(4, 5, 0))
670 targetMigration = currentDatabaseType switch
671 {
672 DatabaseType.MySql => nameof(MYAllowNullDMApi),
673 DatabaseType.PostgresSql => nameof(PGAllowNullDMApi),
674 DatabaseType.SqlServer => nameof(MSAllowNullDMApi),
675 DatabaseType.Sqlite => nameof(SLAllowNullDMApi),
676 _ => BadDatabaseType(),
677 };
678 if (targetVersion < new Version(4, 4, 0))
679 targetMigration = currentDatabaseType switch
680 {
681 DatabaseType.MySql => nameof(MYFixForeignKey),
682 DatabaseType.PostgresSql => nameof(PGCreate),
683 DatabaseType.SqlServer => nameof(MSRemoveSoftColumns),
684 DatabaseType.Sqlite => nameof(SLRemoveSoftColumns),
685 _ => BadDatabaseType(),
686 };
687
688 if (targetVersion < new Version(4, 2, 0))
689 targetMigration = currentDatabaseType == DatabaseType.Sqlite ? nameof(SLRebuild) : nameof(MSFixCascadingDelete);
690
691 return targetMigration;
692 }
693 }
694}
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< OidcConnection > oidcConnections
Backing field for IDatabaseContext.OidcConnections.
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< OidcConnection > OidcConnections
The OidcConnections 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.