Skip to content

Add Director and Review models with migrations for database schema #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
dotnet-version: '6.0.x'

- name: Cache NuGet packages
uses: actions/cache@v4.0.2
uses: actions/cache@v4.2.2
with:
path: ~/.nuget/packages
key: nuget-ui-tests-${{ hashFiles('tests/RazorPagesMovie.UITests/RazorPagesMovie.UITests.csproj') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:

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

- name: Cache NuGet packages
uses: actions/cache@v4.1.2
uses: actions/cache@v4.2.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/global.json') }}
Expand Down
Binary file added AKS-Release-Pipelines.webp
Binary file not shown.
17 changes: 15 additions & 2 deletions src/Data/RazorPagesMovieContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ public RazorPagesMovieContext(DbContextOptions<RazorPagesMovieContext> options)

public DbSet<Movie> Movie { get; set; } = default!;
public DbSet<User> Users { get; set; } = default!;
public DbSet<Director> Directors { get; set; } = default!;
public DbSet<Review> Reviews { get; set; } = default!;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

// Director configuration
modelBuilder.Entity<Director>(entity =>
{
entity.Property(e => e.Name).IsRequired().HasMaxLength(100);
entity.Property(e => e.BirthDate).IsRequired();
});

// User configuration
modelBuilder.Entity<User>(entity =>
{
Expand All @@ -38,8 +47,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.OnDelete(DeleteBehavior.Cascade);

entity.HasIndex(m => m.UserId);
entity.Property(m => m.Timestamp).IsConcurrencyToken();
entity.Property(m => m.Timestamp).HasDefaultValue(new byte[8]); // Set default value for Timestamp
entity.Property(m => m.Timestamp).IsRowVersion(); // Ensure Timestamp is configured as rowversion
});

// Seed data with hashed passwords
Expand Down Expand Up @@ -89,6 +97,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
Timestamp = new byte[8]
});
}

foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
relationship.DeleteBehavior = DeleteBehavior.NoAction; // Or DeleteBehavior.Restrict
}
}

private static string HashPassword(string password)
Expand Down

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
Expand Up @@ -37,7 +37,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Rating = table.Column<string>(type: "nvarchar(max)", nullable: false),
UserId = table.Column<int>(type: "int", nullable: true),
Timestamp = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: false, defaultValue: new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })
Timestamp = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: false)
},
constraints: table =>
{
Expand Down
Loading
Loading