Replace models with proper EF-models
This commit is contained in:
parent
b766813b60
commit
ca10f50645
49
ChaosBot/Models/ChaosbotContext.cs
Normal file
49
ChaosBot/Models/ChaosbotContext.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using ChaosBot.Database.Repository;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
public class ChaosbotContext : DbContext
|
||||
{
|
||||
public DbSet<LodestoneCharacter> LodestoneCharacter { get; set; }
|
||||
public DbSet<LodestoneFreeCompany> LodestoneFreeCompany { get; set; }
|
||||
public DbSet<Point> Points { get; set; }
|
||||
public DbSet<Raffle> Raffles { get; set; }
|
||||
public DbSet<CommandPermission> CommandPermissions { get; set; }
|
||||
public DbSet<Configuration> Configuration { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
if (ConfigurationRepository.AppSettingsHandler == null)
|
||||
{
|
||||
ConfigurationRepository.AppSettingsHandler = new ConfigurationBuilder()
|
||||
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("./appsettings.json", optional: false, reloadOnChange: true).Build();
|
||||
}
|
||||
string server = ConfigurationRepository.GetValue<string>("Database:Host");
|
||||
int port = ConfigurationRepository.GetValue<int>("Database:Port");
|
||||
string user = ConfigurationRepository.GetValue<string>("Database:User");
|
||||
string pass = ConfigurationRepository.GetValue<string>("Database:Pass");
|
||||
string name = ConfigurationRepository.GetValue<string>("Database:Name");
|
||||
optionsBuilder.UseMySql(
|
||||
$"server={server};port={port};user={user};password={pass};database={name}",
|
||||
x => x.ServerVersion("5.5.64-mariadb"));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<LodestoneCharacter>()
|
||||
.HasKey(x => new {x.DiscordGuildId, x.LodestoneId});
|
||||
modelBuilder.Entity<LodestoneFreeCompany>()
|
||||
.HasKey(x => new {x.DiscordGuildId, x.LodestoneId});
|
||||
modelBuilder.Entity<Point>()
|
||||
.HasKey(x => new {x.DiscordGuildId, x.DiscordUserId});
|
||||
modelBuilder.Entity<Configuration>()
|
||||
.HasKey(x => new {x.DiscordGuildId, x.Key});
|
||||
}
|
||||
}
|
||||
}
|
||||
20
ChaosBot/Models/CommandPermission.cs
Normal file
20
ChaosBot/Models/CommandPermission.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
#region Required
|
||||
public class CommandPermission
|
||||
{
|
||||
[Key]
|
||||
public ulong Id { get; set; }
|
||||
[Required]
|
||||
public ulong DiscordGuildId { get; set; }
|
||||
[Required]
|
||||
public ulong TargetId { get; set; }
|
||||
[Required]
|
||||
public int TargetType { get; set; }
|
||||
[Required]
|
||||
public string Command { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
18
ChaosBot/Models/Configuration.cs
Normal file
18
ChaosBot/Models/Configuration.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
#region Required
|
||||
public class Configuration
|
||||
{
|
||||
[Required]
|
||||
public ulong DiscordGuildId { get; set; }
|
||||
[Required]
|
||||
[MaxLength(128)]
|
||||
public string Key { get; set; }
|
||||
[Required]
|
||||
public string SerializedValue { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
public partial class LevelUp
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public long? UserId { get; set; }
|
||||
public long? GuildId { get; set; }
|
||||
public long? Experience { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable disable
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
public partial class LodestoneCharacter
|
||||
#region Required
|
||||
public class LodestoneCharacter
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
[Required]
|
||||
public ulong LodestoneId { get; set; }
|
||||
[Required]
|
||||
public ulong DiscordGuildId { get; set; }
|
||||
[Required]
|
||||
public ulong DiscordUserId { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
public string Avatar { get; set; }
|
||||
public long? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable disable
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
public partial class LodestoneFreeCompany
|
||||
#region Required
|
||||
public class LodestoneFreeCompany
|
||||
{
|
||||
public string Id { get; set; }
|
||||
[Required]
|
||||
public ulong LodestoneId { get; set; }
|
||||
[Required]
|
||||
public ulong DiscordGuildId { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
15
ChaosBot/Models/Point.cs
Normal file
15
ChaosBot/Models/Point.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
#region Required
|
||||
public class Point
|
||||
{
|
||||
[Required]
|
||||
public ulong DiscordUserId { get; set; }
|
||||
[Required]
|
||||
public ulong DiscordGuildId { get; set; }
|
||||
public ulong Amount { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
public partial class PointsTable
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? Points { get; set; }
|
||||
public long? UserId { get; set; }
|
||||
public long? GuildId { get; set; }
|
||||
}
|
||||
}
|
||||
16
ChaosBot/Models/Raffle.cs
Normal file
16
ChaosBot/Models/Raffle.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
#region Required
|
||||
public class Raffle
|
||||
{
|
||||
[Key]
|
||||
public ulong Id { get; set; }
|
||||
[Required]
|
||||
public ulong DiscordUserId { get; set; }
|
||||
[Required]
|
||||
public ulong DiscordGuildId { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
public partial class RaffleTable
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public long? UserId { get; set; }
|
||||
public long? GuildId { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
public partial class ServerConfigurationFlag
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string SerializedValue { get; set; }
|
||||
public long? GuildId { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,195 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ChaosBot.Models
|
||||
{
|
||||
public partial class chaosbotContext : DbContext
|
||||
{
|
||||
public chaosbotContext()
|
||||
{
|
||||
}
|
||||
|
||||
public chaosbotContext(DbContextOptions<chaosbotContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<LodestoneCharacter> LodestoneCharacters { get; set; }
|
||||
public virtual DbSet<LodestoneFreeCompany> LodestoneFreeCompanies { get; set; }
|
||||
public virtual DbSet<PointsTable> PointsTables { get; set; }
|
||||
public virtual DbSet<RaffleTable> RaffleTables { get; set; }
|
||||
public virtual DbSet<ServerConfigurationFlag> ServerConfigurationFlags { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
|
||||
optionsBuilder.UseMySql($"server={Program.LoadConfiguration("Database:Host")};port={Program.LoadConfiguration("Database:Port")};user={Program.LoadConfiguration("Database:User")};password={Program.LoadConfiguration("Database:Pass")};database={Program.LoadConfiguration("Database:Name")}", x => x.ServerVersion("5.5.64-mariadb"));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<LodestoneCharacter>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.ToTable("LodestoneCharacter");
|
||||
|
||||
entity.Property(e => e.Avatar)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("avatar")
|
||||
.HasCharSet("latin1")
|
||||
.HasCollation("latin1_swedish_ci")
|
||||
.HasAnnotation("Relational:ColumnType", "text");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id")
|
||||
.HasAnnotation("Relational:ColumnType", "int(11)");
|
||||
|
||||
entity.Property(e => e.Name)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name")
|
||||
.HasCharSet("latin1")
|
||||
.HasCollation("latin1_swedish_ci")
|
||||
.HasAnnotation("Relational:ColumnType", "text");
|
||||
|
||||
entity.Property(e => e.UserId)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("userId")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<LodestoneFreeCompany>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.ToTable("LodestoneFreeCompany");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("id")
|
||||
.HasCharSet("latin1")
|
||||
.HasCollation("latin1_swedish_ci")
|
||||
.HasAnnotation("Relational:ColumnType", "text");
|
||||
|
||||
entity.Property(e => e.Name)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name")
|
||||
.HasCharSet("latin1")
|
||||
.HasCollation("latin1_swedish_ci")
|
||||
.HasAnnotation("Relational:ColumnType", "text");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<PointsTable>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.ToTable("PointsTable");
|
||||
|
||||
entity.Property(e => e.GuildId)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("guildId")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id")
|
||||
.HasAnnotation("Relational:ColumnType", "int(11)");
|
||||
|
||||
entity.Property(e => e.Points)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("points")
|
||||
.HasAnnotation("Relational:ColumnType", "int(11)");
|
||||
|
||||
entity.Property(e => e.UserId)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("userId")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<RaffleTable>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.ToTable("RaffleTable");
|
||||
|
||||
entity.Property(e => e.GuildId)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("guildId")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id")
|
||||
.HasAnnotation("Relational:ColumnType", "int(11)");
|
||||
|
||||
entity.Property(e => e.UserId)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("userId")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<LevelUp>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.ToTable("LevelTable");
|
||||
|
||||
entity.Property(e => e.GuildId)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("guildId")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnType("int(11)")
|
||||
.HasColumnName("id")
|
||||
.HasAnnotation("Relational:ColumnType", "int(11)");
|
||||
|
||||
entity.Property(e => e.UserId)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("userId")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
|
||||
entity.Property(e => e.Experience)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("xp")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ServerConfigurationFlag>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.Property(e => e.GuildId)
|
||||
.HasColumnType("bigint(20)")
|
||||
.HasColumnName("guildId")
|
||||
.HasAnnotation("Relational:ColumnType", "bigint(20)");
|
||||
|
||||
entity.Property(e => e.Key)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("key")
|
||||
.HasCharSet("latin1")
|
||||
.HasCollation("latin1_swedish_ci")
|
||||
.HasAnnotation("Relational:ColumnType", "text");
|
||||
|
||||
entity.Property(e => e.SerializedValue)
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("serializedValue")
|
||||
.HasCharSet("latin1")
|
||||
.HasCollation("latin1_swedish_ci")
|
||||
.HasAnnotation("Relational:ColumnType", "text");
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user