[CHANGE] Updated string maxsize on entities. Setup lib dbcontext

This commit is contained in:
max
2025-08-17 18:54:20 +02:00
parent 7f7e137a92
commit b6453d8bf6
12 changed files with 168 additions and 18 deletions

View File

@@ -21,11 +21,13 @@ public sealed class ApplicationDbContext : DbContext
sg.ToTable("settings_groups");
sg.HasKey(x => x.Id);
});
modelBuilder.Entity<SettingsModel>(settingsEntity =>
{
settingsEntity.ToTable("settings");
settingsEntity.HasKey(x => x.Key);
});
base.OnModelCreating(modelBuilder);
}
}

View File

@@ -1,11 +1,89 @@
using Manager.Data.Models.LibraryContext;
using Manager.Data.Models.LibraryContext.Join;
using Microsoft.EntityFrameworkCore;
namespace Manager.Data.Contexts;
public class LibraryDbContext : DbContext
public sealed class LibraryDbContext : DbContext
{
public LibraryDbContext(DbContextOptions<LibraryDbContext> options) : base(options)
{
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
ChangeTracker.LazyLoadingEnabled = false;
}
public DbSet<CaptionEntity> Captions { get; set; }
public DbSet<ChannelEntity> Channels { get; set; }
public DbSet<ClientAccountEntity> Accounts { get; set; }
public DbSet<HttpCookieEntity> HttpCookies { get; set; }
public DbSet<MediaEntity> Media { get; set; }
public DbSet<MediaFormatEntity> MediaFormats { get; set; }
public DbSet<PlaylistEntity> Playlists { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CaptionEntity>(ce =>
{
ce.ToTable("captions");
ce.HasKey(x => new { x.MediaId, x.LanguageCode });
});
modelBuilder.Entity<ChannelEntity>(channel =>
{
channel.ToTable("channels");
channel.HasKey(x => x.Id);
});
modelBuilder.Entity<ClientAccountEntity>(cae =>
{
cae.ToTable("client_accounts");
cae.HasKey(x => x.Id);
});
modelBuilder.Entity<HttpCookieEntity>(httpce =>
{
httpce.ToTable("http_cookies");
});
modelBuilder.Entity<MediaEntity>(me =>
{
me.ToTable("media");
me.HasKey(x => x.Id);
me.HasMany(x => x.Formats)
.WithOne()
.HasForeignKey(mf => mf.MediaId);
me.HasMany(x => x.Captions)
.WithOne()
.HasForeignKey(ce => ce.MediaId);
});
modelBuilder.Entity<MediaFormatEntity>(mfe =>
{
mfe.ToTable("media_formats");
mfe.HasKey(x => new { x.MediaId, x.Itag });
});
modelBuilder.Entity<PlaylistEntity>(ple =>
{
ple.ToTable("playlists");
ple.HasKey(x => x.Id);
});
/* Join tables */
modelBuilder.Entity<PlaylistMedia>(pmj =>
{
pmj.ToTable("join_playlist_media");
pmj.HasKey(x => new { x.PlaylistId, x.MediaId });
pmj.HasOne<PlaylistEntity>()
.WithMany(pe => pe.PlaylistMedias)
.HasForeignKey(fk => fk.PlaylistId);
pmj.HasOne<MediaEntity>()
.WithMany(me => me.PlaylistMedias)
.HasForeignKey(fk => fk.MediaId);
});
base.OnModelCreating(modelBuilder);
}
}

View File

@@ -0,0 +1,10 @@
namespace Manager.Data;
public static class DataConstants
{
public static class DbContext
{
public const int DefaultDbStringSize = 100;
public const int DefaultDbDescriptionStringSize = 500;
}
}

View File

@@ -1,11 +1,17 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Models.ApplicationContext;
public class SettingsModel
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Key { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Name { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
public required string Description { get; set; }
public Guid? GroupId { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string ValueType { get; set; } = nameof(String);
public object? Value { get; set; }
public object? DefaultValue { get; set; }

View File

@@ -1,9 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Models.LibraryContext;
public class CaptionEntity
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string MediaId { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Name { get; set; }
public required string CaptionPath { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? LanguageCode { get; set; }
}

View File

@@ -1,15 +1,17 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Models.LibraryContext;
public class ChannelEntity
public class ChannelEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Name { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
public string? Description { get; set; }
public DateTime JoinedDate { get; set; }
public long Subscribers { get; set; }
public long TotalVideos { get; set; }
public long TotalViews { get; set; }
public DateTime AddedDate { get; set; }
public DateTime ModifiedDate { get; set; }
}

View File

@@ -1,8 +1,11 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Models.LibraryContext;
public class ClientAccountEntity : DateTimeBase
{
public Guid Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string Name { get; set; } = "";
public List<PlaylistEntity> Playlists { get; set; } = [];
public List<HttpCookieEntity> HttpCookies { get; set; } = [];

View File

@@ -1,15 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Models.LibraryContext;
public class HttpCookieEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Name { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Value { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Domain { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Path { get; set; }
public DateTimeOffset? ExpiresUtc { get; set; }
public bool Secure { get; set; }
public bool HttpOnly { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? SameSite { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string ClientId { get; set; }
}

View File

@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Models.LibraryContext.Join;
public class PlaylistMedia
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string PlaylistId { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string MediaId { get; set; }
public DateTime DateAddedUtc { get; set; }
public DateTime DateModifiedUtc { get; set; }
}

View File

@@ -1,21 +1,29 @@
using System.ComponentModel.DataAnnotations;
using Manager.Data.Models.LibraryContext.Join;
namespace Manager.Data.Models.LibraryContext;
public class MediaEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Title { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
public string? Description { get; set; }
public DateTime UploadDateUtc { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string ChannelId { get; set; }
public List<MediaFormatEntity> Formats { get; set; } = [];
public List<CaptionEntity> Captions { get; set; } = [];
public List<PlaylistMedia> PlaylistMedias { get; set; } = [];
public MediaState State { get; set; } = MediaState.Online;
public MediaExternalState ExternalState { get; set; } = MediaExternalState.Online;
public bool IsDownloaded { get; set; }
public MediaProcessState ProcessState { get; set; } = MediaProcessState.ToDownload;
public MediaState State { get; set; } = MediaState.Indexed;
}
public enum MediaState
public enum MediaExternalState
{
Online,
Offline,
@@ -23,11 +31,13 @@ public enum MediaState
Removed
}
public enum MediaProcessState
[Flags]
public enum MediaState
{
ToDownload,
Downloaded,
ToRemove,
Removed,
Failed
None = 0,
Indexed = 1 << 0,
Downloading = 1 << 1,
Downloaded = 1 << 2,
Remove = 1 << 3,
Failed = 1 << 4,
}

View File

@@ -1,12 +1,16 @@
using System.ComponentModel.DataAnnotations;
namespace Manager.Data.Models.LibraryContext;
public class MediaFormatEntity
{
// Id = <contentid>_<itag> example: 58Gh4dE_123
public required string Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string MediaId { get; set; }
public required int Itag { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? Quality { get; set; }
public bool IsAdaptive { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? MimeType { get; set; }
public long Bitrate { get; set; }
public long AverageBitrate { get; set; }
@@ -16,8 +20,10 @@ public class MediaFormatEntity
public int? Width { get; set; }
public int? Height { get; set; }
public double? Framerate { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? QualityLabel { get; set; }
public int? AudioChannels { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? AudioSampleRate { get; set; }
public double? LoudnessDb { get; set; }
}

View File

@@ -1,9 +1,17 @@
using System.ComponentModel.DataAnnotations;
using Manager.Data.Models.LibraryContext.Join;
namespace Manager.Data.Models.LibraryContext;
public class PlaylistEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Name { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbDescriptionStringSize)]
public string? Description { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string ChannelId { get; set; }
public List<PlaylistMedia> PlaylistMedias { get; set; } = [];
}