Добавил миграции для базы данных storedb

parent c566e00b
......@@ -52,7 +52,6 @@ namespace Store.Controllers
return View();
}
[HttpPost]
public IActionResult Create(Product product)
{
......
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Store.Models;
namespace Store.Migrations
{
[DbContext(typeof(ProductContext))]
[Migration("20190530151932_InitialMigration")]
partial class InitialMigration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Store.Models.Product", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("Amount");
b.Property<string>("Brand");
b.Property<string>("Category");
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("Products");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace Store.Migrations
{
public partial class InitialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
{
Id = table.Column<string>(nullable: false),
Name = table.Column<string>(nullable: true),
Category = table.Column<string>(nullable: true),
Brand = table.Column<string>(nullable: true),
Amount = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Products");
}
}
}
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Store.Models;
namespace Store.Migrations
{
[DbContext(typeof(ProductContext))]
[Migration("20190603135845_UpdateProductTable")]
partial class UpdateProductTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Store.Models.Product", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("Amount");
b.Property<string>("Brand");
b.Property<string>("Category");
b.Property<string>("Description");
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("Products");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace Store.Migrations
{
public partial class UpdateProductTable : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Description",
table: "Products",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Description",
table: "Products");
}
}
}
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Store.Models;
namespace Store.Migrations
{
[DbContext(typeof(ProductContext))]
partial class ProductContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Store.Models.Product", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("Amount");
b.Property<string>("Brand");
b.Property<string>("Category");
b.Property<string>("Description");
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("Products");
});
#pragma warning restore 612, 618
}
}
}
......@@ -7,5 +7,6 @@ namespace Store.Models
public string Category { get; set; }
public string Brand { get; set; }
public int Amount { get; set; }
public string Description { get; set; }
}
}
using Microsoft.EntityFrameworkCore;
namespace Store.Models
{
public class ProductContext : DbContext
{
public DbSet<Product> Products { get; set; }
public ProductContext(DbContextOptions<ProductContext> options) :
base(options)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Store.Models;
namespace Store
{
......@@ -31,6 +28,8 @@ namespace Store
options.MinimumSameSitePolicy = SameSiteMode.None;
});
string connection = Configuration.GetConnectionString("StoreConnection");
services.AddDbContext<ProductContext>(options => options.UseNpgsql(connection));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
......
......@@ -6,11 +6,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.4" />
</ItemGroup>
<ItemGroup>
......
{
"ConnectionStrings": {
"StoreConnection": "Host=localhost;Database=storedb;Username=postgres;Password=1qaz@WSX"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
......
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