Обновил подключение к бд
This commit is contained in:
parent
46295b1884
commit
67e5d51014
@ -8,7 +8,7 @@ public static class ServicesExtensions
|
||||
public static void AddDbContextWithDefaultConfiguration<TDbContext>(this WebApplicationBuilder builder) where TDbContext : DbContext
|
||||
{
|
||||
builder.Services.AddDbContext<TDbContext>(
|
||||
optionsBuilder => optionsBuilder.UseNpgsql("prod", npgsqlBuilder =>
|
||||
optionsBuilder => optionsBuilder.UseNpgsql(builder.Configuration["DATABASE"], npgsqlBuilder =>
|
||||
npgsqlBuilder.MigrationsAssembly(typeof(Program).Assembly.GetName().Name)));
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace HackathonPreparing.ApiService.Migrations
|
||||
{
|
||||
[DbContext(typeof(UserContext))]
|
||||
[Migration("20240619195157_UserContextMigration")]
|
||||
[Migration("20240621094038_UserContextMigration")]
|
||||
partial class UserContextMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -26,7 +26,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.AuthFeature.User", b =>
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.Features.AuthFeature.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -96,7 +96,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
b.ToTable("AspNetUsers", "user");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b =>
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.Features.WeatherForecastFeature.WeatherForecast", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -122,37 +122,37 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
Date = new DateOnly(2024, 6, 20),
|
||||
Summary = "Chilly",
|
||||
TemperatureC = -12
|
||||
Date = new DateOnly(2024, 6, 22),
|
||||
Summary = "Sweltering",
|
||||
TemperatureC = -3
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 2,
|
||||
Date = new DateOnly(2024, 6, 21),
|
||||
Summary = "Chilly",
|
||||
TemperatureC = 41
|
||||
Date = new DateOnly(2024, 6, 23),
|
||||
Summary = "Freezing",
|
||||
TemperatureC = 46
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 3,
|
||||
Date = new DateOnly(2024, 6, 22),
|
||||
Summary = "Freezing",
|
||||
TemperatureC = 5
|
||||
Date = new DateOnly(2024, 6, 24),
|
||||
Summary = "Bracing",
|
||||
TemperatureC = 21
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 4,
|
||||
Date = new DateOnly(2024, 6, 23),
|
||||
Summary = "Sweltering",
|
||||
TemperatureC = 40
|
||||
Date = new DateOnly(2024, 6, 25),
|
||||
Summary = "Bracing",
|
||||
TemperatureC = -14
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 5,
|
||||
Date = new DateOnly(2024, 6, 24),
|
||||
Summary = "Scorching",
|
||||
TemperatureC = 40
|
||||
Date = new DateOnly(2024, 6, 26),
|
||||
Summary = "Hot",
|
||||
TemperatureC = -15
|
||||
});
|
||||
});
|
||||
|
||||
@ -188,7 +188,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
ConcurrencyStamp = "8ded6932-88b3-4542-a741-ecd3734c0857",
|
||||
ConcurrencyStamp = "b6604d84-0a9e-4d18-8273-9b109e229f38",
|
||||
Name = "moderator",
|
||||
NormalizedName = "MODERATOR"
|
||||
});
|
||||
@ -308,7 +308,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>
|
||||
{
|
||||
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null)
|
||||
b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -317,7 +317,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>
|
||||
{
|
||||
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null)
|
||||
b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -332,7 +332,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null)
|
||||
b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -341,7 +341,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>
|
||||
{
|
||||
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null)
|
||||
b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
@ -198,7 +198,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
schema: "user",
|
||||
table: "AspNetRoles",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||
values: new object[] { 1, "8ded6932-88b3-4542-a741-ecd3734c0857", "moderator", "MODERATOR" });
|
||||
values: new object[] { 1, "b6604d84-0a9e-4d18-8273-9b109e229f38", "moderator", "MODERATOR" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
schema: "user",
|
||||
@ -206,11 +206,11 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
columns: new[] { "Id", "Date", "Summary", "TemperatureC" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 1, new DateOnly(2024, 6, 20), "Chilly", -12 },
|
||||
{ 2, new DateOnly(2024, 6, 21), "Chilly", 41 },
|
||||
{ 3, new DateOnly(2024, 6, 22), "Freezing", 5 },
|
||||
{ 4, new DateOnly(2024, 6, 23), "Sweltering", 40 },
|
||||
{ 5, new DateOnly(2024, 6, 24), "Scorching", 40 }
|
||||
{ 1, new DateOnly(2024, 6, 22), "Sweltering", -3 },
|
||||
{ 2, new DateOnly(2024, 6, 23), "Freezing", 46 },
|
||||
{ 3, new DateOnly(2024, 6, 24), "Bracing", 21 },
|
||||
{ 4, new DateOnly(2024, 6, 25), "Bracing", -14 },
|
||||
{ 5, new DateOnly(2024, 6, 26), "Hot", -15 }
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
@ -23,7 +23,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.AuthFeature.User", b =>
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.Features.AuthFeature.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -93,7 +93,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
b.ToTable("AspNetUsers", "user");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b =>
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.Features.WeatherForecastFeature.WeatherForecast", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -119,37 +119,37 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
Date = new DateOnly(2024, 6, 20),
|
||||
Summary = "Chilly",
|
||||
TemperatureC = -12
|
||||
Date = new DateOnly(2024, 6, 22),
|
||||
Summary = "Sweltering",
|
||||
TemperatureC = -3
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 2,
|
||||
Date = new DateOnly(2024, 6, 21),
|
||||
Summary = "Chilly",
|
||||
TemperatureC = 41
|
||||
Date = new DateOnly(2024, 6, 23),
|
||||
Summary = "Freezing",
|
||||
TemperatureC = 46
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 3,
|
||||
Date = new DateOnly(2024, 6, 22),
|
||||
Summary = "Freezing",
|
||||
TemperatureC = 5
|
||||
Date = new DateOnly(2024, 6, 24),
|
||||
Summary = "Bracing",
|
||||
TemperatureC = 21
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 4,
|
||||
Date = new DateOnly(2024, 6, 23),
|
||||
Summary = "Sweltering",
|
||||
TemperatureC = 40
|
||||
Date = new DateOnly(2024, 6, 25),
|
||||
Summary = "Bracing",
|
||||
TemperatureC = -14
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 5,
|
||||
Date = new DateOnly(2024, 6, 24),
|
||||
Summary = "Scorching",
|
||||
TemperatureC = 40
|
||||
Date = new DateOnly(2024, 6, 26),
|
||||
Summary = "Hot",
|
||||
TemperatureC = -15
|
||||
});
|
||||
});
|
||||
|
||||
@ -185,7 +185,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
ConcurrencyStamp = "8ded6932-88b3-4542-a741-ecd3734c0857",
|
||||
ConcurrencyStamp = "b6604d84-0a9e-4d18-8273-9b109e229f38",
|
||||
Name = "moderator",
|
||||
NormalizedName = "MODERATOR"
|
||||
});
|
||||
@ -305,7 +305,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>
|
||||
{
|
||||
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null)
|
||||
b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -314,7 +314,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>
|
||||
{
|
||||
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null)
|
||||
b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -329,7 +329,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null)
|
||||
b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -338,7 +338,7 @@ namespace HackathonPreparing.ApiService.Migrations
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>
|
||||
{
|
||||
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null)
|
||||
b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
|
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
|
||||
{
|
||||
[DbContext(typeof(WeatherForecastContext))]
|
||||
[Migration("20240619195229_WeatherForecastContextMigration")]
|
||||
[Migration("20240621100828_WeatherForecastContextMigration")]
|
||||
partial class WeatherForecastContextMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -26,7 +26,7 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b =>
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.Features.WeatherForecastFeature.WeatherForecast", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -52,37 +52,37 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
Date = new DateOnly(2024, 6, 20),
|
||||
Summary = "Balmy",
|
||||
TemperatureC = -7
|
||||
Date = new DateOnly(2024, 6, 22),
|
||||
Summary = "Cool",
|
||||
TemperatureC = 38
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 2,
|
||||
Date = new DateOnly(2024, 6, 21),
|
||||
Summary = "Warm",
|
||||
TemperatureC = -5
|
||||
Date = new DateOnly(2024, 6, 23),
|
||||
Summary = "Cool",
|
||||
TemperatureC = 24
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 3,
|
||||
Date = new DateOnly(2024, 6, 22),
|
||||
Summary = "Freezing",
|
||||
TemperatureC = 23
|
||||
Date = new DateOnly(2024, 6, 24),
|
||||
Summary = "Chilly",
|
||||
TemperatureC = 36
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 4,
|
||||
Date = new DateOnly(2024, 6, 23),
|
||||
Summary = "Balmy",
|
||||
TemperatureC = -20
|
||||
Date = new DateOnly(2024, 6, 25),
|
||||
Summary = "Bracing",
|
||||
TemperatureC = -5
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 5,
|
||||
Date = new DateOnly(2024, 6, 24),
|
||||
Summary = "Mild",
|
||||
TemperatureC = -12
|
||||
Date = new DateOnly(2024, 6, 26),
|
||||
Summary = "Freezing",
|
||||
TemperatureC = 7
|
||||
});
|
||||
});
|
||||
|
||||
@ -111,7 +111,7 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
ConcurrencyStamp = "5203886a-ebdc-407b-858f-63f149ce22f0",
|
||||
ConcurrencyStamp = "66150c17-e6f7-466b-aef2-44e0afa8182f",
|
||||
Name = "moderator",
|
||||
NormalizedName = "MODERATOR"
|
||||
});
|
@ -54,18 +54,18 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
|
||||
columns: new[] { "Id", "Date", "Summary", "TemperatureC" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 1, new DateOnly(2024, 6, 20), "Balmy", -7 },
|
||||
{ 2, new DateOnly(2024, 6, 21), "Warm", -5 },
|
||||
{ 3, new DateOnly(2024, 6, 22), "Freezing", 23 },
|
||||
{ 4, new DateOnly(2024, 6, 23), "Balmy", -20 },
|
||||
{ 5, new DateOnly(2024, 6, 24), "Mild", -12 }
|
||||
{ 1, new DateOnly(2024, 6, 22), "Cool", 38 },
|
||||
{ 2, new DateOnly(2024, 6, 23), "Cool", 24 },
|
||||
{ 3, new DateOnly(2024, 6, 24), "Chilly", 36 },
|
||||
{ 4, new DateOnly(2024, 6, 25), "Bracing", -5 },
|
||||
{ 5, new DateOnly(2024, 6, 26), "Freezing", 7 }
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
schema: "weatherforecast",
|
||||
table: "IdentityRole<int>",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||
values: new object[] { 1, "5203886a-ebdc-407b-858f-63f149ce22f0", "moderator", "MODERATOR" });
|
||||
values: new object[] { 1, "66150c17-e6f7-466b-aef2-44e0afa8182f", "moderator", "MODERATOR" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
@ -23,7 +23,7 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b =>
|
||||
modelBuilder.Entity("HackathonPreparing.ApiService.Features.WeatherForecastFeature.WeatherForecast", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -49,37 +49,37 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
Date = new DateOnly(2024, 6, 20),
|
||||
Summary = "Balmy",
|
||||
TemperatureC = -7
|
||||
Date = new DateOnly(2024, 6, 22),
|
||||
Summary = "Cool",
|
||||
TemperatureC = 38
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 2,
|
||||
Date = new DateOnly(2024, 6, 21),
|
||||
Summary = "Warm",
|
||||
TemperatureC = -5
|
||||
Date = new DateOnly(2024, 6, 23),
|
||||
Summary = "Cool",
|
||||
TemperatureC = 24
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 3,
|
||||
Date = new DateOnly(2024, 6, 22),
|
||||
Summary = "Freezing",
|
||||
TemperatureC = 23
|
||||
Date = new DateOnly(2024, 6, 24),
|
||||
Summary = "Chilly",
|
||||
TemperatureC = 36
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 4,
|
||||
Date = new DateOnly(2024, 6, 23),
|
||||
Summary = "Balmy",
|
||||
TemperatureC = -20
|
||||
Date = new DateOnly(2024, 6, 25),
|
||||
Summary = "Bracing",
|
||||
TemperatureC = -5
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 5,
|
||||
Date = new DateOnly(2024, 6, 24),
|
||||
Summary = "Mild",
|
||||
TemperatureC = -12
|
||||
Date = new DateOnly(2024, 6, 26),
|
||||
Summary = "Freezing",
|
||||
TemperatureC = 7
|
||||
});
|
||||
});
|
||||
|
||||
@ -108,7 +108,7 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
ConcurrencyStamp = "5203886a-ebdc-407b-858f-63f149ce22f0",
|
||||
ConcurrencyStamp = "66150c17-e6f7-466b-aef2-44e0afa8182f",
|
||||
Name = "moderator",
|
||||
NormalizedName = "MODERATOR"
|
||||
});
|
||||
|
@ -5,8 +5,5 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"prod": "User ID=root;Password=DAm4qdJ7VZ*pS8zcF9pRrRt^;Host=192.168.111.242;Port=5432;Database=prod;"
|
||||
}
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
10
README.md
10
README.md
@ -49,11 +49,21 @@ database:prod
|
||||
|
||||
Если нет миграций в проекте то в папке HackathonPreparing.ApiService нужно писать:
|
||||
|
||||
```sh
|
||||
dotnet ef migrations add UserContextMigration --context UserContext
|
||||
dotnet ef database update --context UserContext
|
||||
|
||||
dotnet ef migrations add WeatherForecastContextMigration --context WeatherForecastContext
|
||||
dotnet ef database update --context WeatherForecastContext
|
||||
```
|
||||
|
||||
```ps
|
||||
dotnet-ef.exe migrations add UserContextMigration --context UserContext
|
||||
dotnet-ef.exe database update --context UserContext
|
||||
|
||||
dotnet-ef.exe migrations add WeatherForecastContextMigration --context WeatherForecastContext
|
||||
dotnet-ef.exe database update --context WeatherForecastContext
|
||||
```
|
||||
|
||||
И так для каждого DbContext в проекте
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user