feat: add postgresql configurations
This commit is contained in:
		| @@ -0,0 +1,20 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public sealed class CampusConfiguration : IEntityTypeConfiguration<Campus> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Campus> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(Campus)); | ||||
|         builder.HasKey(c => c.Id); | ||||
|         builder.HasIndex(c => c.Id).IsUnique(); | ||||
|         builder.Property(c => c.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(c => c.Address).HasColumnType("text").HasMaxLength(512); | ||||
|         builder.Property(c => c.CodeName).HasColumnType("text").IsRequired().HasMaxLength(16); | ||||
|         builder.Property(c => c.FullName).HasColumnType("text").HasMaxLength(256); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,18 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class DisciplineConfiguration : IEntityTypeConfiguration<Discipline> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Discipline> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(Discipline)); | ||||
|         builder.HasKey(d => d.Id); | ||||
|         builder.HasIndex(d => d.Id).IsUnique(); | ||||
|         builder.Property(d => d.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(d => d.Name).HasColumnType("text").HasMaxLength(256).IsRequired(); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,26 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class FacultyConfiguration : IEntityTypeConfiguration<Faculty> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Faculty> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(Faculty)); | ||||
|         builder.HasKey(f => f.Id); | ||||
|         builder.HasIndex(f => f.Id).IsUnique(); | ||||
|         builder.Property(f => f.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(f => f.Name).HasColumnType("text").IsRequired().HasMaxLength(256); | ||||
|  | ||||
|         builder.Property(f => f.CampusId).HasColumnType("serial"); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(f => f.Campus) | ||||
|             .WithMany(c => c.Faculties) | ||||
|             .HasForeignKey(c => c.CampusId) | ||||
|             .OnDelete(DeleteBehavior.SetNull); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,25 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class GroupConfiguration : IEntityTypeConfiguration<Group> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Group> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(Group)); | ||||
|         builder.HasKey(g => g.Id); | ||||
|         builder.HasIndex(g => g.Id).IsUnique(); | ||||
|         builder.Property(g => g.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(g => g.FacultyId).HasColumnType("serial"); | ||||
|         builder.Property(g => g.Name).HasColumnType("text").IsRequired().HasMaxLength(64); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(g => g.Faculty) | ||||
|             .WithMany(u => u.Groups) | ||||
|             .HasForeignKey(d => d.FacultyId) | ||||
|             .OnDelete(DeleteBehavior.SetNull); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,25 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class LectureHallConfiguration : IEntityTypeConfiguration<LectureHall> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<LectureHall> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(LectureHall)); | ||||
|         builder.HasKey(l => l.Id); | ||||
|         builder.HasIndex(l => l.Id).IsUnique(); | ||||
|         builder.Property(l => l.Id).HasColumnType("INT").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(l => l.CampusId).HasColumnType("INT").IsRequired(); | ||||
|         builder.Property(l => l.Name).HasColumnType("VARCHAR(64)").IsRequired().HasMaxLength(64); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(l => l.Campus) | ||||
|             .WithMany(c => c.LectureHalls) | ||||
|             .HasForeignKey(d => d.CampusId) | ||||
|             .OnDelete(DeleteBehavior.Restrict); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,48 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class LessonAssociationConfiguration : IEntityTypeConfiguration<LessonAssociation> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<LessonAssociation> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(LessonAssociation)); | ||||
|         builder.HasKey(l => l.Id); | ||||
|         builder.HasIndex(l => l.Id).IsUnique(); | ||||
|         builder.Property(l => l.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(l => l.LinkToMeet).HasColumnType("text").HasMaxLength(512); | ||||
|  | ||||
|         builder.Property(l => l.LessonId).HasColumnType("serial").IsRequired(); | ||||
|         builder.Property(l => l.ProfessorId).HasColumnType("serial"); | ||||
|         builder.Property(l => l.LectureHallId).HasColumnType("serial"); | ||||
|         builder.Property(l => l.TypeOfOccupationId).HasColumnType("serial").IsRequired(); | ||||
|  | ||||
|  | ||||
|         builder | ||||
|             .HasOne(l => l.Lesson) | ||||
|             .WithMany(d => d.LessonAssociations) | ||||
|             .HasForeignKey(l => l.LessonId) | ||||
|             .OnDelete(DeleteBehavior.Cascade); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(l => l.Professor) | ||||
|             .WithMany(p => p.LessonAssociations) | ||||
|             .HasForeignKey(l => l.ProfessorId) | ||||
|             .OnDelete(DeleteBehavior.SetNull); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(l => l.LectureHall) | ||||
|             .WithMany(l => l.LessonAssociations) | ||||
|             .HasForeignKey(l => l.LectureHallId) | ||||
|             .OnDelete(DeleteBehavior.SetNull); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(l => l.TypeOfOccupation) | ||||
|             .WithMany(t => t.Lessons) | ||||
|             .HasForeignKey(d => d.TypeOfOccupationId) | ||||
|             .OnDelete(DeleteBehavior.Cascade); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,36 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class LessonConfiguration : IEntityTypeConfiguration<Lesson> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Lesson> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(Lesson)); | ||||
|         builder.HasKey(l => l.Id); | ||||
|         builder.HasIndex(l => l.Id).IsUnique(); | ||||
|         builder.Property(l => l.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(l => l.IsEven).HasColumnType("boolean").IsRequired(); | ||||
|         builder.Property(l => l.DayOfWeek).HasColumnType("serial").IsRequired(); | ||||
|         builder.Property(l => l.PairNumber).HasColumnType("serial").IsRequired(); | ||||
|         builder.Property(l => l.IsExcludedWeeks).HasColumnType("boolean"); | ||||
|  | ||||
|         builder.Property(l => l.GroupId).HasColumnType("serial").IsRequired(); | ||||
|         builder.Property(l => l.DisciplineId).HasColumnType("serial").IsRequired(); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(l => l.Group) | ||||
|             .WithMany(g => g.Lessons) | ||||
|             .HasForeignKey(d => d.GroupId) | ||||
|             .OnDelete(DeleteBehavior.Cascade); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(l => l.Discipline) | ||||
|             .WithMany(d => d.Lessons) | ||||
|             .HasForeignKey(l => l.DisciplineId) | ||||
|             .OnDelete(DeleteBehavior.Cascade); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class ProfessorConfiguration : IEntityTypeConfiguration<Professor> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Professor> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(Professor)); | ||||
|         builder.HasKey(p => p.Id); | ||||
|         builder.HasIndex(p => p.Id).IsUnique(); | ||||
|         builder.Property(p => p.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(p => p.Name).HasColumnType("text").IsRequired(); | ||||
|         builder.Property(p => p.AltName).HasColumnType("text"); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,26 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class SpecificWeekConfiguration : IEntityTypeConfiguration<SpecificWeek> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<SpecificWeek> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(SpecificWeek)); | ||||
|         builder.HasKey(s => s.Id); | ||||
|         builder.HasIndex(s => s.Id).IsUnique(); | ||||
|         builder.Property(s => s.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(s => s.WeekNumber).HasColumnType("serial").IsRequired(); | ||||
|  | ||||
|         builder.Property(s => s.LessonId).HasColumnType("serial").IsRequired(); | ||||
|  | ||||
|         builder | ||||
|             .HasOne(s => s.Lesson) | ||||
|             .WithMany(l => l.SpecificWeeks) | ||||
|             .HasForeignKey(s => s.LessonId) | ||||
|             .OnDelete(DeleteBehavior.Cascade); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,18 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| using Mirea.Api.DataAccess.Domain.Schedule; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Postgresql.Schedule; | ||||
|  | ||||
| public class TypeOfOccupationConfiguration : IEntityTypeConfiguration<TypeOfOccupation> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<TypeOfOccupation> builder) | ||||
|     { | ||||
|         builder.ToTable(nameof(TypeOfOccupation)); | ||||
|         builder.HasKey(t => t.Id); | ||||
|         builder.HasIndex(t => t.Id).IsUnique(); | ||||
|         builder.Property(t => t.Id).HasColumnType("serial").IsRequired().ValueGeneratedOnAdd(); | ||||
|  | ||||
|         builder.Property(t => t.ShortName).HasColumnType("text").IsRequired().HasMaxLength(16); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user