tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
MySqlDatabaseContext.cs
Go to the documentation of this file.
1using System;
2
3using Microsoft.EntityFrameworkCore;
4
5using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
6
10
12{
17 {
19 protected override DeleteBehavior RevInfoCompileJobDeleteBehavior => DeleteBehavior.Cascade;
20
25 public MySqlDatabaseContext(DbContextOptions<MySqlDatabaseContext> dbContextOptions)
26 : base(dbContextOptions)
27 {
28 }
29
35 public static void ConfigureWith(DbContextOptionsBuilder options, DatabaseConfiguration databaseConfiguration)
36 {
37 ArgumentNullException.ThrowIfNull(options);
38 ArgumentNullException.ThrowIfNull(databaseConfiguration);
39
40 if (databaseConfiguration.DatabaseType != DatabaseType.MariaDB && databaseConfiguration.DatabaseType != DatabaseType.MySql)
41 throw new InvalidOperationException($"Invalid DatabaseType for {nameof(MySqlDatabaseContext)}!");
42
43 ServerVersion serverVersion;
44 if (!String.IsNullOrEmpty(databaseConfiguration.ServerVersion))
45 {
46 serverVersion = ServerVersion.Parse(
47 databaseConfiguration.ServerVersion,
48 databaseConfiguration.DatabaseType == DatabaseType.MariaDB
49 ? ServerType.MariaDb
50 : ServerType.MySql);
51 }
52 else
53 serverVersion = ServerVersion.AutoDetect(databaseConfiguration.ConnectionString);
54
55 options.UseMySql(
56 databaseConfiguration.ConnectionString,
57 serverVersion,
58 mySqlOptions =>
59 {
60 mySqlOptions.EnableRetryOnFailure();
61 mySqlOptions.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery);
62 });
63 }
64
66 protected override void OnModelCreating(ModelBuilder modelBuilder)
67 {
68 base.OnModelCreating(modelBuilder);
69
70 // Added to prevent a column type change after upgrading Pomelo.Mysql
71 // Related: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1606
72 modelBuilder
73 .MapMySqlTextField<ChatBot>(x => x.ConnectionString)
74 .MapMySqlTextField<ChatChannel>(x => x.Tag)
75 .MapMySqlTextField<ChatChannel>(x => x.IrcChannel)
76 .MapMySqlTextField<CompileJob>(x => x.EngineVersion)
77 .MapMySqlTextField<CompileJob>(x => x.DmeName)
78 .MapMySqlTextField<CompileJob>(x => x.Output)
79 .MapMySqlTextField<CompileJob>(x => x.RepositoryOrigin)
80 .MapMySqlTextField<DreamDaemonSettings>(x => x.AdditionalParameters)
81 .MapMySqlTextField<DreamMakerSettings>(x => x.ProjectName)
82 .MapMySqlTextField<Instance>(x => x.Name)
83 .MapMySqlTextField<Instance>(x => x.Path)
84 .MapMySqlTextField<Instance>(x => x.SwarmIdentifer)
85 .MapMySqlTextField<Job>(x => x.Description)
86 .MapMySqlTextField<Job>(x => x.ExceptionDetails)
87 .MapMySqlTextField<OAuthConnection>(x => x.ExternalUserId)
88 .MapMySqlTextField<ReattachInformation>(x => x.AccessIdentifier)
89 .MapMySqlTextField<RepositorySettings>(x => x.AccessToken)
90 .MapMySqlTextField<RepositorySettings>(x => x.AccessUser)
91 .MapMySqlTextField<RepositorySettings>(x => x.CommitterEmail)
92 .MapMySqlTextField<RepositorySettings>(x => x.CommitterName)
93 .MapMySqlTextField<RevisionInformation>(x => x.CommitSha)
94 .MapMySqlTextField<RevisionInformation>(x => x.OriginCommitSha)
95 .MapMySqlTextField<TestMerge>(x => x.Author)
96 .MapMySqlTextField<TestMerge>(x => x.BodyAtMerge)
97 .MapMySqlTextField<TestMerge>(x => x.Comment)
98 .MapMySqlTextField<TestMerge>(x => x.TargetCommitSha)
99 .MapMySqlTextField<TestMerge>(x => x.TitleAtMerge)
100 .MapMySqlTextField<TestMerge>(x => x.Url)
101 .MapMySqlTextField<User>(x => x.CanonicalName)
102 .MapMySqlTextField<User>(x => x.Name)
103 .MapMySqlTextField<User>(x => x.PasswordHash)
104 .MapMySqlTextField<User>(x => x.SystemIdentifier)
105 .MapMySqlTextField<UserGroup>(x => x.Name);
106 }
107 }
108}
string? ConnectionString
The information used to connect to the Provider.
virtual ? string Name
The name of the entity represented by the NamedEntity.
Configuration options for the Database.DatabaseContext.
string? ServerVersion
The string form of the global::System.Version of the target server.
string? ConnectionString
The connection string for the database.
DatabaseType DatabaseType
The Configuration.DatabaseType to create.
Backend abstract implementation of IDatabaseContext.
override void OnModelCreating(ModelBuilder modelBuilder)
static void ConfigureWith(DbContextOptionsBuilder options, DatabaseConfiguration databaseConfiguration)
Configure the MySqlDatabaseContext.
MySqlDatabaseContext(DbContextOptions< MySqlDatabaseContext > dbContextOptions)
Initializes a new instance of the MySqlDatabaseContext class.
Represents an Api.Models.Instance in the database.
Definition Instance.cs:11
Represents a group of Users.
Definition UserGroup.cs:16
DatabaseType
Type of database to user.