diff --git a/.gitignore b/.gitignore index ed7bc38..82f3d28 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ bld/ [Ll]og/ [Ll]ogs/ -Migrations/ VolumeMount.AppHost-postgresql-data/ # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/20240619195157_UserContextMigration.Designer.cs b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/20240619195157_UserContextMigration.Designer.cs new file mode 100644 index 0000000..bef113c --- /dev/null +++ b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/20240619195157_UserContextMigration.Designer.cs @@ -0,0 +1,353 @@ +// +using System; +using HackathonPreparing.ApiService.AuthFeature.EfCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HackathonPreparing.ApiService.Migrations +{ + [DbContext(typeof(UserContext))] + [Migration("20240619195157_UserContextMigration")] + partial class UserContextMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("user") + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HackathonPreparing.ApiService.AuthFeature.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AboutMe") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", "user"); + }); + + modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Summary") + .IsRequired() + .HasColumnType("text"); + + b.Property("TemperatureC") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("WeatherForecast", "user"); + + b.HasData( + new + { + Id = 1, + Date = new DateOnly(2024, 6, 20), + Summary = "Chilly", + TemperatureC = -12 + }, + new + { + Id = 2, + Date = new DateOnly(2024, 6, 21), + Summary = "Chilly", + TemperatureC = 41 + }, + new + { + Id = 3, + Date = new DateOnly(2024, 6, 22), + Summary = "Freezing", + TemperatureC = 5 + }, + new + { + Id = 4, + Date = new DateOnly(2024, 6, 23), + Summary = "Sweltering", + TemperatureC = 40 + }, + new + { + Id = 5, + Date = new DateOnly(2024, 6, 24), + Summary = "Scorching", + TemperatureC = 40 + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", "user"); + + b.HasData( + new + { + Id = 1, + ConcurrencyStamp = "8ded6932-88b3-4542-a741-ecd3734c0857", + Name = "moderator", + NormalizedName = "MODERATOR" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/20240619195157_UserContextMigration.cs b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/20240619195157_UserContextMigration.cs new file mode 100644 index 0000000..8a0208e --- /dev/null +++ b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/20240619195157_UserContextMigration.cs @@ -0,0 +1,297 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace HackathonPreparing.ApiService.Migrations +{ + /// + public partial class UserContextMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "user"); + + migrationBuilder.CreateTable( + name: "AspNetRoles", + schema: "user", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + schema: "user", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + AboutMe = table.Column(type: "text", nullable: true), + TwoFactorEnabled = table.Column(type: "boolean", nullable: false), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "boolean", nullable: false), + PasswordHash = table.Column(type: "text", nullable: true), + SecurityStamp = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true), + PhoneNumber = table.Column(type: "text", nullable: true), + PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), + LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), + LockoutEnabled = table.Column(type: "boolean", nullable: false), + AccessFailedCount = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "WeatherForecast", + schema: "user", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "date", nullable: false), + TemperatureC = table.Column(type: "integer", nullable: false), + Summary = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WeatherForecast", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + schema: "user", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RoleId = table.Column(type: "integer", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalSchema: "user", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + schema: "user", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "integer", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalSchema: "user", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + schema: "user", + columns: table => new + { + LoginProvider = table.Column(type: "text", nullable: false), + ProviderKey = table.Column(type: "text", nullable: false), + ProviderDisplayName = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalSchema: "user", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + schema: "user", + columns: table => new + { + UserId = table.Column(type: "integer", nullable: false), + RoleId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalSchema: "user", + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalSchema: "user", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + schema: "user", + columns: table => new + { + UserId = table.Column(type: "integer", nullable: false), + LoginProvider = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalSchema: "user", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + schema: "user", + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[] { 1, "8ded6932-88b3-4542-a741-ecd3734c0857", "moderator", "MODERATOR" }); + + migrationBuilder.InsertData( + schema: "user", + table: "WeatherForecast", + 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 } + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + schema: "user", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + schema: "user", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + schema: "user", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + schema: "user", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + schema: "user", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + schema: "user", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + schema: "user", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims", + schema: "user"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims", + schema: "user"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins", + schema: "user"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles", + schema: "user"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens", + schema: "user"); + + migrationBuilder.DropTable( + name: "WeatherForecast", + schema: "user"); + + migrationBuilder.DropTable( + name: "AspNetRoles", + schema: "user"); + + migrationBuilder.DropTable( + name: "AspNetUsers", + schema: "user"); + } + } +} diff --git a/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/UserContextModelSnapshot.cs b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/UserContextModelSnapshot.cs new file mode 100644 index 0000000..5700967 --- /dev/null +++ b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/UserContextModelSnapshot.cs @@ -0,0 +1,350 @@ +// +using System; +using HackathonPreparing.ApiService.AuthFeature.EfCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HackathonPreparing.ApiService.Migrations +{ + [DbContext(typeof(UserContext))] + partial class UserContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("user") + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HackathonPreparing.ApiService.AuthFeature.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AboutMe") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", "user"); + }); + + modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Summary") + .IsRequired() + .HasColumnType("text"); + + b.Property("TemperatureC") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("WeatherForecast", "user"); + + b.HasData( + new + { + Id = 1, + Date = new DateOnly(2024, 6, 20), + Summary = "Chilly", + TemperatureC = -12 + }, + new + { + Id = 2, + Date = new DateOnly(2024, 6, 21), + Summary = "Chilly", + TemperatureC = 41 + }, + new + { + Id = 3, + Date = new DateOnly(2024, 6, 22), + Summary = "Freezing", + TemperatureC = 5 + }, + new + { + Id = 4, + Date = new DateOnly(2024, 6, 23), + Summary = "Sweltering", + TemperatureC = 40 + }, + new + { + Id = 5, + Date = new DateOnly(2024, 6, 24), + Summary = "Scorching", + TemperatureC = 40 + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", "user"); + + b.HasData( + new + { + Id = 1, + ConcurrencyStamp = "8ded6932-88b3-4542-a741-ecd3734c0857", + Name = "moderator", + NormalizedName = "MODERATOR" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", "user"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("HackathonPreparing.ApiService.AuthFeature.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/20240619195229_WeatherForecastContextMigration.Designer.cs b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/20240619195229_WeatherForecastContextMigration.Designer.cs new file mode 100644 index 0000000..851df0a --- /dev/null +++ b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/20240619195229_WeatherForecastContextMigration.Designer.cs @@ -0,0 +1,122 @@ +// +using System; +using HackathonPreparing.ApiService.WeatherForecastFeature.EfCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HackathonPreparing.ApiService.Migrations.WeatherForecast +{ + [DbContext(typeof(WeatherForecastContext))] + [Migration("20240619195229_WeatherForecastContextMigration")] + partial class WeatherForecastContextMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("weatherforecast") + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Summary") + .IsRequired() + .HasColumnType("text"); + + b.Property("TemperatureC") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Forecasts", "weatherforecast"); + + b.HasData( + new + { + Id = 1, + Date = new DateOnly(2024, 6, 20), + Summary = "Balmy", + TemperatureC = -7 + }, + new + { + Id = 2, + Date = new DateOnly(2024, 6, 21), + Summary = "Warm", + TemperatureC = -5 + }, + new + { + Id = 3, + Date = new DateOnly(2024, 6, 22), + Summary = "Freezing", + TemperatureC = 23 + }, + new + { + Id = 4, + Date = new DateOnly(2024, 6, 23), + Summary = "Balmy", + TemperatureC = -20 + }, + new + { + Id = 5, + Date = new DateOnly(2024, 6, 24), + Summary = "Mild", + TemperatureC = -12 + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConcurrencyStamp") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("NormalizedName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("IdentityRole", "weatherforecast"); + + b.HasData( + new + { + Id = 1, + ConcurrencyStamp = "5203886a-ebdc-407b-858f-63f149ce22f0", + Name = "moderator", + NormalizedName = "MODERATOR" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/20240619195229_WeatherForecastContextMigration.cs b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/20240619195229_WeatherForecastContextMigration.cs new file mode 100644 index 0000000..eb4b8e1 --- /dev/null +++ b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/20240619195229_WeatherForecastContextMigration.cs @@ -0,0 +1,84 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace HackathonPreparing.ApiService.Migrations.WeatherForecast +{ + /// + public partial class WeatherForecastContextMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "weatherforecast"); + + migrationBuilder.CreateTable( + name: "Forecasts", + schema: "weatherforecast", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "date", nullable: false), + TemperatureC = table.Column(type: "integer", nullable: false), + Summary = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Forecasts", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "IdentityRole", + schema: "weatherforecast", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: true), + NormalizedName = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_IdentityRole", x => x.Id); + }); + + migrationBuilder.InsertData( + schema: "weatherforecast", + table: "Forecasts", + 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 } + }); + + migrationBuilder.InsertData( + schema: "weatherforecast", + table: "IdentityRole", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[] { 1, "5203886a-ebdc-407b-858f-63f149ce22f0", "moderator", "MODERATOR" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Forecasts", + schema: "weatherforecast"); + + migrationBuilder.DropTable( + name: "IdentityRole", + schema: "weatherforecast"); + } + } +} diff --git a/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/WeatherForecastContextModelSnapshot.cs b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/WeatherForecastContextModelSnapshot.cs new file mode 100644 index 0000000..9ffb322 --- /dev/null +++ b/HackathonPreparing/HackathonPreparing/HackathonPreparing.ApiService/Migrations/WeatherForecast/WeatherForecastContextModelSnapshot.cs @@ -0,0 +1,119 @@ +// +using System; +using HackathonPreparing.ApiService.WeatherForecastFeature.EfCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HackathonPreparing.ApiService.Migrations.WeatherForecast +{ + [DbContext(typeof(WeatherForecastContext))] + partial class WeatherForecastContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("weatherforecast") + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HackathonPreparing.ApiService.WeatherForecastFeature.WeatherForecast", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Summary") + .IsRequired() + .HasColumnType("text"); + + b.Property("TemperatureC") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Forecasts", "weatherforecast"); + + b.HasData( + new + { + Id = 1, + Date = new DateOnly(2024, 6, 20), + Summary = "Balmy", + TemperatureC = -7 + }, + new + { + Id = 2, + Date = new DateOnly(2024, 6, 21), + Summary = "Warm", + TemperatureC = -5 + }, + new + { + Id = 3, + Date = new DateOnly(2024, 6, 22), + Summary = "Freezing", + TemperatureC = 23 + }, + new + { + Id = 4, + Date = new DateOnly(2024, 6, 23), + Summary = "Balmy", + TemperatureC = -20 + }, + new + { + Id = 5, + Date = new DateOnly(2024, 6, 24), + Summary = "Mild", + TemperatureC = -12 + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConcurrencyStamp") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("NormalizedName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("IdentityRole", "weatherforecast"); + + b.HasData( + new + { + Id = 1, + ConcurrencyStamp = "5203886a-ebdc-407b-858f-63f149ce22f0", + Name = "moderator", + NormalizedName = "MODERATOR" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/README.md b/README.md index 53d6a84..0fea791 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,30 @@ # Backend + +# ApiService + +Database connection in appsettings.json: + username:postgres + password:postgres + host:localhost + port:5432 + database:prod + + + +if no migrations + +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 + +and etc for each dbcontext in project + +if you have Migrations folder in ApiService project just call (in dev mode app) post: /api/db/migrate + +/api/swagger - path to swagger + + +