Added timezone support
This commit is contained in:
parent
62458cbdd4
commit
7c3fecf70b
|
@ -1,5 +1,6 @@
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
namespace Wave.Data;
|
namespace Wave.Data;
|
||||||
|
|
||||||
|
@ -9,6 +10,11 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
|
||||||
protected override void OnModelCreating(ModelBuilder builder) {
|
protected override void OnModelCreating(ModelBuilder builder) {
|
||||||
base.OnModelCreating(builder);
|
base.OnModelCreating(builder);
|
||||||
|
|
||||||
|
var dateTimeOffsetUtcConverter = new ValueConverter<DateTimeOffset, DateTimeOffset>(
|
||||||
|
model => model.ToUniversalTime(),
|
||||||
|
utc => utc.ToLocalTime()
|
||||||
|
);
|
||||||
|
|
||||||
builder.Entity<ApplicationUser>(user => {
|
builder.Entity<ApplicationUser>(user => {
|
||||||
user.Property(u => u.FullName).HasMaxLength(64);
|
user.Property(u => u.FullName).HasMaxLength(64);
|
||||||
user.Property(u => u.AboutTheAuthor).HasMaxLength(512);
|
user.Property(u => u.AboutTheAuthor).HasMaxLength(512);
|
||||||
|
@ -36,9 +42,13 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
|
||||||
.IsRequired(false).OnDelete(DeleteBehavior.SetNull);
|
.IsRequired(false).OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
article.Property(a => a.CreationDate)
|
article.Property(a => a.CreationDate)
|
||||||
.IsRequired().HasDefaultValueSql("now()");
|
.IsRequired().HasDefaultValueSql("now()")
|
||||||
|
.HasConversion(dateTimeOffsetUtcConverter);
|
||||||
|
article.Property(a => a.PublishDate)
|
||||||
|
.HasConversion(dateTimeOffsetUtcConverter);
|
||||||
article.Property(a => a.LastModified)
|
article.Property(a => a.LastModified)
|
||||||
.IsRequired().HasDefaultValueSql("now()");
|
.IsRequired().HasDefaultValueSql("now()")
|
||||||
|
.HasConversion(dateTimeOffsetUtcConverter);
|
||||||
|
|
||||||
article.HasQueryFilter(a => !a.IsDeleted);
|
article.HasQueryFilter(a => !a.IsDeleted);
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,6 +13,7 @@ services:
|
||||||
links:
|
links:
|
||||||
- database:db
|
- database:db
|
||||||
environment:
|
environment:
|
||||||
|
- "TZ=Europe/Berlin"
|
||||||
- "WAVE_ConnectionStrings__DefaultConnection=Host=db; Username=wave; Password=development"
|
- "WAVE_ConnectionStrings__DefaultConnection=Host=db; Username=wave; Password=development"
|
||||||
- "WAVE_ConnectionStrings__Redis=redis,password=development"
|
- "WAVE_ConnectionStrings__Redis=redis,password=development"
|
||||||
volumes:
|
volumes:
|
||||||
|
|
Loading…
Reference in a new issue