Создал миграции и настроил класс Program

parent 50c64b42
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Payment.WebApi.Infrastructures.Databases;
#nullable disable
namespace Payment.WebApi.Migrations
{
[DbContext(typeof(PaymentDbContext))]
[Migration("20220706141914_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Payment.WebApi.Models.DbModels.Supplier", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
b.HasData(
new
{
Id = 1,
Name = "Алсеко"
},
new
{
Id = 2,
Name = "Казактелеком"
},
new
{
Id = 3,
Name = "Beeline"
});
});
modelBuilder.Entity("Payment.WebApi.Models.DbModels.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MiddleName")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
b.HasData(
new
{
Id = 1,
Age = 25,
FirstName = "Jhon",
LastName = "Doe",
MiddleName = "Blastovich"
},
new
{
Id = 2,
Age = 27,
FirstName = "Jhoan",
LastName = "Shepard"
});
});
modelBuilder.Entity("Payment.WebApi.Models.DbModels.UserBalance", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<decimal>("Amount")
.HasColumnType("numeric");
b.Property<string>("Currency")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserBalance");
b.HasData(
new
{
Id = 1,
Amount = 100m,
Currency = "KZT",
UserId = 1
},
new
{
Id = 2,
Amount = 250m,
Currency = "KZT",
UserId = 2
});
});
modelBuilder.Entity("Payment.WebApi.Models.DbModels.UserBalance", b =>
{
b.HasOne("Payment.WebApi.Models.DbModels.User", "User")
.WithMany("Balances")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Payment.WebApi.Models.DbModels.User", b =>
{
b.Navigation("Balances");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Payment.WebApi.Migrations
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Suppliers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Suppliers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FirstName = table.Column<string>(type: "text", nullable: false),
LastName = table.Column<string>(type: "text", nullable: false),
MiddleName = table.Column<string>(type: "text", nullable: true),
Age = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UserBalance",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Amount = table.Column<decimal>(type: "numeric", nullable: false),
Currency = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserBalance", x => x.Id);
table.ForeignKey(
name: "FK_UserBalance_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "Suppliers",
columns: new[] { "Id", "Name" },
values: new object[,]
{
{ 1, "Алсеко" },
{ 2, "Казактелеком" },
{ 3, "Beeline" }
});
migrationBuilder.InsertData(
table: "Users",
columns: new[] { "Id", "Age", "FirstName", "LastName", "MiddleName" },
values: new object[,]
{
{ 1, 25, "Jhon", "Doe", "Blastovich" },
{ 2, 27, "Jhoan", "Shepard", null }
});
migrationBuilder.InsertData(
table: "UserBalance",
columns: new[] { "Id", "Amount", "Currency", "UserId" },
values: new object[,]
{
{ 1, 100m, "KZT", 1 },
{ 2, 250m, "KZT", 2 }
});
migrationBuilder.CreateIndex(
name: "IX_UserBalance_UserId",
table: "UserBalance",
column: "UserId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Suppliers");
migrationBuilder.DropTable(
name: "UserBalance");
migrationBuilder.DropTable(
name: "Users");
}
}
}
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Payment.WebApi.Infrastructures.Databases;
#nullable disable
namespace Payment.WebApi.Migrations
{
[DbContext(typeof(PaymentDbContext))]
partial class PaymentDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Payment.WebApi.Models.DbModels.Supplier", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
b.HasData(
new
{
Id = 1,
Name = "Алсеко"
},
new
{
Id = 2,
Name = "Казактелеком"
},
new
{
Id = 3,
Name = "Beeline"
});
});
modelBuilder.Entity("Payment.WebApi.Models.DbModels.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("MiddleName")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
b.HasData(
new
{
Id = 1,
Age = 25,
FirstName = "Jhon",
LastName = "Doe",
MiddleName = "Blastovich"
},
new
{
Id = 2,
Age = 27,
FirstName = "Jhoan",
LastName = "Shepard"
});
});
modelBuilder.Entity("Payment.WebApi.Models.DbModels.UserBalance", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<decimal>("Amount")
.HasColumnType("numeric");
b.Property<string>("Currency")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserBalance");
b.HasData(
new
{
Id = 1,
Amount = 100m,
Currency = "KZT",
UserId = 1
},
new
{
Id = 2,
Amount = 250m,
Currency = "KZT",
UserId = 2
});
});
modelBuilder.Entity("Payment.WebApi.Models.DbModels.UserBalance", b =>
{
b.HasOne("Payment.WebApi.Models.DbModels.User", "User")
.WithMany("Balances")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Payment.WebApi.Models.DbModels.User", b =>
{
b.Navigation("Balances");
});
#pragma warning restore 612, 618
}
}
}
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Controllers" />
</ItemGroup>
</Project> </Project>
using Payment.WebApi.Extensions;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllers(); var services = builder.Services;
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); services.AddControllers();
builder.Services.AddSwaggerGen();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
services.AddAppServices(builder.Configuration);
var app = builder.Build(); var app = builder.Build();
......
...@@ -5,5 +5,8 @@ ...@@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"ConnectionStrings": {
"ConnectionString" : "Server=localhost;Port=5432;Database=Payments;UserId=postgres"
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment