mirror of
https://github.com/rafi1212122/BLHX.Server.git
synced 2025-12-12 14:34:39 +01:00
36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace BLHX.Server.Common.Database
|
|
{
|
|
public sealed class AccountContext : DbContext, IBLHXDBContext<AccountContext>
|
|
{
|
|
public static string DbPath => "Databases/accounts.db";
|
|
public DbSet<Account> Accounts { get; set; }
|
|
|
|
public AccountContext()
|
|
{
|
|
if (Database.GetPendingMigrations().Any())
|
|
Database.Migrate();
|
|
}
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
|
=> options.UseSqlite($"Data Source={((IBLHXDBContext)this).GetFullDbPath()}");
|
|
}
|
|
|
|
[PrimaryKey(nameof(Uid))]
|
|
public class Account
|
|
{
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
public uint Uid { get; set; }
|
|
public string DeviceId { get; set; }
|
|
public string Token { get; set; }
|
|
|
|
public Account(string deviceId, string token)
|
|
{
|
|
DeviceId = deviceId;
|
|
Token = token;
|
|
}
|
|
}
|
|
}
|