Изменил папку нахождения бд
All checks were successful
Build and deploy / Publish image (push) Successful in 1m6s

This commit is contained in:
2025-02-06 07:20:43 +03:00
parent 2e5fb3972e
commit 069e4a5311
2 changed files with 11 additions and 10 deletions

View File

@@ -9,6 +9,10 @@ public class DatabaseContext : DbContext
public DbSet<Specialty> Specialties { get; set; } public DbSet<Specialty> Specialties { get; set; }
public string DbPath { get; } public string DbPath { get; }
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<Institut>().HasKey(i => i.Id); modelBuilder.Entity<Institut>().HasKey(i => i.Id);
@@ -37,13 +41,4 @@ public class DatabaseContext : DbContext
new Specialty() { Id = 10, Name = "Безопасность информационных технологий в правоохранительной сфере", Code = "10.05.05", InstitutId = 1 } new Specialty() { Id = 10, Name = "Безопасность информационных технологий в правоохранительной сфере", Code = "10.05.05", InstitutId = 1 }
); );
} }
public DatabaseContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
DbPath = System.IO.Path.Join("./", "database.db");
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
} }

View File

@@ -29,7 +29,13 @@ builder.Services.Configure<ForwardedHeadersOptions>(options =>
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
}); });
builder.Services.AddDbContext<DatabaseContext>(); var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
var folder = Path.Join(baseDirectory, "Data");
if (!Directory.Exists(folder))
Directory.CreateDirectory(folder);
folder = Path.Join(folder, "database.db");
builder.Services.AddDbContext<DatabaseContext>(options => options.UseSqlite($"Data Source={folder}"));
// Add services to the container. // Add services to the container.
builder.Services.AddRazorComponents() builder.Services.AddRazorComponents()