Skip to content

Commit

Permalink
Add DB migration (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanedirt committed Jun 16, 2024
1 parent 9c8fd9e commit ecb32fe
Show file tree
Hide file tree
Showing 4 changed files with 628 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/AliasDb/AliasDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
// </copyright>
//-----------------------------------------------------------------------

using Microsoft.Extensions.Configuration;

namespace AliasDb;

using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
Expand Down Expand Up @@ -118,4 +121,24 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasForeignKey(p => p.UserId)
.IsRequired();
}

/// <summary>
/// Sets up the connection string if it is not already configured.
/// </summary>
/// <param name="optionsBuilder">DbContextOptionsBuilder instance.</param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// If the options are not already configured, use the appsettings.json file.
if (!optionsBuilder.IsConfigured)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();

optionsBuilder
.UseSqlite(configuration.GetConnectionString("AliasDbContext"))
.UseLazyLoadingProxies();
}
}
}
Loading

0 comments on commit ecb32fe

Please sign in to comment.