Skip to content

Commit

Permalink
Switch to MS SQL for .ToJson support
Browse files Browse the repository at this point in the history
  • Loading branch information
huysentruitw committed Oct 23, 2023
1 parent 23e9d3f commit ef814e7
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 191 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ TestResults/
.cr/
.vs/
__mismatch__
.mongodb
.rabbitmq
.redis
.mysql
15 changes: 6 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
version: '3.8'

services:
mysql:
image: 'mysql:8.0-debian'
mssql:
image: 'mcr.microsoft.com/mssql/server:2019-latest'
restart: always
environment:
MYSQL_DATABASE: shop
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_ROOT_PASSWORD: root
ACCEPT_EULA: Y
MSSQL_PID: Developer
SA_PASSWORD: P@ssw0rd
ports:
- '3306:3306'
volumes:
- .mysql:/var/lib/mysql
- 11433:1433
28 changes: 28 additions & 0 deletions src/Shop.Application/Features/Basket/Entities/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Shop.Application.Features.Basket.Entities;

internal sealed record Basket
{
public required Guid Id { get; init; }

public required Reservation[] Reservations { get; init; }
}

internal sealed record Reservation
{
public required Guid ProductId { get; init; }

public required int Quantity { get; init; }
}

internal sealed class BasketEntityTypeConfiguration : IEntityTypeConfiguration<Basket>
{
public void Configure(EntityTypeBuilder<Basket> builder)
{
builder.HasKey(x => x.Id);

builder.OwnsMany<Reservation>(x => x.Reservations, options => options.ToJson());
}
}

This file was deleted.

44 changes: 0 additions & 44 deletions src/Shop.Application/Migrations/20230706213110_Add product.cs

This file was deleted.

This file was deleted.

This file was deleted.

92 changes: 92 additions & 0 deletions src/Shop.Application/Migrations/20231023191622_Initial.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions src/Shop.Application/Migrations/20231023191622_Initial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Shop.Application.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Basket",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Reservations = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Basket", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Product",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
UnitPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Product", x => x.Id);
});

migrationBuilder.CreateIndex(
name: "IX_Product_Name",
table: "Product",
column: "Name");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Basket");

migrationBuilder.DropTable(
name: "Product");
}
}
}
Loading

0 comments on commit ef814e7

Please sign in to comment.