Skip to content

Commit

Permalink
added migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
saschaheinl committed Sep 6, 2024
1 parent 689333b commit 686d7c1
Show file tree
Hide file tree
Showing 55 changed files with 578 additions and 30 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("TVR.Bundesliga.API.Contracts")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5b745884b1b27f4ddc86c78e7e75fcb628dd6c6c")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+689333bd7d30980d737924b86ba79c2bf81969f0")]
[assembly: System.Reflection.AssemblyProductAttribute("TVR.Bundesliga.API.Contracts")]
[assembly: System.Reflection.AssemblyTitleAttribute("TVR.Bundesliga.API.Contracts")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"/Users/sascha/Documents/repos/tvr-bundesliga/*":"https://raw.githubusercontent.com/saschaheinl/tvr-bundesliga-apps/5b745884b1b27f4ddc86c78e7e75fcb628dd6c6c/*"}}
{"documents":{"/Users/sascha/Documents/repos/tvr-bundesliga/*":"https://raw.githubusercontent.com/saschaheinl/tvr-bundesliga-apps/689333bd7d30980d737924b86ba79c2bf81969f0/*"}}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/Users/sascha/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/Users/sascha/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.10.1</NuGetToolVersion>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.9.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/Users/sascha/.nuget/packages/" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17256611589446991
17256623670413570
18 changes: 10 additions & 8 deletions API/TVR.Bundesliga.API.Core/Context/TicketDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ public TicketDb(DbContextOptions<TicketDb> options) : base(options)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Configuring Event as a required relationship

modelBuilder.Entity<Ticket>()
.HasOne(t => t.Event)
.WithMany() // No inverse navigation from Event to Ticket
.HasForeignKey("EventId") // Assume there's an EventId FK in Ticket
.IsRequired(false); // Optional relationship
.WithMany()
.HasForeignKey("EventId")
.IsRequired(false);

// Configuring Guest as a required relationship
modelBuilder.Entity<Ticket>()
.HasOne(t => t.Guest)
.WithMany() // No inverse navigation from Guest to Ticket
.HasForeignKey("GuestId") // Assume there's a GuestId FK in Ticket
.IsRequired(true); // This is required in your logic
.WithMany()
.HasForeignKey(t => t.GuestId);

modelBuilder.Entity<Ticket>()
.Property(t => t.Id)
.ValueGeneratedOnAdd();
}
}

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,22 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TVR.Bundesliga.API.Core.Migrations
{
/// <inheritdoc />
public partial class RemoveGuestIdUniqueContraint : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{

}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{

}
}
}

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,59 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TVR.Bundesliga.API.Core.Migrations
{
/// <inheritdoc />
public partial class RemoveGuestIdUniqueContraintAndAddGuestId : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Tickets_Guest_GuestId",
table: "Tickets");

migrationBuilder.AlterColumn<int>(
name: "GuestId",
table: "Tickets",
type: "integer",
nullable: true,
oldClrType: typeof(int),
oldType: "integer");

migrationBuilder.AddForeignKey(
name: "FK_Tickets_Guest_GuestId",
table: "Tickets",
column: "GuestId",
principalTable: "Guest",
principalColumn: "Id");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Tickets_Guest_GuestId",
table: "Tickets");

migrationBuilder.AlterColumn<int>(
name: "GuestId",
table: "Tickets",
type: "integer",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "integer",
oldNullable: true);

migrationBuilder.AddForeignKey(
name: "FK_Tickets_Guest_GuestId",
table: "Tickets",
column: "GuestId",
principalTable: "Guest",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}
Loading

0 comments on commit 686d7c1

Please sign in to comment.