Skip to content

Commit

Permalink
added EF migrations.
Browse files Browse the repository at this point in the history
issue in EF core dotnet/efcore#12078 makes things worse
  • Loading branch information
nvsnkv committed Nov 6, 2021
1 parent b8a5ec0 commit ea5ffcc
Show file tree
Hide file tree
Showing 14 changed files with 387 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ obj
.suo
/src/Flow.sln.DotSettings.user
/src/.vs
/src/.env
12 changes: 12 additions & 0 deletions src/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "5.0.11",
"commands": [
"dotnet-ef"
]
}
}
}
7 changes: 7 additions & 0 deletions src/Flow.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flow.Infrastructure.IO", "l
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flow.Infrastructure.IO.UnitTests", "l2\Flow.Infrastructure.IO.UnitTests\Flow.Infrastructure.IO.UnitTests.csproj", "{AAB611F2-902B-4196-97B8-E48EEE41E010}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flow.Infrastructure.Storage.Migrations", "l2\Flow.Infrastructure.Storage.Migrations\Flow.Infrastructure.Storage.Migrations.csproj", "{D4126756-6928-4D1F-B203-DC1A4E38AD2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -69,6 +71,10 @@ Global
{AAB611F2-902B-4196-97B8-E48EEE41E010}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAB611F2-902B-4196-97B8-E48EEE41E010}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAB611F2-902B-4196-97B8-E48EEE41E010}.Release|Any CPU.Build.0 = Release|Any CPU
{D4126756-6928-4D1F-B203-DC1A4E38AD2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4126756-6928-4D1F-B203-DC1A4E38AD2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4126756-6928-4D1F-B203-DC1A4E38AD2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4126756-6928-4D1F-B203-DC1A4E38AD2A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -83,6 +89,7 @@ Global
{25C4F714-68D3-42E6-A6CB-5E063DBCDE63} = {C2DD4A7B-704F-4C12-B89E-E6A7657A418D}
{C99CF6F9-CFE3-4F67-B450-89B45AD7893F} = {C2DD4A7B-704F-4C12-B89E-E6A7657A418D}
{AAB611F2-902B-4196-97B8-E48EEE41E010} = {C2DD4A7B-704F-4C12-B89E-E6A7657A418D}
{D4126756-6928-4D1F-B203-DC1A4E38AD2A} = {C2DD4A7B-704F-4C12-B89E-E6A7657A418D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BD863072-1B8D-417A-BFF4-C60D20CE1D31}
Expand Down
16 changes: 16 additions & 0 deletions src/docker-compose.devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.8"
services:
accounts-db:
image: postgres
restart: always
volumes:
- flow-storage-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=flow-dev
- "POSTGRES_USER=${DEV_DB_USER}"
- "POSTGRES_PASSWORD=${DEV_DB_PWD}"
ports:
- "${DEV_DB_PORT}:5432"

volumes:
flow-storage-data:
2 changes: 2 additions & 0 deletions src/l0/Flow.Domain.Transactions/AccountInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Flow.Domain.Transactions
{
public sealed class AccountInfo
{
public static readonly AccountInfo Empty = new AccountInfo(string.Empty, string.Empty);

public AccountInfo(string name, string bank)
{
Name = name;
Expand Down
7 changes: 6 additions & 1 deletion src/l0/Flow.Domain.Transactions/RecordedTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace Flow.Domain.Transactions
{
public sealed class RecordedTransaction: Transaction
public class RecordedTransaction: Transaction
{
public RecordedTransaction(long key, DateTime timestamp, decimal amount, string currency, string? category, string title)
: this(key, timestamp, amount, currency, category, title, AccountInfo.Empty)
{
}

public RecordedTransaction(long key, DateTime timestamp, decimal amount, string currency, string? category, string title, AccountInfo account) : base(timestamp, amount, currency, category, title, account)
{
Key = key;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace Flow.Infrastructure.Storage.Migrations;

internal class DesignTimeDbContextBuilderFactory : IDesignTimeDbContextFactory<FlowDbContext>
{
public FlowDbContext CreateDbContext(string[] args)
{
var options = new DbContextOptionsBuilder()
.UseNpgsql(
args.FirstOrDefault() ?? throw new InvalidOperationException("Connection string was not configured!"),
o => o.MigrationsAssembly(typeof(DesignTimeDbContextBuilderFactory).Assembly.FullName))
.Options;

return new FlowDbContext(options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\Flow.Infrastructure.Storage\Flow.Infrastructure.Storage.csproj" />
</ItemGroup>

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>

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,66 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace Flow.Infrastructure.Storage.Migrations.Migrations
{
public partial class initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AccountInfo",
columns: table => new
{
Name = table.Column<string>(type: "text", nullable: false),
Bank = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AccountInfo", x => new { x.Name, x.Bank });
});

migrationBuilder.CreateTable(
name: "Transactions",
columns: table => new
{
Key = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Overrides_Comment = table.Column<string>(type: "text", nullable: true),
Overrides_Title = table.Column<string>(type: "text", nullable: true),
Overrides_Category = table.Column<string>(type: "text", nullable: true),
account_name = table.Column<string>(type: "text", nullable: false),
bank_name = table.Column<string>(type: "text", nullable: false),
Timestamp = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
Amount = table.Column<decimal>(type: "numeric", nullable: false),
Currency = table.Column<string>(type: "text", nullable: false),
Category = table.Column<string>(type: "text", nullable: false),
Title = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Transactions", x => x.Key);
table.ForeignKey(
name: "FK_Transactions_AccountInfo_account_name_bank_name",
columns: x => new { x.account_name, x.bank_name },
principalTable: "AccountInfo",
principalColumns: new[] { "Name", "Bank" },
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Transactions_account_name_bank_name",
table: "Transactions",
columns: new[] { "account_name", "bank_name" });
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Transactions");

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

0 comments on commit ea5ffcc

Please sign in to comment.