Обновил подключение к бд
All checks were successful
Lint / Run linters (push) Successful in 37s
Build and deploy / Publish image (push) Successful in 1m53s
Build and deploy / Deploy image (push) Successful in 11s

This commit is contained in:
Sergey Karmanov 2024-06-21 13:10:38 +03:00
parent 46295b1884
commit 67e5d51014
9 changed files with 104 additions and 97 deletions

View File

@ -8,7 +8,7 @@ public static class ServicesExtensions
public static void AddDbContextWithDefaultConfiguration<TDbContext>(this WebApplicationBuilder builder) where TDbContext : DbContext public static void AddDbContextWithDefaultConfiguration<TDbContext>(this WebApplicationBuilder builder) where TDbContext : DbContext
{ {
builder.Services.AddDbContext<TDbContext>( builder.Services.AddDbContext<TDbContext>(
optionsBuilder => optionsBuilder.UseNpgsql("prod", npgsqlBuilder => optionsBuilder => optionsBuilder.UseNpgsql(builder.Configuration["DATABASE"], npgsqlBuilder =>
npgsqlBuilder.MigrationsAssembly(typeof(Program).Assembly.GetName().Name))); npgsqlBuilder.MigrationsAssembly(typeof(Program).Assembly.GetName().Name)));
} }

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace HackathonPreparing.ApiService.Migrations namespace HackathonPreparing.ApiService.Migrations
{ {
[DbContext(typeof(UserContext))] [DbContext(typeof(UserContext))]
[Migration("20240619195157_UserContextMigration")] [Migration("20240621094038_UserContextMigration")]
partial class UserContextMigration partial class UserContextMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -26,7 +26,7 @@ namespace HackathonPreparing.ApiService.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("HackathonPreparing.ApiService.AuthFeature.User", b => modelBuilder.Entity("HackathonPreparing.ApiService.Features.AuthFeature.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -96,7 +96,7 @@ namespace HackathonPreparing.ApiService.Migrations
b.ToTable("AspNetUsers", "user"); b.ToTable("AspNetUsers", "user");
}); });
modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b => modelBuilder.Entity("HackathonPreparing.ApiService.Features.WeatherForecastFeature.WeatherForecast", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -122,37 +122,37 @@ namespace HackathonPreparing.ApiService.Migrations
new new
{ {
Id = 1, Id = 1,
Date = new DateOnly(2024, 6, 20), Date = new DateOnly(2024, 6, 22),
Summary = "Chilly", Summary = "Sweltering",
TemperatureC = -12 TemperatureC = -3
}, },
new new
{ {
Id = 2, Id = 2,
Date = new DateOnly(2024, 6, 21), Date = new DateOnly(2024, 6, 23),
Summary = "Chilly", Summary = "Freezing",
TemperatureC = 41 TemperatureC = 46
}, },
new new
{ {
Id = 3, Id = 3,
Date = new DateOnly(2024, 6, 22), Date = new DateOnly(2024, 6, 24),
Summary = "Freezing", Summary = "Bracing",
TemperatureC = 5 TemperatureC = 21
}, },
new new
{ {
Id = 4, Id = 4,
Date = new DateOnly(2024, 6, 23), Date = new DateOnly(2024, 6, 25),
Summary = "Sweltering", Summary = "Bracing",
TemperatureC = 40 TemperatureC = -14
}, },
new new
{ {
Id = 5, Id = 5,
Date = new DateOnly(2024, 6, 24), Date = new DateOnly(2024, 6, 26),
Summary = "Scorching", Summary = "Hot",
TemperatureC = 40 TemperatureC = -15
}); });
}); });
@ -188,7 +188,7 @@ namespace HackathonPreparing.ApiService.Migrations
new new
{ {
Id = 1, Id = 1,
ConcurrencyStamp = "8ded6932-88b3-4542-a741-ecd3734c0857", ConcurrencyStamp = "b6604d84-0a9e-4d18-8273-9b109e229f38",
Name = "moderator", Name = "moderator",
NormalizedName = "MODERATOR" NormalizedName = "MODERATOR"
}); });
@ -308,7 +308,7 @@ namespace HackathonPreparing.ApiService.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>
{ {
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@ -317,7 +317,7 @@ namespace HackathonPreparing.ApiService.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>
{ {
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@ -332,7 +332,7 @@ namespace HackathonPreparing.ApiService.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@ -341,7 +341,7 @@ namespace HackathonPreparing.ApiService.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>
{ {
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)

View File

@ -198,7 +198,7 @@ namespace HackathonPreparing.ApiService.Migrations
schema: "user", schema: "user",
table: "AspNetRoles", table: "AspNetRoles",
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, 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( migrationBuilder.InsertData(
schema: "user", schema: "user",
@ -206,11 +206,11 @@ namespace HackathonPreparing.ApiService.Migrations
columns: new[] { "Id", "Date", "Summary", "TemperatureC" }, columns: new[] { "Id", "Date", "Summary", "TemperatureC" },
values: new object[,] values: new object[,]
{ {
{ 1, new DateOnly(2024, 6, 20), "Chilly", -12 }, { 1, new DateOnly(2024, 6, 22), "Sweltering", -3 },
{ 2, new DateOnly(2024, 6, 21), "Chilly", 41 }, { 2, new DateOnly(2024, 6, 23), "Freezing", 46 },
{ 3, new DateOnly(2024, 6, 22), "Freezing", 5 }, { 3, new DateOnly(2024, 6, 24), "Bracing", 21 },
{ 4, new DateOnly(2024, 6, 23), "Sweltering", 40 }, { 4, new DateOnly(2024, 6, 25), "Bracing", -14 },
{ 5, new DateOnly(2024, 6, 24), "Scorching", 40 } { 5, new DateOnly(2024, 6, 26), "Hot", -15 }
}); });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(

View File

@ -23,7 +23,7 @@ namespace HackathonPreparing.ApiService.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("HackathonPreparing.ApiService.AuthFeature.User", b => modelBuilder.Entity("HackathonPreparing.ApiService.Features.AuthFeature.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -93,7 +93,7 @@ namespace HackathonPreparing.ApiService.Migrations
b.ToTable("AspNetUsers", "user"); b.ToTable("AspNetUsers", "user");
}); });
modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b => modelBuilder.Entity("HackathonPreparing.ApiService.Features.WeatherForecastFeature.WeatherForecast", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -119,37 +119,37 @@ namespace HackathonPreparing.ApiService.Migrations
new new
{ {
Id = 1, Id = 1,
Date = new DateOnly(2024, 6, 20), Date = new DateOnly(2024, 6, 22),
Summary = "Chilly", Summary = "Sweltering",
TemperatureC = -12 TemperatureC = -3
}, },
new new
{ {
Id = 2, Id = 2,
Date = new DateOnly(2024, 6, 21), Date = new DateOnly(2024, 6, 23),
Summary = "Chilly", Summary = "Freezing",
TemperatureC = 41 TemperatureC = 46
}, },
new new
{ {
Id = 3, Id = 3,
Date = new DateOnly(2024, 6, 22), Date = new DateOnly(2024, 6, 24),
Summary = "Freezing", Summary = "Bracing",
TemperatureC = 5 TemperatureC = 21
}, },
new new
{ {
Id = 4, Id = 4,
Date = new DateOnly(2024, 6, 23), Date = new DateOnly(2024, 6, 25),
Summary = "Sweltering", Summary = "Bracing",
TemperatureC = 40 TemperatureC = -14
}, },
new new
{ {
Id = 5, Id = 5,
Date = new DateOnly(2024, 6, 24), Date = new DateOnly(2024, 6, 26),
Summary = "Scorching", Summary = "Hot",
TemperatureC = 40 TemperatureC = -15
}); });
}); });
@ -185,7 +185,7 @@ namespace HackathonPreparing.ApiService.Migrations
new new
{ {
Id = 1, Id = 1,
ConcurrencyStamp = "8ded6932-88b3-4542-a741-ecd3734c0857", ConcurrencyStamp = "b6604d84-0a9e-4d18-8273-9b109e229f38",
Name = "moderator", Name = "moderator",
NormalizedName = "MODERATOR" NormalizedName = "MODERATOR"
}); });
@ -305,7 +305,7 @@ namespace HackathonPreparing.ApiService.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>
{ {
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@ -314,7 +314,7 @@ namespace HackathonPreparing.ApiService.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>
{ {
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@ -329,7 +329,7 @@ namespace HackathonPreparing.ApiService.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@ -338,7 +338,7 @@ namespace HackathonPreparing.ApiService.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>
{ {
b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) b.HasOne("HackathonPreparing.ApiService.Features.AuthFeature.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace HackathonPreparing.ApiService.Migrations.WeatherForecast namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
{ {
[DbContext(typeof(WeatherForecastContext))] [DbContext(typeof(WeatherForecastContext))]
[Migration("20240619195229_WeatherForecastContextMigration")] [Migration("20240621100828_WeatherForecastContextMigration")]
partial class WeatherForecastContextMigration partial class WeatherForecastContextMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -26,7 +26,7 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b => modelBuilder.Entity("HackathonPreparing.ApiService.Features.WeatherForecastFeature.WeatherForecast", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -52,37 +52,37 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
new new
{ {
Id = 1, Id = 1,
Date = new DateOnly(2024, 6, 20), Date = new DateOnly(2024, 6, 22),
Summary = "Balmy", Summary = "Cool",
TemperatureC = -7 TemperatureC = 38
}, },
new new
{ {
Id = 2, Id = 2,
Date = new DateOnly(2024, 6, 21), Date = new DateOnly(2024, 6, 23),
Summary = "Warm", Summary = "Cool",
TemperatureC = -5 TemperatureC = 24
}, },
new new
{ {
Id = 3, Id = 3,
Date = new DateOnly(2024, 6, 22), Date = new DateOnly(2024, 6, 24),
Summary = "Freezing", Summary = "Chilly",
TemperatureC = 23 TemperatureC = 36
}, },
new new
{ {
Id = 4, Id = 4,
Date = new DateOnly(2024, 6, 23), Date = new DateOnly(2024, 6, 25),
Summary = "Balmy", Summary = "Bracing",
TemperatureC = -20 TemperatureC = -5
}, },
new new
{ {
Id = 5, Id = 5,
Date = new DateOnly(2024, 6, 24), Date = new DateOnly(2024, 6, 26),
Summary = "Mild", Summary = "Freezing",
TemperatureC = -12 TemperatureC = 7
}); });
}); });
@ -111,7 +111,7 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
new new
{ {
Id = 1, Id = 1,
ConcurrencyStamp = "5203886a-ebdc-407b-858f-63f149ce22f0", ConcurrencyStamp = "66150c17-e6f7-466b-aef2-44e0afa8182f",
Name = "moderator", Name = "moderator",
NormalizedName = "MODERATOR" NormalizedName = "MODERATOR"
}); });

View File

@ -54,18 +54,18 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
columns: new[] { "Id", "Date", "Summary", "TemperatureC" }, columns: new[] { "Id", "Date", "Summary", "TemperatureC" },
values: new object[,] values: new object[,]
{ {
{ 1, new DateOnly(2024, 6, 20), "Balmy", -7 }, { 1, new DateOnly(2024, 6, 22), "Cool", 38 },
{ 2, new DateOnly(2024, 6, 21), "Warm", -5 }, { 2, new DateOnly(2024, 6, 23), "Cool", 24 },
{ 3, new DateOnly(2024, 6, 22), "Freezing", 23 }, { 3, new DateOnly(2024, 6, 24), "Chilly", 36 },
{ 4, new DateOnly(2024, 6, 23), "Balmy", -20 }, { 4, new DateOnly(2024, 6, 25), "Bracing", -5 },
{ 5, new DateOnly(2024, 6, 24), "Mild", -12 } { 5, new DateOnly(2024, 6, 26), "Freezing", 7 }
}); });
migrationBuilder.InsertData( migrationBuilder.InsertData(
schema: "weatherforecast", schema: "weatherforecast",
table: "IdentityRole<int>", table: "IdentityRole<int>",
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, 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 /> /// <inheritdoc />

View File

@ -23,7 +23,7 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b => modelBuilder.Entity("HackathonPreparing.ApiService.Features.WeatherForecastFeature.WeatherForecast", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -49,37 +49,37 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
new new
{ {
Id = 1, Id = 1,
Date = new DateOnly(2024, 6, 20), Date = new DateOnly(2024, 6, 22),
Summary = "Balmy", Summary = "Cool",
TemperatureC = -7 TemperatureC = 38
}, },
new new
{ {
Id = 2, Id = 2,
Date = new DateOnly(2024, 6, 21), Date = new DateOnly(2024, 6, 23),
Summary = "Warm", Summary = "Cool",
TemperatureC = -5 TemperatureC = 24
}, },
new new
{ {
Id = 3, Id = 3,
Date = new DateOnly(2024, 6, 22), Date = new DateOnly(2024, 6, 24),
Summary = "Freezing", Summary = "Chilly",
TemperatureC = 23 TemperatureC = 36
}, },
new new
{ {
Id = 4, Id = 4,
Date = new DateOnly(2024, 6, 23), Date = new DateOnly(2024, 6, 25),
Summary = "Balmy", Summary = "Bracing",
TemperatureC = -20 TemperatureC = -5
}, },
new new
{ {
Id = 5, Id = 5,
Date = new DateOnly(2024, 6, 24), Date = new DateOnly(2024, 6, 26),
Summary = "Mild", Summary = "Freezing",
TemperatureC = -12 TemperatureC = 7
}); });
}); });
@ -108,7 +108,7 @@ namespace HackathonPreparing.ApiService.Migrations.WeatherForecast
new new
{ {
Id = 1, Id = 1,
ConcurrencyStamp = "5203886a-ebdc-407b-858f-63f149ce22f0", ConcurrencyStamp = "66150c17-e6f7-466b-aef2-44e0afa8182f",
Name = "moderator", Name = "moderator",
NormalizedName = "MODERATOR" NormalizedName = "MODERATOR"
}); });

View File

@ -5,8 +5,5 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*"
"ConnectionStrings": {
"prod": "User ID=root;Password=DAm4qdJ7VZ*pS8zcF9pRrRt^;Host=192.168.111.242;Port=5432;Database=prod;"
}
} }

View File

@ -49,11 +49,21 @@ database:prod
Если нет миграций в проекте то в папке HackathonPreparing.ApiService нужно писать: Если нет миграций в проекте то в папке HackathonPreparing.ApiService нужно писать:
```sh
dotnet ef migrations add UserContextMigration --context UserContext dotnet ef migrations add UserContextMigration --context UserContext
dotnet ef database update --context UserContext dotnet ef database update --context UserContext
dotnet ef migrations add WeatherForecastContextMigration --context WeatherForecastContext dotnet ef migrations add WeatherForecastContextMigration --context WeatherForecastContext
dotnet ef database update --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 в проекте И так для каждого DbContext в проекте