-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auto migrations): Add Migrations & IConfig (#16)
* adding migration project * add connection string * edited environment variables * fix env * Fix ENV! --------- Co-authored-by: sadq <[email protected]>
- Loading branch information
1 parent
b3dc3fe
commit 2a0e1dc
Showing
7 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONNECTION_STRING="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using DotNetEnv; | ||
using DotNetEnv.Configuration; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using RelationshipAnalysis.Context; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace RelationAnalysis.Migrations | ||
{ | ||
public class ConsoleStartup | ||
{ | ||
public IConfiguration Configuration { get; } = new ConfigurationBuilder() | ||
.AddEnvironmentVariables() | ||
.Build(); | ||
public ConsoleStartup() | ||
{ | ||
|
||
//.. for test | ||
Console.WriteLine(Configuration["CONNECTION_STRING"]); | ||
} | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
|
||
services.AddDbContext<ApplicationDbContext>(options => | ||
{ | ||
options.UseNpgsql(Configuration["CONNECTION_STRING"]).UseLazyLoadingProxies(); | ||
}); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.EntityFrameworkCore; | ||
using DotNetEnv; | ||
using RelationshipAnalysis.Context; | ||
|
||
namespace RelationAnalysis.Migrations | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Applying migrations"); | ||
var webHost = new WebHostBuilder() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseStartup<ConsoleStartup>() | ||
.Build(); | ||
|
||
using (var context = (ApplicationDbContext) webHost.Services.GetService(typeof(ApplicationDbContext))) | ||
{ | ||
context.Database.Migrate(); | ||
} | ||
Console.WriteLine("Done"); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
RelationAnalysis.Migrations/RelationAnalysis.Migrations.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Dotenv" Version="0.0.1.1" /> | ||
<PackageReference Include="DotNetEnv" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Microsoft.AspNetCore.Hosting"> | ||
<HintPath>..\..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\8.0.8\Microsoft.AspNetCore.Hosting.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.Extensions.Configuration"> | ||
<HintPath>..\..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\8.0.8\Microsoft.Extensions.Configuration.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RelationshipAnalysis\RelationshipAnalysis.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...818110538_Graph models Update.Designer.cs → ...ations/20240818162120_initial.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters