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> /// <summary>
/// The release date of this episode. It can be null if unknown. /// The release date of this episode. It can be null if unknown.
/// </summary> /// </summary>
public DateTime? ReleaseDate { get; set; } public DateOnly? ReleaseDate { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public DateTime AddedDate { get; set; } public DateTime AddedDate { get; set; }

View File

@ -104,7 +104,7 @@ public class Movie
/// <summary> /// <summary>
/// The date this movie aired. /// The date this movie aired.
/// </summary> /// </summary>
public DateTime? AirDate { get; set; } public DateOnly? AirDate { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public DateTime AddedDate { get; set; } public DateTime AddedDate { get; set; }
@ -120,11 +120,11 @@ public class Movie
[JsonIgnore] [JsonIgnore]
[Column("air_date")] [Column("air_date")]
public DateTime? StartAir => AirDate; public DateOnly? StartAir => AirDate;
[JsonIgnore] [JsonIgnore]
[Column("air_date")] [Column("air_date")]
public DateTime? EndAir => AirDate; public DateOnly? EndAir => AirDate;
/// <summary> /// <summary>
/// A video of a few minutes that tease the content. /// 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> /// <summary>
/// The starting air date of this season. /// The starting air date of this season.
/// </summary> /// </summary>
public DateTime? StartDate { get; set; } public DateOnly? StartDate { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public DateTime AddedDate { get; set; } public DateTime AddedDate { get; set; }
@ -105,7 +105,7 @@ public class Season : IQuery, IResource, IMetadata, IThumbnails, IAddedDate
/// <summary> /// <summary>
/// The ending date of this season. /// The ending date of this season.
/// </summary> /// </summary>
public DateTime? EndDate { get; set; } public DateOnly? EndDate { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public Image? Poster { get; set; } public Image? Poster { get; set; }

View File

@ -94,13 +94,13 @@ public class Show
/// <summary> /// <summary>
/// The date this show started airing. It can be null if this is unknown. /// The date this show started airing. It can be null if this is unknown.
/// </summary> /// </summary>
public DateTime? StartAir { get; set; } public DateOnly? StartAir { get; set; }
/// <summary> /// <summary>
/// The date this show finished airing. /// The date this show finished airing.
/// It can also be null if this is unknown. /// It can also be null if this is unknown.
/// </summary> /// </summary>
public DateTime? EndAir { get; set; } public DateOnly? EndAir { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public DateTime AddedDate { get; set; } public DateTime AddedDate { get; set; }
@ -121,7 +121,7 @@ public class Show
[JsonIgnore] [JsonIgnore]
[Column("start_air")] [Column("start_air")]
public DateTime? AirDate => StartAir; public DateOnly? AirDate => StartAir;
/// <inheritdoc /> /// <inheritdoc />
public Dictionary<string, MetadataId> ExternalId { get; set; } = new(); 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 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "7.0.12") .HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 63); .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, "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, "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); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Kyoo.Abstractions.Models.Collection", b => modelBuilder.Entity("Kyoo.Abstractions.Models.Collection", b =>
@ -109,8 +109,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("text") .HasColumnType("text")
.HasColumnName("path"); .HasColumnName("path");
b.Property<DateTime?>("ReleaseDate") b.Property<DateOnly?>("ReleaseDate")
.HasColumnType("timestamp with time zone") .HasColumnType("date")
.HasColumnName("release_date"); .HasColumnName("release_date");
b.Property<int?>("Runtime") b.Property<int?>("Runtime")
@ -238,8 +238,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("added_date") .HasColumnName("added_date")
.HasDefaultValueSql("now() at time zone 'utc'"); .HasDefaultValueSql("now() at time zone 'utc'");
b.Property<DateTime?>("AirDate") b.Property<DateOnly?>("AirDate")
.HasColumnType("timestamp with time zone") .HasColumnType("date")
.HasColumnName("air_date"); .HasColumnName("air_date");
b.Property<string[]>("Aliases") b.Property<string[]>("Aliases")
@ -373,8 +373,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("added_date") .HasColumnName("added_date")
.HasDefaultValueSql("now() at time zone 'utc'"); .HasDefaultValueSql("now() at time zone 'utc'");
b.Property<DateTime?>("EndDate") b.Property<DateOnly?>("EndDate")
.HasColumnType("timestamp with time zone") .HasColumnType("date")
.HasColumnName("end_date"); .HasColumnName("end_date");
b.Property<string>("ExternalId") b.Property<string>("ExternalId")
@ -404,8 +404,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("character varying(256)") .HasColumnType("character varying(256)")
.HasColumnName("slug"); .HasColumnName("slug");
b.Property<DateTime?>("StartDate") b.Property<DateOnly?>("StartDate")
.HasColumnType("timestamp with time zone") .HasColumnType("date")
.HasColumnName("start_date"); .HasColumnName("start_date");
b.HasKey("Id") b.HasKey("Id")
@ -440,8 +440,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("text[]") .HasColumnType("text[]")
.HasColumnName("aliases"); .HasColumnName("aliases");
b.Property<DateTime?>("EndAir") b.Property<DateOnly?>("EndAir")
.HasColumnType("timestamp with time zone") .HasColumnType("date")
.HasColumnName("end_air"); .HasColumnName("end_air");
b.Property<string>("ExternalId") b.Property<string>("ExternalId")
@ -473,8 +473,8 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("character varying(256)") .HasColumnType("character varying(256)")
.HasColumnName("slug"); .HasColumnName("slug");
b.Property<DateTime?>("StartAir") b.Property<DateOnly?>("StartAir")
.HasColumnType("timestamp with time zone") .HasColumnType("date")
.HasColumnName("start_air"); .HasColumnName("start_air");
b.Property<Status>("Status") b.Property<Status>("Status")
@ -651,6 +651,10 @@ namespace Kyoo.Postgresql.Migrations
.IsUnique() .IsUnique()
.HasDatabaseName("ix_users_slug"); .HasDatabaseName("ix_users_slug");
b.HasIndex("Username")
.IsUnique()
.HasDatabaseName("ix_users_username");
b.ToTable("users", (string)null); b.ToTable("users", (string)null);
}); });