Use DateOnly for dates fields instead of DateTime

This commit is contained in:
Zoe Roux 2024-03-24 18:52:54 +01:00
parent c942794b89
commit 8afbc63b85
No known key found for this signature in database
7 changed files with 1525 additions and 23 deletions

View File

@ -151,7 +151,7 @@ public class Episode : IQuery, IResource, IMetadata, IThumbnails, IAddedDate, IN
/// <summary>
/// The release date of this episode. It can be null if unknown.
/// </summary>
public DateTime? ReleaseDate { get; set; }
public DateOnly? ReleaseDate { get; set; }
/// <inheritdoc />
public DateTime AddedDate { get; set; }

View File

@ -104,7 +104,7 @@ public class Movie
/// <summary>
/// The date this movie aired.
/// </summary>
public DateTime? AirDate { get; set; }
public DateOnly? AirDate { get; set; }
/// <inheritdoc />
public DateTime AddedDate { get; set; }
@ -120,11 +120,11 @@ public class Movie
[JsonIgnore]
[Column("air_date")]
public DateTime? StartAir => AirDate;
public DateOnly? StartAir => AirDate;
[JsonIgnore]
[Column("air_date")]
public DateTime? EndAir => AirDate;
public DateOnly? EndAir => AirDate;
/// <summary>
/// A video of a few minutes that tease the content.

View File

@ -97,7 +97,7 @@ public class Season : IQuery, IResource, IMetadata, IThumbnails, IAddedDate
/// <summary>
/// The starting air date of this season.
/// </summary>
public DateTime? StartDate { get; set; }
public DateOnly? StartDate { get; set; }
/// <inheritdoc />
public DateTime AddedDate { get; set; }
@ -105,7 +105,7 @@ public class Season : IQuery, IResource, IMetadata, IThumbnails, IAddedDate
/// <summary>
/// The ending date of this season.
/// </summary>
public DateTime? EndDate { get; set; }
public DateOnly? EndDate { get; set; }
/// <inheritdoc />
public Image? Poster { get; set; }

View File

@ -94,13 +94,13 @@ public class Show
/// <summary>
/// The date this show started airing. It can be null if this is unknown.
/// </summary>
public DateTime? StartAir { get; set; }
public DateOnly? StartAir { get; set; }
/// <summary>
/// The date this show finished airing.
/// It can also be null if this is unknown.
/// </summary>
public DateTime? EndAir { get; set; }
public DateOnly? EndAir { get; set; }
/// <inheritdoc />
public DateTime AddedDate { get; set; }
@ -121,7 +121,7 @@ public class Show
[JsonIgnore]
[Column("start_air")]
public DateTime? AirDate => StartAir;
public DateOnly? AirDate => StartAir;
/// <inheritdoc />
public Dictionary<string, MetadataId> ExternalId { get; set; } = new();

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,181 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
/// <inheritdoc />
public partial class UseDateOnly : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder
.AlterDatabase()
.Annotation(
"Npgsql:Enum:genre",
"action,adventure,animation,comedy,crime,documentary,drama,family,fantasy,history,horror,music,mystery,romance,science_fiction,thriller,war,western"
)
.Annotation("Npgsql:Enum:status", "unknown,finished,airing,planned")
.Annotation("Npgsql:Enum:watch_status", "completed,watching,droped,planned,deleted")
.OldAnnotation(
"Npgsql:Enum:genre",
"action,adventure,animation,comedy,crime,documentary,drama,family,fantasy,history,horror,music,mystery,romance,science_fiction,thriller,war,western"
)
.OldAnnotation("Npgsql:Enum:status", "unknown,finished,airing,planned")
.OldAnnotation("Npgsql:Enum:watch_status", "completed,watching,droped,planned");
migrationBuilder.AlterColumn<DateOnly>(
name: "start_air",
table: "shows",
type: "date",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true
);
migrationBuilder.AlterColumn<DateOnly>(
name: "end_air",
table: "shows",
type: "date",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true
);
migrationBuilder.AlterColumn<DateOnly>(
name: "start_date",
table: "seasons",
type: "date",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true
);
migrationBuilder.AlterColumn<DateOnly>(
name: "end_date",
table: "seasons",
type: "date",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true
);
migrationBuilder.AlterColumn<DateOnly>(
name: "air_date",
table: "movies",
type: "date",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true
);
migrationBuilder.AlterColumn<DateOnly>(
name: "release_date",
table: "episodes",
type: "date",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true
);
migrationBuilder.CreateIndex(
name: "ix_users_username",
table: "users",
column: "username",
unique: true
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(name: "ix_users_username", table: "users");
migrationBuilder
.AlterDatabase()
.Annotation(
"Npgsql:Enum:genre",
"action,adventure,animation,comedy,crime,documentary,drama,family,fantasy,history,horror,music,mystery,romance,science_fiction,thriller,war,western"
)
.Annotation("Npgsql:Enum:status", "unknown,finished,airing,planned")
.Annotation("Npgsql:Enum:watch_status", "completed,watching,droped,planned")
.OldAnnotation(
"Npgsql:Enum:genre",
"action,adventure,animation,comedy,crime,documentary,drama,family,fantasy,history,horror,music,mystery,romance,science_fiction,thriller,war,western"
)
.OldAnnotation("Npgsql:Enum:status", "unknown,finished,airing,planned")
.OldAnnotation(
"Npgsql:Enum:watch_status",
"completed,watching,droped,planned,deleted"
);
migrationBuilder.AlterColumn<DateTime>(
name: "start_air",
table: "shows",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateOnly),
oldType: "date",
oldNullable: true
);
migrationBuilder.AlterColumn<DateTime>(
name: "end_air",
table: "shows",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateOnly),
oldType: "date",
oldNullable: true
);
migrationBuilder.AlterColumn<DateTime>(
name: "start_date",
table: "seasons",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateOnly),
oldType: "date",
oldNullable: true
);
migrationBuilder.AlterColumn<DateTime>(
name: "end_date",
table: "seasons",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateOnly),
oldType: "date",
oldNullable: true
);
migrationBuilder.AlterColumn<DateTime>(
name: "air_date",
table: "movies",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateOnly),
oldType: "date",
oldNullable: true
);
migrationBuilder.AlterColumn<DateTime>(
name: "release_date",
table: "episodes",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateOnly),
oldType: "date",
oldNullable: true
);
}
}
}

View File

@ -19,12 +19,12 @@ namespace Kyoo.Postgresql.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.12")
.HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "genre", new[] { "action", "adventure", "animation", "comedy", "crime", "documentary", "drama", "family", "fantasy", "history", "horror", "music", "mystery", "romance", "science_fiction", "thriller", "war", "western" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "status", new[] { "unknown", "finished", "airing", "planned" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "watch_status", new[] { "completed", "watching", "droped", "planned" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "watch_status", new[] { "completed", "watching", "droped", "planned", "deleted" });
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Kyoo.Abstractions.Models.Collection", b =>
@ -109,8 +109,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("text")
.HasColumnName("path");
b.Property<DateTime?>("ReleaseDate")
.HasColumnType("timestamp with time zone")
b.Property<DateOnly?>("ReleaseDate")
.HasColumnType("date")
.HasColumnName("release_date");
b.Property<int?>("Runtime")
@ -238,8 +238,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("added_date")
.HasDefaultValueSql("now() at time zone 'utc'");
b.Property<DateTime?>("AirDate")
.HasColumnType("timestamp with time zone")
b.Property<DateOnly?>("AirDate")
.HasColumnType("date")
.HasColumnName("air_date");
b.Property<string[]>("Aliases")
@ -373,8 +373,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("added_date")
.HasDefaultValueSql("now() at time zone 'utc'");
b.Property<DateTime?>("EndDate")
.HasColumnType("timestamp with time zone")
b.Property<DateOnly?>("EndDate")
.HasColumnType("date")
.HasColumnName("end_date");
b.Property<string>("ExternalId")
@ -404,8 +404,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.Property<DateTime?>("StartDate")
.HasColumnType("timestamp with time zone")
b.Property<DateOnly?>("StartDate")
.HasColumnType("date")
.HasColumnName("start_date");
b.HasKey("Id")
@ -440,8 +440,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("text[]")
.HasColumnName("aliases");
b.Property<DateTime?>("EndAir")
.HasColumnType("timestamp with time zone")
b.Property<DateOnly?>("EndAir")
.HasColumnType("date")
.HasColumnName("end_air");
b.Property<string>("ExternalId")
@ -473,8 +473,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("character varying(256)")
.HasColumnName("slug");
b.Property<DateTime?>("StartAir")
.HasColumnType("timestamp with time zone")
b.Property<DateOnly?>("StartAir")
.HasColumnType("date")
.HasColumnName("start_air");
b.Property<Status>("Status")
@ -651,6 +651,10 @@ namespace Kyoo.Postgresql.Migrations
.IsUnique()
.HasDatabaseName("ix_users_slug");
b.HasIndex("Username")
.IsUnique()
.HasDatabaseName("ix_users_username");
b.ToTable("users", (string)null);
});