Skip to content

Commit

Permalink
feat: Using a Separate Migrations Project
Browse files Browse the repository at this point in the history
  • Loading branch information
leandro-cervelin committed Jan 8, 2024
1 parent c9a7fe0 commit dd2e5dd
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 117 deletions.
8 changes: 7 additions & 1 deletion CF.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CF.Customer.UnitTest", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CF.IntegrationTest", "src\CF.IntegrationTest\CF.IntegrationTest.csproj", "{4CABA244-6123-4C61-90AB-F5FE20A8168A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CF.Api.UnitTest", "src\CF.Api.UnitTest\CF.Api.UnitTest.csproj", "{AF09E52F-212E-4ED6-A815-217B49C8D837}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CF.Api.UnitTest", "src\CF.Api.UnitTest\CF.Api.UnitTest.csproj", "{AF09E52F-212E-4ED6-A815-217B49C8D837}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CF.Migrations", "src\CF.Migrations\CF.Migrations.csproj", "{348179D1-891E-4D2E-BA8A-24807E1223EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -53,6 +55,10 @@ Global
{AF09E52F-212E-4ED6-A815-217B49C8D837}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF09E52F-212E-4ED6-A815-217B49C8D837}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF09E52F-212E-4ED6-A815-217B49C8D837}.Release|Any CPU.Build.0 = Release|Any CPU
{348179D1-891E-4D2E-BA8A-24807E1223EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{348179D1-891E-4D2E-BA8A-24807E1223EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{348179D1-891E-4D2E-BA8A-24807E1223EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{348179D1-891E-4D2E-BA8A-24807E1223EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 1 addition & 4 deletions src/CF.Api/CF.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<ItemGroup>
<ProjectReference Include="..\CF.Customer.Infrastructure\CF.Customer.Infrastructure.csproj" />
<ProjectReference Include="..\CF.Migrations\CF.Migrations.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -34,8 +35,4 @@
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>

</Project>
38 changes: 0 additions & 38 deletions src/CF.Api/Migrations/20201026103509_Customer.cs

This file was deleted.

64 changes: 0 additions & 64 deletions src/CF.Api/Migrations/CustomerContextModelSnapshot.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/CF.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
builder.Services.AddDbContext<CustomerContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("DbConnection"),
a => { a.MigrationsAssembly("CF.Api"); });
a => { a.MigrationsAssembly("CF.Migrations"); });
});

AddNLog();
Expand Down
21 changes: 21 additions & 0 deletions src/CF.Migrations/CF.Migrations.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CF.Customer.Infrastructure\CF.Customer.Infrastructure.csproj" />
</ItemGroup>

</Project>

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

46 changes: 46 additions & 0 deletions src/CF.Migrations/Migrations/20240108231037_InitialMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CF.Migrations.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Customer",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
Email = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
FirstName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Password = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
Surname = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Updated = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Customer", x => x.Id);
});

migrationBuilder.CreateIndex(
name: "IX_Customer_Email",
table: "Customer",
column: "Email",
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Customer");
}
}
}
69 changes: 69 additions & 0 deletions src/CF.Migrations/Migrations/CustomerContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// <auto-generated />
using System;
using CF.Customer.Infrastructure.DbContext;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace CF.Migrations.Migrations
{
[DbContext(typeof(CustomerContext))]
partial class CustomerContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("CF.Customer.Domain.Entities.Customer", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");

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

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

b.Property<string>("Email")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");

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

b.Property<string>("Password")
.IsRequired()
.HasMaxLength(2000)
.HasColumnType("nvarchar(2000)");

b.Property<string>("Surname")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");

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

b.HasKey("Id");

b.HasIndex("Email")
.IsUnique();

b.ToTable("Customer", (string)null);
});
#pragma warning restore 612, 618
}
}
}

0 comments on commit dd2e5dd

Please sign in to comment.