Skip to content

Commit 20e1722

Browse files
authored
Merge pull request #74 from octodemo/develop
Add Director and Review models with migrations for database schema
2 parents 0da4369 + a94ef45 commit 20e1722

12 files changed

+849
-9
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
dotnet-version: '6.0.x'
114114

115115
- name: Cache NuGet packages
116-
uses: actions/cache@v4.0.2
116+
uses: actions/cache@v4.2.2
117117
with:
118118
path: ~/.nuget/packages
119119
key: nuget-ui-tests-${{ hashFiles('tests/RazorPagesMovie.UITests/RazorPagesMovie.UITests.csproj') }}

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585

8686
- name: Cache NuGet packages
8787
if: matrix.build-mode == 'manual'
88-
uses: actions/cache@v4.0.2
88+
uses: actions/cache@v4.2.2
8989
with:
9090
path: ~/.nuget/packages
9191
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/global.json') }}
@@ -150,7 +150,7 @@ jobs:
150150
dotnet-version: '6.0.x'
151151

152152
- name: Cache NuGet packages
153-
uses: actions/cache@v4.1.2
153+
uses: actions/cache@v4.2.2
154154
with:
155155
path: ~/.nuget/packages
156156
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/global.json') }}

AKS-Release-Pipelines.webp

159 KB
Binary file not shown.

src/Data/RazorPagesMovieContext.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ public RazorPagesMovieContext(DbContextOptions<RazorPagesMovieContext> options)
1414

1515
public DbSet<Movie> Movie { get; set; } = default!;
1616
public DbSet<User> Users { get; set; } = default!;
17+
public DbSet<Director> Directors { get; set; } = default!;
18+
public DbSet<Review> Reviews { get; set; } = default!;
1719

1820
protected override void OnModelCreating(ModelBuilder modelBuilder)
1921
{
2022
base.OnModelCreating(modelBuilder);
2123

24+
// Director configuration
25+
modelBuilder.Entity<Director>(entity =>
26+
{
27+
entity.Property(e => e.Name).IsRequired().HasMaxLength(100);
28+
entity.Property(e => e.BirthDate).IsRequired();
29+
});
30+
2231
// User configuration
2332
modelBuilder.Entity<User>(entity =>
2433
{
@@ -38,8 +47,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3847
.OnDelete(DeleteBehavior.Cascade);
3948

4049
entity.HasIndex(m => m.UserId);
41-
entity.Property(m => m.Timestamp).IsConcurrencyToken();
42-
entity.Property(m => m.Timestamp).HasDefaultValue(new byte[8]); // Set default value for Timestamp
50+
entity.Property(m => m.Timestamp).IsRowVersion(); // Ensure Timestamp is configured as rowversion
4351
});
4452

4553
// Seed data with hashed passwords
@@ -89,6 +97,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
8997
Timestamp = new byte[8]
9098
});
9199
}
100+
101+
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
102+
{
103+
relationship.DeleteBehavior = DeleteBehavior.NoAction; // Or DeleteBehavior.Restrict
104+
}
92105
}
93106

94107
private static string HashPassword(string password)

src/Migrations/20241201195812_InitialCreate.Designer.cs renamed to src/Migrations/20241216191308_InitialCreate.Designer.cs

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Migrations/20241201195812_InitialCreate.cs renamed to src/Migrations/20241216191308_InitialCreate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
3737
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
3838
Rating = table.Column<string>(type: "nvarchar(max)", nullable: false),
3939
UserId = table.Column<int>(type: "int", nullable: true),
40-
Timestamp = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: false, defaultValue: new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })
40+
Timestamp = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: false)
4141
},
4242
constraints: table =>
4343
{

0 commit comments

Comments
 (0)