Skip to content

Commit

Permalink
#25 Infrastructure - BankAccountRepository - EF (Added migrations)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinajemuovic committed Jun 18, 2022
1 parent 6f8df27 commit ef3d5f6
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 7 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ dotnet test Optivem.Kata.Banking.sln

## Migrations

To update the database:

```
dotnet ef database update --project .\src\Optivem.Kata.Banking.Infrastructure
```
dotnet ef migrations add InitialMigration --project .\src\Optivem.Kata.Banking.Web


To add a migration:

```
dotnet ef migrations add NameOfSomeMigration --project .\src\Optivem.Kata.Banking.Infrastructure
```

To remove a migration:

```
dotnet ef migrations remove --project .\src\Optivem.Kata.Banking.Infrastructure
```

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Optivem.Kata.Banking.Infrastructure.Migrations
{
public partial class InitialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "BankAccounts",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AccountNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: false),
LastName = table.Column<string>(type: "nvarchar(max)", nullable: false),
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Balance = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BankAccounts", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BankAccounts");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Optivem.Kata.Banking.Infrastructure.Persistence;

#nullable disable

namespace Optivem.Kata.Banking.Infrastructure.Migrations
{
[DbContext(typeof(DatabaseContext))]
partial class DatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);

modelBuilder.Entity("Optivem.Kata.Banking.Infrastructure.Persistence.BankAccountRecord", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"), 1L, 1);

b.Property<string>("AccountNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<int>("Balance")
.HasColumnType("int");

b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("LastName")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");

b.HasKey("Id");

b.ToTable("BankAccounts");
});
#pragma warning restore 612, 618
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -8,6 +8,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
<PackageReference Include="NUlid" Version="1.7.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Optivem.Kata.Banking.Infrastructure.Persistence
{
public class DatabaseContextFactory : IDesignTimeDbContextFactory<DatabaseContext>
{
public DatabaseContext CreateDbContext(string[] args)
{
var connectionString = "Data Source=localhost;Initial Catalog=BankingKata;Integrated Security=True;MultipleActiveResultSets=True;";
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
optionsBuilder.UseSqlServer(connectionString);

return new DatabaseContext(optionsBuilder.Options);
}
}
}
4 changes: 0 additions & 4 deletions src/Optivem.Kata.Banking.Web/Optivem.Kata.Banking.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task Nothing()

}

[Fact]
[Fact(Skip = "In progress")]
public async Task Should_open_bank_account_given_valid_request()
{
var url = "bank-accounts";
Expand Down

0 comments on commit ef3d5f6

Please sign in to comment.