2023-03-28 01:05:15 +05:00
|
|
|
|
using AsbCloudDb.Model.GTR;
|
|
|
|
|
using AsbCloudDb.Model.Subsystems;
|
2022-08-01 13:55:51 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-05-06 10:58:52 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-08-10 10:32:35 +05:00
|
|
|
|
using AsbCloudDb.Model.Manuals;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudDb.Model
|
|
|
|
|
{
|
|
|
|
|
public partial class AsbCloudDbContext : DbContext, IAsbCloudDbContext
|
|
|
|
|
{
|
2022-05-06 10:58:52 +05:00
|
|
|
|
public virtual DbSet<Cluster> Clusters => Set<Cluster>();
|
|
|
|
|
public virtual DbSet<Company> Companies => Set<Company>();
|
|
|
|
|
public virtual DbSet<CompanyType> CompaniesTypes => Set<CompanyType>();
|
2022-07-25 18:02:39 +05:00
|
|
|
|
public virtual DbSet<DailyReport.DailyReport> DailyReports => Set <DailyReport.DailyReport >();
|
2022-05-06 10:58:52 +05:00
|
|
|
|
public virtual DbSet<Deposit> Deposits => Set<Deposit>();
|
|
|
|
|
public virtual DbSet<DetectedOperation> DetectedOperations => Set<DetectedOperation>();
|
2023-01-11 14:59:54 +05:00
|
|
|
|
public virtual DbSet<PlannedTrajectory> PlannedTrajectories => Set<PlannedTrajectory>();
|
2022-12-05 12:39:25 +05:00
|
|
|
|
public virtual DbSet<ProcessMap> ProcessMap => Set<ProcessMap>();
|
2022-05-06 10:58:52 +05:00
|
|
|
|
public virtual DbSet<DrillingProgramPart> DrillingProgramParts => Set<DrillingProgramPart>();
|
|
|
|
|
public virtual DbSet<FileCategory> FileCategories => Set<FileCategory>();
|
|
|
|
|
public virtual DbSet<FileInfo> Files => Set<FileInfo>();
|
|
|
|
|
public virtual DbSet<FileMark> FileMarks => Set<FileMark>();
|
|
|
|
|
public virtual DbSet<Measure> Measures => Set<Measure>();
|
|
|
|
|
public virtual DbSet<MeasureCategory> MeasureCategories => Set<MeasureCategory>();
|
|
|
|
|
public virtual DbSet<Permission> Permissions => Set<Permission>();
|
|
|
|
|
public virtual DbSet<RelationCompanyWell> RelationCompaniesWells => Set<RelationCompanyWell>();
|
|
|
|
|
public virtual DbSet<RelationUserDrillingProgramPart> RelationDrillingProgramPartUsers => Set<RelationUserDrillingProgramPart>();
|
|
|
|
|
public virtual DbSet<RelationUserRolePermission> RelationUserRolePermissions => Set<RelationUserRolePermission>();
|
|
|
|
|
public virtual DbSet<RelationUserRoleUserRole> RelationUserRoleUserRoles => Set<RelationUserRoleUserRole>();
|
|
|
|
|
public virtual DbSet<RelationUserUserRole> RelationUserUserRoles => Set<RelationUserUserRole>();
|
2023-06-21 11:44:04 +05:00
|
|
|
|
public virtual DbSet<RelationContactWell> RelationContactsWells => Set<RelationContactWell>();
|
2022-05-06 10:58:52 +05:00
|
|
|
|
public virtual DbSet<ReportProperty> ReportProperties => Set<ReportProperty>();
|
|
|
|
|
public virtual DbSet<SetpointsRequest> SetpointsRequests => Set<SetpointsRequest>();
|
2022-08-01 13:55:51 +05:00
|
|
|
|
public virtual DbSet<Subsystem> Subsystems => Set<Subsystem>();
|
|
|
|
|
public virtual DbSet<SubsystemOperationTime> SubsystemOperationTimes => Set<SubsystemOperationTime>();
|
2022-05-06 10:58:52 +05:00
|
|
|
|
public virtual DbSet<Telemetry> Telemetries => Set<Telemetry>();
|
|
|
|
|
public virtual DbSet<TelemetryDataSaub> TelemetryDataSaub => Set<TelemetryDataSaub>();
|
|
|
|
|
public virtual DbSet<TelemetryDataSaubStat> TelemetryDataSaubStats => Set<TelemetryDataSaubStat>();
|
|
|
|
|
public virtual DbSet<TelemetryDataSpin> TelemetryDataSpin => Set<TelemetryDataSpin>();
|
|
|
|
|
public virtual DbSet<TelemetryEvent> TelemetryEvents => Set<TelemetryEvent>();
|
|
|
|
|
public virtual DbSet<TelemetryMessage> TelemetryMessages => Set<TelemetryMessage>();
|
|
|
|
|
public virtual DbSet<TelemetryUser> TelemetryUsers => Set<TelemetryUser>();
|
|
|
|
|
public virtual DbSet<User> Users => Set<User>();
|
|
|
|
|
public virtual DbSet<UserRole> UserRoles => Set<UserRole>();
|
2022-07-27 18:14:07 +05:00
|
|
|
|
public virtual DbSet<UserSetting> UserSettings => Set<UserSetting>();
|
2022-05-06 10:58:52 +05:00
|
|
|
|
public virtual DbSet<Well> Wells => Set<Well>();
|
|
|
|
|
public virtual DbSet<WellComposite> WellComposites => Set<WellComposite>();
|
|
|
|
|
public virtual DbSet<WellOperation> WellOperations => Set<WellOperation>();
|
|
|
|
|
public virtual DbSet<WellOperationCategory> WellOperationCategories => Set<WellOperationCategory>();
|
|
|
|
|
public virtual DbSet<WellSectionType> WellSectionTypes => Set<WellSectionType>();
|
|
|
|
|
public virtual DbSet<WellType> WellTypes => Set<WellType>();
|
2022-05-22 21:18:43 +05:00
|
|
|
|
public virtual DbSet<Driller> Drillers => Set<Driller>();
|
2022-05-26 13:28:16 +05:00
|
|
|
|
public virtual DbSet<Schedule> Schedule => Set<Schedule>();
|
2022-06-07 16:24:05 +05:00
|
|
|
|
public virtual DbSet<OperationValue> OperationValues => Set<OperationValue>();
|
2022-09-12 08:22:46 +05:00
|
|
|
|
public virtual DbSet<WellFinalDocument> WellFinalDocuments => Set<WellFinalDocument>();
|
2022-11-18 14:29:29 +05:00
|
|
|
|
public virtual DbSet<LimitingParameter> LimitingParameter => Set<LimitingParameter>();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2023-01-10 10:49:27 +05:00
|
|
|
|
public virtual DbSet<TelemetryWirelineRunOut> TelemetryWirelineRunOut => Set<TelemetryWirelineRunOut>();
|
|
|
|
|
|
2023-03-28 01:05:15 +05:00
|
|
|
|
// GTR WITS
|
2023-04-04 21:21:06 +05:00
|
|
|
|
public DbSet<WitsItemFloat> WitsItemFloat => Set<WitsItemFloat>();
|
|
|
|
|
public DbSet<WitsItemInt> WitsItemInt => Set<WitsItemInt>();
|
|
|
|
|
public DbSet<WitsItemString> WitsItemString => Set<WitsItemString>();
|
2023-03-28 01:05:15 +05:00
|
|
|
|
|
2022-04-01 17:55:44 +05:00
|
|
|
|
// WITS
|
2022-05-06 10:58:52 +05:00
|
|
|
|
public DbSet<WITS.Record1> Record1 => Set<WITS.Record1>();
|
|
|
|
|
public DbSet<WITS.Record7> Record7 => Set<WITS.Record7>();
|
|
|
|
|
public DbSet<WITS.Record8> Record8 => Set<WITS.Record8>();
|
|
|
|
|
public DbSet<WITS.Record50> Record50 => Set<WITS.Record50>();
|
|
|
|
|
public DbSet<WITS.Record60> Record60 => Set<WITS.Record60>();
|
|
|
|
|
public DbSet<WITS.Record61> Record61 => Set<WITS.Record61>();
|
2022-12-02 10:58:19 +05:00
|
|
|
|
|
2022-12-20 11:57:29 +05:00
|
|
|
|
private static int referenceCount;
|
|
|
|
|
public static int ReferenceCount => referenceCount;
|
2022-12-02 10:58:19 +05:00
|
|
|
|
|
2023-04-21 11:22:39 +05:00
|
|
|
|
public DbSet<Faq> Faqs => Set<Faq>();
|
2023-06-28 16:36:13 +05:00
|
|
|
|
public DbSet<HelpPage> HelpPages => Set<HelpPage>();
|
2023-07-07 16:26:16 +05:00
|
|
|
|
public DbSet<Notification> Notifications => Set<Notification>();
|
|
|
|
|
public DbSet<NotificationCategory> NotificationCategories => Set<NotificationCategory>();
|
2023-08-10 10:32:35 +05:00
|
|
|
|
public DbSet<Manual> Manuals => Set<Manual>();
|
2023-09-07 12:21:54 +05:00
|
|
|
|
public DbSet<ManualDirectory> ManualDirectories => Set<ManualDirectory>();
|
2023-08-10 10:32:35 +05:00
|
|
|
|
|
2023-06-28 16:36:13 +05:00
|
|
|
|
|
2021-09-07 14:04:30 +05:00
|
|
|
|
public AsbCloudDbContext() : base()
|
2022-04-11 18:00:34 +05:00
|
|
|
|
{
|
2022-12-20 11:57:29 +05:00
|
|
|
|
Interlocked.Increment(ref referenceCount);
|
2021-09-10 11:28:57 +05:00
|
|
|
|
}
|
2021-09-07 14:04:30 +05:00
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
public AsbCloudDbContext(DbContextOptions<AsbCloudDbContext> options)
|
|
|
|
|
: base(options)
|
2021-10-31 18:01:32 +05:00
|
|
|
|
{
|
2022-12-20 11:57:29 +05:00
|
|
|
|
Interlocked.Increment(ref referenceCount);
|
2022-12-02 10:58:19 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~AsbCloudDbContext()
|
|
|
|
|
{
|
2022-12-20 11:57:29 +05:00
|
|
|
|
Interlocked.Decrement(ref referenceCount);
|
2021-09-10 11:28:57 +05:00
|
|
|
|
}
|
2021-09-07 14:04:30 +05:00
|
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
2022-12-20 11:57:29 +05:00
|
|
|
|
{
|
2021-09-07 14:04:30 +05:00
|
|
|
|
if (!optionsBuilder.IsConfigured)
|
2022-12-02 10:58:19 +05:00
|
|
|
|
optionsBuilder.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"
|
|
|
|
|
//, builder=>builder.EnableRetryOnFailure(2, System.TimeSpan.FromMinutes(1))
|
|
|
|
|
);
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
modelBuilder.HasPostgresExtension("adminpack")
|
|
|
|
|
.HasAnnotation("Relational:Collation", "Russian_Russia.1251");
|
|
|
|
|
|
2022-06-20 12:42:35 +05:00
|
|
|
|
modelBuilder.Entity<Deposit>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.Property(e => e.Timezone)
|
|
|
|
|
.HasJsonConversion();
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
modelBuilder.Entity<Cluster>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasOne(d => d.Deposit)
|
|
|
|
|
.WithMany(p => p.Clusters)
|
|
|
|
|
.HasForeignKey(d => d.IdDeposit)
|
|
|
|
|
.HasConstraintName("t_cluster_t_deposit_id_fk");
|
2022-06-20 12:42:35 +05:00
|
|
|
|
|
|
|
|
|
entity.Property(e => e.Timezone)
|
|
|
|
|
.HasJsonConversion();
|
2022-08-01 13:55:51 +05:00
|
|
|
|
});
|
2022-06-20 12:42:35 +05:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Well>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasOne(d => d.Cluster)
|
|
|
|
|
.WithMany(p => p.Wells)
|
|
|
|
|
.HasForeignKey(d => d.IdCluster)
|
|
|
|
|
.HasConstraintName("t_well_t_cluster_id_fk");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.Telemetry)
|
|
|
|
|
.WithOne(p => p.Well)
|
|
|
|
|
.HasForeignKey<Well>(d => d.IdTelemetry)
|
|
|
|
|
.OnDelete(DeleteBehavior.SetNull)
|
|
|
|
|
.HasConstraintName("t_well_t_telemetry_id_fk");
|
|
|
|
|
|
|
|
|
|
entity.Property(e => e.Timezone)
|
|
|
|
|
.HasJsonConversion();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Telemetry>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.Property(e => e.Info)
|
|
|
|
|
.HasJsonConversion();
|
|
|
|
|
|
|
|
|
|
entity.Property(e => e.TimeZone)
|
|
|
|
|
.HasJsonConversion();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
});
|
|
|
|
|
|
2021-10-12 10:39:42 +05:00
|
|
|
|
modelBuilder.Entity<WellComposite>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(
|
|
|
|
|
nameof(WellComposite.IdWell),
|
|
|
|
|
nameof(WellComposite.IdWellSrc),
|
|
|
|
|
nameof(WellComposite.IdWellSectionType));
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.Well)
|
|
|
|
|
.WithMany(p => p.WellComposites)
|
|
|
|
|
.HasForeignKey(d => d.IdWell)
|
|
|
|
|
.HasConstraintName("t_well_сomposite_t_well_id_fk");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.WellSrc)
|
|
|
|
|
.WithMany(p => p.WellCompositeSrcs)
|
|
|
|
|
.HasForeignKey(d => d.IdWellSrc)
|
|
|
|
|
.HasConstraintName("t_well_сomposite_src_t_well_id_fk");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.WellSectionType)
|
|
|
|
|
.WithMany(p => p.WellComposites)
|
2021-10-14 14:46:20 +05:00
|
|
|
|
.HasForeignKey(d => d.IdWellSectionType)
|
2021-10-12 10:39:42 +05:00
|
|
|
|
.HasConstraintName("t_well_сomposite_t_well_section_type_id_fk");
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-14 17:17:33 +05:00
|
|
|
|
modelBuilder.Entity<TelemetryDataSaub>(entity =>
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
|
|
|
|
entity.HasOne(d => d.Telemetry)
|
2021-09-14 17:17:33 +05:00
|
|
|
|
.WithMany(p => p.DataSaub)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
.HasForeignKey(d => d.IdTelemetry)
|
2021-10-01 17:37:44 +05:00
|
|
|
|
.OnDelete(DeleteBehavior.Cascade)
|
2021-09-14 17:17:33 +05:00
|
|
|
|
.HasConstraintName("t_telemetry_data_saub_t_telemetry_id_fk");
|
2021-11-13 18:47:11 +05:00
|
|
|
|
|
2022-04-01 17:55:44 +05:00
|
|
|
|
entity.HasKey(nameof(ITelemetryData.IdTelemetry), nameof(ITelemetryData.DateTime));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<WITS.RecordBase>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(nameof(ITelemetryData.IdTelemetry), nameof(ITelemetryData.DateTime));
|
2021-09-14 17:17:33 +05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<TelemetryDataSpin>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasOne(d => d.Telemetry)
|
|
|
|
|
.WithMany(p => p.DataSpin)
|
|
|
|
|
.HasForeignKey(d => d.IdTelemetry)
|
2021-10-01 17:37:44 +05:00
|
|
|
|
.OnDelete(DeleteBehavior.Cascade)
|
2021-09-14 17:17:33 +05:00
|
|
|
|
.HasConstraintName("t_telemetry_data_spin_t_telemetry_id_fk");
|
2021-11-13 18:47:11 +05:00
|
|
|
|
|
2022-04-01 17:55:44 +05:00
|
|
|
|
entity.HasKey(nameof(ITelemetryData.IdTelemetry), nameof(ITelemetryData.DateTime));
|
2021-04-02 17:28:07 +05:00
|
|
|
|
});
|
|
|
|
|
|
2021-08-10 15:53:11 +05:00
|
|
|
|
modelBuilder.Entity<TelemetryMessage>(entity =>
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
|
|
|
|
entity.HasOne(d => d.Telemetry)
|
|
|
|
|
.WithMany(p => p.Messages)
|
|
|
|
|
.HasForeignKey(d => d.IdTelemetry)
|
2021-10-01 17:37:44 +05:00
|
|
|
|
.OnDelete(DeleteBehavior.Cascade)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
.HasConstraintName("t_messages_t_telemetry_id_fk");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<TelemetryUser>(entity =>
|
|
|
|
|
{
|
2021-04-23 10:21:25 +05:00
|
|
|
|
entity.HasKey(nameof(TelemetryUser.IdTelemetry), nameof(TelemetryUser.IdUser));
|
2021-04-02 17:28:07 +05:00
|
|
|
|
entity.HasOne(d => d.Telemetry)
|
2021-04-23 10:21:25 +05:00
|
|
|
|
.WithMany(p => p.Users)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
.HasForeignKey(d => d.IdTelemetry)
|
2021-10-01 17:37:44 +05:00
|
|
|
|
.OnDelete(DeleteBehavior.Cascade)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
.HasConstraintName("t_telemetry_user_t_telemetry_id_fk");
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-10 15:53:11 +05:00
|
|
|
|
modelBuilder.Entity<TelemetryEvent>(entity =>
|
2021-04-23 10:21:25 +05:00
|
|
|
|
{
|
2021-08-10 15:53:11 +05:00
|
|
|
|
entity.HasKey(nameof(TelemetryEvent.IdTelemetry), nameof(TelemetryEvent.IdEvent));
|
2021-04-23 10:21:25 +05:00
|
|
|
|
entity.HasOne(d => d.Telemetry)
|
|
|
|
|
.WithMany(p => p.Events)
|
|
|
|
|
.HasForeignKey(d => d.IdTelemetry)
|
2021-10-01 17:37:44 +05:00
|
|
|
|
.OnDelete(DeleteBehavior.Cascade)
|
2021-04-23 10:21:25 +05:00
|
|
|
|
.HasConstraintName("t_event_t_telemetry_id_fk");
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
modelBuilder.Entity<User>(entity =>
|
|
|
|
|
{
|
2021-07-21 12:30:51 +05:00
|
|
|
|
entity.HasOne(d => d.Company)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
.WithMany(p => p.Users)
|
2021-07-21 12:30:51 +05:00
|
|
|
|
.HasForeignKey(d => d.IdCompany)
|
2021-10-01 17:37:44 +05:00
|
|
|
|
.OnDelete(DeleteBehavior.SetNull)
|
2021-07-21 15:22:58 +05:00
|
|
|
|
.HasConstraintName("t_user_t_company_id_fk");
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
entity.HasIndex(d => d.Login)
|
|
|
|
|
.IsUnique();
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-09 15:41:42 +05:00
|
|
|
|
modelBuilder.Entity<RelationCompanyWell>(entity =>
|
|
|
|
|
{
|
2021-07-21 16:30:57 +05:00
|
|
|
|
entity.HasKey(nameof(RelationCompanyWell.IdCompany), nameof(RelationCompanyWell.IdWell));
|
|
|
|
|
|
|
|
|
|
entity.HasOne(r => r.Well)
|
|
|
|
|
.WithMany(w => w.RelationCompaniesWells)
|
|
|
|
|
.HasForeignKey(r => r.IdWell)
|
|
|
|
|
.HasConstraintName("t_relation_company_well_t_well_id_fk");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(r => r.Company)
|
|
|
|
|
.WithMany(w => w.RelationCompaniesWells)
|
|
|
|
|
.HasForeignKey(r => r.IdCompany)
|
|
|
|
|
.HasConstraintName("t_relation_company_well_t_company_id_fk");
|
|
|
|
|
});
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
modelBuilder.Entity<RelationUserRoleUserRole>(entity =>
|
|
|
|
|
{
|
2022-01-12 16:33:53 +05:00
|
|
|
|
entity.HasKey(x => new { x.Id, x.IdInclude })
|
|
|
|
|
.HasName("t_relation_user_role_user_role_pk");
|
|
|
|
|
});
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
modelBuilder.Entity<RelationUserDrillingProgramPart>(entity =>
|
|
|
|
|
{
|
2022-02-09 14:25:22 +05:00
|
|
|
|
entity.HasKey(x => new { x.IdUser, x.IdDrillingProgramPart })
|
|
|
|
|
.HasName("t_relation_user_drilling_program_part_pk");
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-13 17:25:06 +05:00
|
|
|
|
modelBuilder.Entity<WellOperation>(entity =>
|
2021-08-13 15:37:33 +05:00
|
|
|
|
{
|
2021-10-08 11:30:06 +05:00
|
|
|
|
entity.HasIndex(d => d.DepthEnd);
|
|
|
|
|
entity.HasIndex(d => d.DateStart);
|
2021-08-13 15:37:33 +05:00
|
|
|
|
});
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
modelBuilder.Entity<DrillingProgramPart>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasIndex(x => new { x.IdWell, x.IdFileCategory })
|
2022-02-12 11:28:16 +05:00
|
|
|
|
.IsUnique();
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-20 12:42:35 +05:00
|
|
|
|
modelBuilder.Entity<Measure>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.Property(e => e.Data)
|
|
|
|
|
.HasJsonConversion();
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-01 16:41:25 +05:00
|
|
|
|
modelBuilder.Entity<FileMark>(entity =>
|
|
|
|
|
{
|
2021-11-09 17:24:30 +05:00
|
|
|
|
entity.HasOne(d => d.User)
|
2021-11-01 16:41:25 +05:00
|
|
|
|
.WithMany(p => p.FileMarks)
|
|
|
|
|
.HasForeignKey(d => d.IdUser)
|
2022-04-11 18:00:34 +05:00
|
|
|
|
.OnDelete(DeleteBehavior.Cascade)
|
2021-11-01 16:41:25 +05:00
|
|
|
|
.HasConstraintName("t_user_t_file_mark_fk");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.FileInfo)
|
|
|
|
|
.WithMany(p => p.FileMarks)
|
|
|
|
|
.HasForeignKey(d => d.IdFile)
|
|
|
|
|
.OnDelete(DeleteBehavior.Cascade)
|
|
|
|
|
.HasConstraintName("t_file_mark_t_file_info_fk");
|
|
|
|
|
});
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-11-29 17:34:53 +05:00
|
|
|
|
modelBuilder.Entity<RelationUserUserRole>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(e => new { e.IdUser, e.IdUserRole });
|
|
|
|
|
});
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-12-15 16:21:52 +05:00
|
|
|
|
modelBuilder.Entity<RelationUserRolePermission>(entity =>
|
2021-11-29 17:34:53 +05:00
|
|
|
|
{
|
2021-12-15 16:21:52 +05:00
|
|
|
|
entity.HasKey(e => new { e.IdUserRole, e.IdPermission });
|
2021-12-20 15:16:21 +05:00
|
|
|
|
|
|
|
|
|
entity.HasOne(r => r.Permission)
|
|
|
|
|
.WithMany(p => p.RelationUserRolePermissions)
|
|
|
|
|
.IsRequired();
|
|
|
|
|
|
|
|
|
|
entity.HasOne(r => r.UserRole)
|
|
|
|
|
.WithMany(r => r.RelationUserRolePermissions)
|
|
|
|
|
.IsRequired();
|
2021-11-29 17:34:53 +05:00
|
|
|
|
});
|
2021-10-10 13:35:43 +05:00
|
|
|
|
|
2022-07-25 18:02:39 +05:00
|
|
|
|
modelBuilder.Entity<DailyReport.DailyReport >(entity =>
|
2022-04-20 18:03:38 +05:00
|
|
|
|
{
|
|
|
|
|
entity.HasKey(e => new { e.IdWell, e.StartDate })
|
|
|
|
|
.HasName("t_id_well_date_start_pk");
|
2022-06-20 12:42:35 +05:00
|
|
|
|
entity.Property(e => e.Info)
|
|
|
|
|
.HasJsonConversion();
|
2022-04-20 18:03:38 +05:00
|
|
|
|
});
|
|
|
|
|
|
2022-05-06 10:58:52 +05:00
|
|
|
|
modelBuilder.Entity<TelemetryDataSaubStat>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasNoKey()
|
|
|
|
|
.ToView("mw_telemetry_datas_saub_stat");
|
|
|
|
|
});
|
|
|
|
|
|
2022-05-26 13:28:16 +05:00
|
|
|
|
modelBuilder.Entity<Schedule>(entity =>
|
2022-05-25 20:19:08 +05:00
|
|
|
|
{
|
|
|
|
|
entity.HasOne(d => d.Driller)
|
|
|
|
|
.WithMany(p => p.Schedule)
|
|
|
|
|
.HasForeignKey(d => d.IdDriller)
|
|
|
|
|
.HasConstraintName("t_schedule_t_driller_id_driller");
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-20 12:42:35 +05:00
|
|
|
|
modelBuilder.Entity<SetpointsRequest>(entity => {
|
|
|
|
|
entity.Property(e => e.Setpoints)
|
|
|
|
|
.HasJsonConversion();
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-04 21:21:06 +05:00
|
|
|
|
modelBuilder.Entity<WitsItemFloat>(entity =>
|
|
|
|
|
{
|
2023-03-28 01:05:15 +05:00
|
|
|
|
entity.HasKey(
|
|
|
|
|
nameof(ITelemetryData.IdTelemetry),
|
2023-03-31 11:10:16 +05:00
|
|
|
|
nameof(WitsItemBase<float>.IdRecord),
|
2023-04-07 17:58:46 +05:00
|
|
|
|
nameof(WitsItemBase<float>.IdItem),
|
|
|
|
|
nameof(WitsItemBase<float>.DateTime));
|
|
|
|
|
});
|
2023-04-04 21:21:06 +05:00
|
|
|
|
modelBuilder.Entity<WitsItemInt>(entity =>
|
2023-03-29 00:06:16 +05:00
|
|
|
|
{
|
|
|
|
|
entity.HasKey(
|
|
|
|
|
nameof(ITelemetryData.IdTelemetry),
|
2023-03-31 11:10:16 +05:00
|
|
|
|
nameof(WitsItemBase<int>.IdRecord),
|
2023-04-07 17:58:46 +05:00
|
|
|
|
nameof(WitsItemBase<int>.IdItem),
|
|
|
|
|
nameof(WitsItemBase<int>.DateTime));
|
2023-03-29 00:06:16 +05:00
|
|
|
|
});
|
2023-04-04 21:21:06 +05:00
|
|
|
|
modelBuilder.Entity<WitsItemString>(entity =>
|
2023-03-29 00:06:16 +05:00
|
|
|
|
{
|
|
|
|
|
entity.HasKey(
|
|
|
|
|
nameof(ITelemetryData.IdTelemetry),
|
2023-03-31 11:10:16 +05:00
|
|
|
|
nameof(WitsItemBase<string>.IdRecord),
|
2023-04-07 17:58:46 +05:00
|
|
|
|
nameof(WitsItemBase<string>.IdItem),
|
|
|
|
|
nameof(WitsItemBase<string>.DateTime));
|
2023-03-28 01:05:15 +05:00
|
|
|
|
});
|
|
|
|
|
|
2022-08-08 16:45:20 +05:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<UserSetting>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(nameof(UserSetting.IdUser), nameof(UserSetting.Key));
|
|
|
|
|
});
|
2022-09-12 08:22:46 +05:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<WellFinalDocument>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(x => new { x.IdWell, x.IdUser, x.IdCategory })
|
|
|
|
|
.HasName("t_well_final_documents_pk");
|
|
|
|
|
});
|
2022-08-08 16:45:20 +05:00
|
|
|
|
|
2023-06-21 11:44:04 +05:00
|
|
|
|
modelBuilder.Entity<RelationContactWell>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(x => new { x.IdWell, x.IdUser });
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-07 12:21:54 +05:00
|
|
|
|
modelBuilder.Entity<ManualDirectory>()
|
2023-08-10 10:32:35 +05:00
|
|
|
|
.HasOne(mf => mf.Parent)
|
|
|
|
|
.WithMany(mf => mf.Children)
|
|
|
|
|
.HasForeignKey(mf => mf.IdParent)
|
|
|
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Manual>()
|
2023-09-07 12:21:54 +05:00
|
|
|
|
.HasOne(m => m.Directory)
|
2023-08-10 10:32:35 +05:00
|
|
|
|
.WithMany(f => f.Manuals)
|
2023-09-07 12:21:54 +05:00
|
|
|
|
.HasForeignKey(m => m.IdDirectory)
|
2023-08-10 10:32:35 +05:00
|
|
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
|
|
2022-08-08 16:45:20 +05:00
|
|
|
|
DefaultData.DefaultContextData.Fill(modelBuilder);
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 17:33:32 +05:00
|
|
|
|
public Task<int> RefreshMaterializedViewAsync<TEntity>(CancellationToken token)
|
2022-05-06 10:58:52 +05:00
|
|
|
|
where TEntity : class
|
|
|
|
|
{
|
2022-07-04 17:33:32 +05:00
|
|
|
|
var materializedViewName = Set<TEntity>().EntityType.GetViewName()
|
|
|
|
|
?? throw new System.Exception($"RefreshMaterializedViewAsync<{typeof(TEntity).Name}>(..) db table for this type does not found.");
|
|
|
|
|
return RefreshMaterializedViewAsync(materializedViewName, token);
|
2022-05-11 09:04:32 +05:00
|
|
|
|
}
|
2022-05-06 10:58:52 +05:00
|
|
|
|
|
2022-07-04 17:33:32 +05:00
|
|
|
|
public Task<int> RefreshMaterializedViewAsync(string materializedViewName, CancellationToken token)
|
2022-05-11 09:04:32 +05:00
|
|
|
|
{
|
|
|
|
|
var sql = $"REFRESH MATERIALIZED VIEW {materializedViewName};";
|
2022-05-06 10:58:52 +05:00
|
|
|
|
return Database.ExecuteSqlRawAsync(sql, token);
|
2023-02-09 11:38:04 +05:00
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
}
|