From cfd1a37fbab15680f94a96338d9be3503acdc53f Mon Sep 17 00:00:00 2001 From: Unai Date: Thu, 3 Nov 2016 17:52:15 +0100 Subject: [PATCH] Migrate Sql Server.Added Swagger --- docker-compose.yml | 11 +- .../Infrastructure/CatalogContext.cs | 39 ++--- .../Infrastructure/CatalogContextSeed.cs | 6 +- .../20161103152832_Initial.Designer.cs | 99 +++++++++++ .../Migrations/20161103152832_Initial.cs | 108 ++++++++++++ ...0161103153420_UpdateTableNames.Designer.cs | 99 +++++++++++ .../20161103153420_UpdateTableNames.cs | 161 ++++++++++++++++++ .../Migrations/CatalogContextModelSnapshot.cs | 98 +++++++++++ src/Services/Catalog/Catalog.API/Startup.cs | 62 ++++--- src/Services/Catalog/Catalog.API/project.json | 12 +- .../Catalog.API/settings.development.json | 2 +- .../Catalog.API/settings.production.json | 2 +- 12 files changed, 635 insertions(+), 64 deletions(-) create mode 100644 src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.Designer.cs create mode 100644 src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.cs create mode 100644 src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.Designer.cs create mode 100644 src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.cs create mode 100644 src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs diff --git a/docker-compose.yml b/docker-compose.yml index 1318a7470..37d67123f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,14 +15,19 @@ services: catalog.api: image: eshop/catalog.api:latest environment: - - ConnectionString=Server=catalogdata;Port=5432;Database=postgres;username=postgres + - ConnectionString=Server=catalogdata;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word expose: - "80" depends_on: - catalogdata catalogdata: - image: glennc/eshopdata + image: eshop/mssql-server-private-preview + environment: + - ACCEPT_EULA=Y + - SA_PASSWORD=Pass@word + ports: + - "1455:1433" ordering.api: image: eshop/ordering.api:latest @@ -43,7 +48,7 @@ services: image: eshop/ordering.data.sqlserver.linux ports: - "1433:1433" - + basket.api: image: eshop/basket.api:latest environment: diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs index c2ebe40af..3ad04aed4 100644 --- a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs @@ -2,7 +2,6 @@ { using EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore; - using Npgsql.EntityFrameworkCore.PostgreSQL; public class CatalogContext : DbContext { @@ -18,32 +17,19 @@ protected override void OnModelCreating(ModelBuilder builder) { - builder.HasSequence("idseqcatalog") - .StartsAt(1) - .IncrementsBy(1); - - builder.HasSequence("idseqcatalogbrand") - .StartsAt(1) - .IncrementsBy(1); - - builder.HasSequence("idseqcatalogtype") - .StartsAt(1) - .IncrementsBy(1); - builder.Entity(ConfigureCatalogBrand); builder.Entity(ConfigureCatalogType); builder.Entity(ConfigureCatalogItem); - builder.HasPostgresExtension("uuid-ossp"); } void ConfigureCatalogItem(EntityTypeBuilder builder) { - builder.ForNpgsqlToTable("catalog"); + builder.ToTable("Catalog"); builder.Property(ci => ci.Id) - .HasDefaultValueSql("nextval('idseqcatalog')") + .ForSqlServerUseSequenceHiLo("catalog_hilo") .IsRequired(); builder.Property(ci => ci.Name) @@ -68,11 +54,13 @@ void ConfigureCatalogBrand(EntityTypeBuilder builder) { - builder.ForNpgsqlToTable("catalogbrand"); + builder.ToTable("CatalogBrand"); - builder.Property(cb => cb.Id) - .HasDefaultValueSql("nextval('idseqcatalogbrand')") - .IsRequired(); + builder.HasKey(ci => ci.Id); + + builder.Property(ci => ci.Id) + .ForSqlServerUseSequenceHiLo("catalog_brand_hilo") + .IsRequired(); builder.Property(cb => cb.Brand) .IsRequired() @@ -81,11 +69,14 @@ void ConfigureCatalogType(EntityTypeBuilder builder) { - builder.ForNpgsqlToTable("catalogtype"); - builder.Property(cb => cb.Id) - .HasDefaultValueSql("nextval('idseqcatalogtype')") - .IsRequired(); + builder.ToTable("CatalogType"); + + builder.HasKey(ci => ci.Id); + + builder.Property(ci => ci.Id) + .ForSqlServerUseSequenceHiLo("catalog_type_hilo") + .IsRequired(); builder.Property(cb => cb.Type) .IsRequired() diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs index a5852b331..105ef79cf 100644 --- a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs @@ -1,7 +1,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure { + using EntityFrameworkCore; using Microsoft.AspNetCore.Builder; - using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -15,9 +15,7 @@ using (context) { - context.Database.EnsureDeleted(); - - context.Database.EnsureCreated(); + context.Database.Migrate(); if (!context.CatalogBrands.Any()) { diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.Designer.cs b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.Designer.cs new file mode 100644 index 000000000..9fc113546 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.Designer.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; + +namespace Catalog.API.Infrastructure.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20161103152832_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.1") + .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.HasKey("Id"); + + b.ToTable("catalogbrand"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId"); + + b.Property("CatalogTypeId"); + + b.Property("Description"); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("PictureUri"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("catalog"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.HasKey("Id"); + + b.ToTable("CatalogTypes"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.cs b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.cs new file mode 100644 index 000000000..51c7dfafb --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Catalog.API.Infrastructure.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateSequence( + name: "catalog_brand_hilo", + incrementBy: 10); + + migrationBuilder.CreateSequence( + name: "catalog_hilo", + incrementBy: 10); + + migrationBuilder.CreateSequence( + name: "catalog_type_hilo", + incrementBy: 10); + + migrationBuilder.CreateTable( + name: "catalogbrand", + columns: table => new + { + Id = table.Column(nullable: false), + Brand = table.Column(maxLength: 100, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_catalogbrand", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CatalogTypes", + columns: table => new + { + Id = table.Column(nullable: false), + Type = table.Column(maxLength: 100, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CatalogTypes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "catalog", + columns: table => new + { + Id = table.Column(nullable: false), + CatalogBrandId = table.Column(nullable: false), + CatalogTypeId = table.Column(nullable: false), + Description = table.Column(nullable: true), + Name = table.Column(maxLength: 50, nullable: false), + PictureUri = table.Column(nullable: true), + Price = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_catalog", x => x.Id); + table.ForeignKey( + name: "FK_catalog_catalogbrand_CatalogBrandId", + column: x => x.CatalogBrandId, + principalTable: "catalogbrand", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_catalog_CatalogTypes_CatalogTypeId", + column: x => x.CatalogTypeId, + principalTable: "CatalogTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_catalog_CatalogBrandId", + table: "catalog", + column: "CatalogBrandId"); + + migrationBuilder.CreateIndex( + name: "IX_catalog_CatalogTypeId", + table: "catalog", + column: "CatalogTypeId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropSequence( + name: "catalog_brand_hilo"); + + migrationBuilder.DropSequence( + name: "catalog_hilo"); + + migrationBuilder.DropSequence( + name: "catalog_type_hilo"); + + migrationBuilder.DropTable( + name: "catalog"); + + migrationBuilder.DropTable( + name: "catalogbrand"); + + migrationBuilder.DropTable( + name: "CatalogTypes"); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.Designer.cs b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.Designer.cs new file mode 100644 index 000000000..711e9aa4f --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.Designer.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; + +namespace Catalog.API.Infrastructure.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20161103153420_UpdateTableNames")] + partial class UpdateTableNames + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.1") + .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrand"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId"); + + b.Property("CatalogTypeId"); + + b.Property("Description"); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("PictureUri"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.HasKey("Id"); + + b.ToTable("CatalogType"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.cs b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.cs new file mode 100644 index 000000000..dd73fbcd9 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.cs @@ -0,0 +1,161 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Catalog.API.Infrastructure.Migrations +{ + public partial class UpdateTableNames : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_catalog_catalogbrand_CatalogBrandId", + table: "catalog"); + + migrationBuilder.DropForeignKey( + name: "FK_catalog_CatalogTypes_CatalogTypeId", + table: "catalog"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogTypes", + table: "CatalogTypes"); + + migrationBuilder.DropPrimaryKey( + name: "PK_catalog", + table: "catalog"); + + migrationBuilder.DropPrimaryKey( + name: "PK_catalogbrand", + table: "catalogbrand"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogType", + table: "CatalogTypes", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Catalog", + table: "catalog", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogBrand", + table: "catalogbrand", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogBrand_CatalogBrandId", + table: "catalog", + column: "CatalogBrandId", + principalTable: "catalogbrand", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogType_CatalogTypeId", + table: "catalog", + column: "CatalogTypeId", + principalTable: "CatalogTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.RenameIndex( + name: "IX_catalog_CatalogTypeId", + table: "catalog", + newName: "IX_Catalog_CatalogTypeId"); + + migrationBuilder.RenameIndex( + name: "IX_catalog_CatalogBrandId", + table: "catalog", + newName: "IX_Catalog_CatalogBrandId"); + + migrationBuilder.RenameTable( + name: "CatalogTypes", + newName: "CatalogType"); + + migrationBuilder.RenameTable( + name: "catalog", + newName: "Catalog"); + + migrationBuilder.RenameTable( + name: "catalogbrand", + newName: "CatalogBrand"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogBrand_CatalogBrandId", + table: "Catalog"); + + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogType_CatalogTypeId", + table: "Catalog"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogType", + table: "CatalogType"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Catalog", + table: "Catalog"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogBrand", + table: "CatalogBrand"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogTypes", + table: "CatalogType", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_catalog", + table: "Catalog", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_catalogbrand", + table: "CatalogBrand", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_catalog_catalogbrand_CatalogBrandId", + table: "Catalog", + column: "CatalogBrandId", + principalTable: "CatalogBrand", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_catalog_CatalogTypes_CatalogTypeId", + table: "Catalog", + column: "CatalogTypeId", + principalTable: "CatalogType", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.RenameIndex( + name: "IX_Catalog_CatalogTypeId", + table: "Catalog", + newName: "IX_catalog_CatalogTypeId"); + + migrationBuilder.RenameIndex( + name: "IX_Catalog_CatalogBrandId", + table: "Catalog", + newName: "IX_catalog_CatalogBrandId"); + + migrationBuilder.RenameTable( + name: "CatalogType", + newName: "CatalogTypes"); + + migrationBuilder.RenameTable( + name: "Catalog", + newName: "catalog"); + + migrationBuilder.RenameTable( + name: "CatalogBrand", + newName: "catalogbrand"); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs new file mode 100644 index 000000000..c0eb1db72 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs @@ -0,0 +1,98 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; + +namespace Catalog.API.Infrastructure.Migrations +{ + [DbContext(typeof(CatalogContext))] + partial class CatalogContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.1") + .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrand"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId"); + + b.Property("CatalogTypeId"); + + b.Property("Description"); + + b.Property("Name") + .IsRequired() + .HasAnnotation("MaxLength", 50); + + b.Property("PictureUri"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasAnnotation("MaxLength", 100); + + b.HasKey("Id"); + + b.ToTable("CatalogType"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 9507678a2..c12b03681 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -1,18 +1,14 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc.ApiExplorer; -using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Serialization; -using System.Threading.Tasks; - -namespace Microsoft.eShopOnContainers.Services.Catalog.API +namespace Microsoft.eShopOnContainers.Services.Catalog.API { + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Hosting; + using Microsoft.EntityFrameworkCore; + using Microsoft.EntityFrameworkCore.Infrastructure; + using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Logging; + public class Startup { public IConfigurationRoot Configuration { get; } @@ -21,22 +17,20 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) - .AddJsonFile($"settings.{env.EnvironmentName}.json",optional:false) + .AddJsonFile($"settings.{env.EnvironmentName}.json", optional: false) .AddEnvironmentVariables(); Configuration = builder.Build(); } - - public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); - services.AddDbContext(c => + services.AddDbContext(c => { - c.UseNpgsql(Configuration["ConnectionString"]); + c.UseSqlServer(Configuration["ConnectionString"]); c.ConfigureWarnings(wb => { wb.Throw(RelationalEventId.QueryClientEvaluationWarning); @@ -45,13 +39,24 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API // Add framework services. + services.AddSwaggerGen(); + services.ConfigureSwaggerGen(options => + { + options.DescribeAllEnumsAsStrings(); + options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info() + { + Title = "Values API", + Version = "v1", + Description = "An API API With Swagger for RC2", + TermsOfService = "None" + }); + }); + services.AddCors(); - services.AddMvcCore() - .AddJsonFormatters(settings=> - { - settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - }); + services.AddMvc(mvcoptions => + { + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -60,8 +65,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API //Configure logs - if(env.IsDevelopment()) - { + if (env.IsDevelopment()) + { app.UseDeveloperExceptionPage(); } @@ -74,9 +79,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API .Wait(); // Use frameworks - app.UseCors(policyBuilder=>policyBuilder.AllowAnyOrigin()); + app.UseCors(policyBuilder => policyBuilder.AllowAnyOrigin()); app.UseMvc(); + + app.UseSwagger() + .UseSwaggerUi(); } } } diff --git a/src/Services/Catalog/Catalog.API/project.json b/src/Services/Catalog/Catalog.API/project.json index 50733a295..3f735f22a 100644 --- a/src/Services/Catalog/Catalog.API/project.json +++ b/src/Services/Catalog/Catalog.API/project.json @@ -3,22 +3,26 @@ "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" - }, + }, "Microsoft.AspNetCore.Mvc": "1.0.1", "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Diagnostics.Abstractions": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", - "Microsoft.EntityFrameworkCore": "1.0.1", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", + "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", - "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.2" + "Microsoft.EntityFrameworkCore": "1.0.1", + "Microsoft.EntityFrameworkCore.Relational": "1.0.1", + "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", + "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final", + "Swashbuckle": "6.0.0-beta902" }, "tools": { - + "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" }, "frameworks": { "netcoreapp1.0": { diff --git a/src/Services/Catalog/Catalog.API/settings.development.json b/src/Services/Catalog/Catalog.API/settings.development.json index a562552b2..2ca24aa6c 100644 --- a/src/Services/Catalog/Catalog.API/settings.development.json +++ b/src/Services/Catalog/Catalog.API/settings.development.json @@ -1,5 +1,5 @@ { - "ConnectionString": "Server=127.0.0.1;Port=5432;Database=CatalogDB;username=postgres;password=postgres", + "ConnectionString": "Server=tcp:127.0.0.1,1455;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word", "Logging": { "IncludeScopes": false, "LogLevel": { diff --git a/src/Services/Catalog/Catalog.API/settings.production.json b/src/Services/Catalog/Catalog.API/settings.production.json index a562552b2..2ca24aa6c 100644 --- a/src/Services/Catalog/Catalog.API/settings.production.json +++ b/src/Services/Catalog/Catalog.API/settings.production.json @@ -1,5 +1,5 @@ { - "ConnectionString": "Server=127.0.0.1;Port=5432;Database=CatalogDB;username=postgres;password=postgres", + "ConnectionString": "Server=tcp:127.0.0.1,1455;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word", "Logging": { "IncludeScopes": false, "LogLevel": {