From 8e0c099867ec641c9aec787e8057c1d704c6f637 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Thu, 24 Sep 2026 10:25:07 +0200 Subject: [PATCH] Stable multitenancy --- .../Services/Shared/AuditService.cs | 2 +- .../Abstractions/ITenantEntity.cs | 6 + .../Entities/Activity.cs | 13 +- .../Entities/AuditLog.cs | 6 +- PostFundManagement.Domain/Entities/Award.cs | 15 +- .../Entities/Beneficiary.cs | 15 +- PostFundManagement.Domain/Entities/Budget.cs | 13 +- .../Entities/ChangeRequest.cs | 13 +- .../Entities/ComplianceItem.cs | 7 +- .../Entities/Contract.cs | 15 +- .../Entities/Disbursement.cs | 14 +- .../Entities/Evidence.cs | 14 +- .../Entities/Indicator.cs | 13 +- .../Entities/Instrument.cs | 13 +- PostFundManagement.Domain/Entities/Invite.cs | 14 +- PostFundManagement.Domain/Entities/Issue.cs | 13 +- .../Entities/Milestone.cs | 13 +- .../Entities/Notification.cs | 4 +- .../Entities/Organisation.cs | 1 - PostFundManagement.Domain/Entities/Outcome.cs | 1 - .../Entities/Portfolio.cs | 6 +- .../Entities/Programme.cs | 6 +- PostFundManagement.Domain/Entities/Project.cs | 6 +- PostFundManagement.Domain/Entities/Risk.cs | 13 +- PostFundManagement.Domain/Entities/Rule.cs | 13 +- .../Entities/SiteVisit.cs | 15 +- PostFundManagement.Domain/Entities/Tenant.cs | 9 - .../Entities/TenantOrganisation.cs | 3 +- .../Entities/TenantUser.cs | 5 +- PostFundManagement.Domain/Entities/User.cs | 1 - PostFundManagement.Domain/Models/Activity.cs | 2 + .../Models/AuditChanges.cs | 6 + PostFundManagement.Domain/Models/AuditLog.cs | 3 +- .../Models/Beneficiary.cs | 2 + PostFundManagement.Domain/Models/Budget.cs | 2 + .../Models/ChangeRequest.cs | 2 + .../Models/ComplianceItem.cs | 2 + PostFundManagement.Domain/Models/Contract.cs | 2 + .../Models/Disbursement.cs | 2 + PostFundManagement.Domain/Models/Evidence.cs | 2 + PostFundManagement.Domain/Models/Indicator.cs | 2 + .../Models/Instrument.cs | 2 + PostFundManagement.Domain/Models/Invite.cs | 2 + PostFundManagement.Domain/Models/Issue.cs | 2 + PostFundManagement.Domain/Models/Milestone.cs | 2 + PostFundManagement.Domain/Models/Risk.cs | 2 + PostFundManagement.Domain/Models/Rule.cs | 2 + PostFundManagement.Domain/Models/SiteVisit.cs | 2 + .../PostFundManagement.Domain.csproj | 1 + .../Database/ApplicationDbContext.cs | 67 +- ...23052735_OptimisedMultitenancy.Designer.cs | 2272 +++++++ .../20260923052735_OptimisedMultitenancy.cs | 5767 +++++++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 1072 +-- .../PostFundManagement.Infrastructure.csproj | 1 + 54 files changed, 8900 insertions(+), 603 deletions(-) create mode 100644 PostFundManagement.Domain/Abstractions/ITenantEntity.cs create mode 100644 PostFundManagement.Domain/Models/AuditChanges.cs create mode 100644 PostFundManagement.Infrastructure/Database/Migrations/20260923052735_OptimisedMultitenancy.Designer.cs create mode 100644 PostFundManagement.Infrastructure/Database/Migrations/20260923052735_OptimisedMultitenancy.cs diff --git a/PostFundManagement.Application/Services/Shared/AuditService.cs b/PostFundManagement.Application/Services/Shared/AuditService.cs index 25ce543..045dfe5 100644 --- a/PostFundManagement.Application/Services/Shared/AuditService.cs +++ b/PostFundManagement.Application/Services/Shared/AuditService.cs @@ -15,7 +15,7 @@ public sealed class AuditService(IDbContextFactory context { EntityId = entityId, Action = action, - Changes = changes, + Changes = new Domain.Models.AuditChanges { Logs = changes }, EntityName = entityName, PerformedBy = performedBy, Timestamp = DateTime.UtcNow, diff --git a/PostFundManagement.Domain/Abstractions/ITenantEntity.cs b/PostFundManagement.Domain/Abstractions/ITenantEntity.cs new file mode 100644 index 0000000..21db6cc --- /dev/null +++ b/PostFundManagement.Domain/Abstractions/ITenantEntity.cs @@ -0,0 +1,6 @@ +namespace PostFundManagement.Domain.Abstractions; + +public interface ITenantEntity +{ + public long TenantId { get; set; } +} diff --git a/PostFundManagement.Domain/Entities/Activity.cs b/PostFundManagement.Domain/Entities/Activity.cs index 5f2f657..872af35 100644 --- a/PostFundManagement.Domain/Entities/Activity.cs +++ b/PostFundManagement.Domain/Entities/Activity.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Activity : Models.Activity +public class Activity : Models.Activity, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual User? Creator { get; set; } public virtual User? Updator { get; set; } @@ -26,6 +28,7 @@ public sealed class ActivityConfiguration : IEntityTypeConfiguration builder.HasKey(pk => pk.Id); builder.Property(f => f.ProjectId).IsRequired(); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.MilestoneId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.UpdatedBy).IsRequired(false); @@ -40,6 +43,12 @@ public sealed class ActivityConfiguration : IEntityTypeConfiguration builder.Property(f => f.Title).IsRequired().HasMaxLength(LabelLength); builder.Property(f => f.Description).IsRequired().HasMaxLength(TextLength); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/AuditLog.cs b/PostFundManagement.Domain/Entities/AuditLog.cs index 0a4a13e..c93bf36 100644 --- a/PostFundManagement.Domain/Entities/AuditLog.cs +++ b/PostFundManagement.Domain/Entities/AuditLog.cs @@ -1,8 +1,8 @@ +using PostFundManagement.Domain.Models; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] public sealed class AuditLog : Models.AuditLog; public sealed class AuditLogConfiguration : IEntityTypeConfiguration @@ -16,7 +16,9 @@ public sealed class AuditLogConfiguration : IEntityTypeConfiguration builder.Property(f => f.EntityName).IsRequired().HasMaxLength(LabelLength); builder.Property(f => f.EntityId).IsRequired(); builder.Property(f => f.Action).IsRequired().HasMaxLength(ShortLabelLength); - builder.Property(f => f.Changes).IsRequired(false).HasColumnType("jsonb"); + builder.Property(f => f.Changes).IsRequired(false).HasColumnType("jsonb") + .HasConversion(model => JsonSerializer.Serialize(model, JsonSerializerOptions.Default), + provider => JsonSerializer.Deserialize(provider, JsonSerializerOptions.Default)); builder.Property(f => f.PerformedBy).IsRequired(); builder.Property(f => f.Timestamp).IsRequired().HasDefaultValueSql("now()"); } diff --git a/PostFundManagement.Domain/Entities/Award.cs b/PostFundManagement.Domain/Entities/Award.cs index 8f1aa9c..a8cdd43 100644 --- a/PostFundManagement.Domain/Entities/Award.cs +++ b/PostFundManagement.Domain/Entities/Award.cs @@ -1,7 +1,8 @@ +using PostFundManagement.Domain.Abstractions; + namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Award : Models.Award +public class Award : Models.Award, ITenantEntity { public virtual User? Creator { get; set; } @@ -41,7 +42,7 @@ public sealed class AwardConfiguration : IEntityTypeConfiguration builder.Property(f => f.Amount).IsRequired().HasPrecision(18, 2); builder.HasOne(f => f.Tenant) - .WithMany(f => f.Awards) + .WithMany() .HasForeignKey(fk => fk.TenantId) .IsRequired() .OnDelete(DeleteBehavior.Restrict); @@ -77,9 +78,9 @@ public sealed class AwardConfiguration : IEntityTypeConfiguration .OnDelete(DeleteBehavior.NoAction); builder.HasOne(f => f.Approver) - .WithMany() - .HasForeignKey(fk => fk.ApprovedBy) - .IsRequired(false) - .OnDelete(DeleteBehavior.NoAction); + .WithMany() + .HasForeignKey(fk => fk.ApprovedBy) + .IsRequired(false) + .OnDelete(DeleteBehavior.NoAction); } } \ No newline at end of file diff --git a/PostFundManagement.Domain/Entities/Beneficiary.cs b/PostFundManagement.Domain/Entities/Beneficiary.cs index 24f246a..d9dcb6a 100644 --- a/PostFundManagement.Domain/Entities/Beneficiary.cs +++ b/PostFundManagement.Domain/Entities/Beneficiary.cs @@ -1,14 +1,18 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Beneficiary : Models.Beneficiary +public class Beneficiary : Models.Beneficiary, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } + [ForeignKey(nameof(CreatedBy))] public virtual User? Creator { get; set; } + [ForeignKey(nameof(UserId))] public virtual User? User { get; set; } } @@ -19,6 +23,7 @@ public sealed class BeneficiaryConfiguration : IEntityTypeConfiguration pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.UserId).IsRequired(); @@ -29,6 +34,12 @@ public sealed class BeneficiaryConfiguration : IEntityTypeConfiguration f.ReachedCount).IsRequired(); builder.Property(f => f.Location).IsRequired(); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/Budget.cs b/PostFundManagement.Domain/Entities/Budget.cs index 497d2b3..6fedde7 100644 --- a/PostFundManagement.Domain/Entities/Budget.cs +++ b/PostFundManagement.Domain/Entities/Budget.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Budget : Models.Budget +public class Budget : Models.Budget, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual User? Creator { get; set; } @@ -19,6 +21,7 @@ public sealed class BudgetConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Budget).Pluralize()); builder.HasKey(pk => pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.ApprovedBy).IsRequired(false); @@ -27,6 +30,12 @@ public sealed class BudgetConfiguration : IEntityTypeConfiguration builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength); builder.Property(f => f.Amount).IsRequired().HasPrecision(18, 2); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/ChangeRequest.cs b/PostFundManagement.Domain/Entities/ChangeRequest.cs index e4b4f11..6698a69 100644 --- a/PostFundManagement.Domain/Entities/ChangeRequest.cs +++ b/PostFundManagement.Domain/Entities/ChangeRequest.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class ChangeRequest : Models.ChangeRequest +public class ChangeRequest : Models.ChangeRequest, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual User? Creator { get; set; } @@ -19,6 +21,7 @@ public sealed class ChangeRequestConfiguration : IEntityTypeConfiguration pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.ApprovedBy).IsRequired(false); @@ -31,6 +34,12 @@ public sealed class ChangeRequestConfiguration : IEntityTypeConfiguration f.Status).IsRequired().HasConversion().HasDefaultValueSql("1") .HasSentinel(ApprovalStatus.Pending); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/ComplianceItem.cs b/PostFundManagement.Domain/Entities/ComplianceItem.cs index 3ecf34a..e6654f6 100644 --- a/PostFundManagement.Domain/Entities/ComplianceItem.cs +++ b/PostFundManagement.Domain/Entities/ComplianceItem.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class ComplianceItem : Models.ComplianceItem +public class ComplianceItem : Models.ComplianceItem, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual User? Creator { get; set; } @@ -19,6 +21,7 @@ public sealed class ComplianceItemConfiguration : IEntityTypeConfiguration pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.VerifiedBy).IsRequired(false); diff --git a/PostFundManagement.Domain/Entities/Contract.cs b/PostFundManagement.Domain/Entities/Contract.cs index 320c9d9..7029f46 100644 --- a/PostFundManagement.Domain/Entities/Contract.cs +++ b/PostFundManagement.Domain/Entities/Contract.cs @@ -1,8 +1,11 @@ +using PostFundManagement.Domain.Abstractions; + namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Contract : Models.Contract +public class Contract : Models.Contract, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Award? Award { get; set; } public virtual User? Creator { get; set; } @@ -15,8 +18,8 @@ public sealed class ContractConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Contract).Pluralize()); builder.HasKey(pk => pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.HasIndex(f => f.AwardId).IsUnique(); - builder.Property(f => f.AwardId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); @@ -28,6 +31,12 @@ public sealed class ContractConfiguration : IEntityTypeConfiguration builder.Property(f => f.Status).IsRequired().HasConversion().HasDefaultValueSql("1") .HasSentinel(ContractStatus.Draft); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Award) .WithOne(f => f.Contract) .HasForeignKey(fk => fk.AwardId) diff --git a/PostFundManagement.Domain/Entities/Disbursement.cs b/PostFundManagement.Domain/Entities/Disbursement.cs index e59dd54..7eb1387 100644 --- a/PostFundManagement.Domain/Entities/Disbursement.cs +++ b/PostFundManagement.Domain/Entities/Disbursement.cs @@ -1,8 +1,11 @@ +using PostFundManagement.Domain.Abstractions; + namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Disbursement : Models.Disbursement +public class Disbursement : Models.Disbursement, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual Milestone? Milestone { get; set; } @@ -19,6 +22,7 @@ public sealed class DisbursementConfiguration : IEntityTypeConfiguration pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.MilestoneId).IsRequired(false); builder.Property(f => f.CreatedBy).IsRequired(); @@ -29,6 +33,12 @@ public sealed class DisbursementConfiguration : IEntityTypeConfiguration f.Status).IsRequired().HasConversion().HasDefaultValueSql("1") .HasSentinel(ApprovalStatus.Pending); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/Evidence.cs b/PostFundManagement.Domain/Entities/Evidence.cs index 2fdb509..670917d 100644 --- a/PostFundManagement.Domain/Entities/Evidence.cs +++ b/PostFundManagement.Domain/Entities/Evidence.cs @@ -1,8 +1,11 @@ +using PostFundManagement.Domain.Abstractions; + namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Evidence : Models.Evidence +public class Evidence : Models.Evidence, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual Milestone? Milestone { get; set; } @@ -23,6 +26,7 @@ public sealed class EvidenceConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Evidence).Pluralize()); builder.HasKey(f => f.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.MilestoneId).IsRequired(); builder.Property(f => f.IndicatorId).IsRequired(); @@ -38,6 +42,12 @@ public sealed class EvidenceConfiguration : IEntityTypeConfiguration builder.Property(f => f.Type).IsRequired().HasConversion().HasDefaultValueSql("9") .HasSentinel(EvidenceType.ProcurementDocument); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/Indicator.cs b/PostFundManagement.Domain/Entities/Indicator.cs index 7fbdbde..c46fbc6 100644 --- a/PostFundManagement.Domain/Entities/Indicator.cs +++ b/PostFundManagement.Domain/Entities/Indicator.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Indicator : Models.Indicator +public class Indicator : Models.Indicator, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual User? Creator { get; set; } @@ -17,6 +19,7 @@ public sealed class IndicatorConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Indicator).Pluralize()); builder.HasKey(pk => pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); @@ -26,6 +29,12 @@ public sealed class IndicatorConfiguration : IEntityTypeConfiguration builder.Property(f => f.TargetAmount).IsRequired().HasPrecision(18, 2); builder.Property(f => f.ActualAmount).IsRequired().HasPrecision(18, 2); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/Instrument.cs b/PostFundManagement.Domain/Entities/Instrument.cs index d4bd7ae..b317780 100644 --- a/PostFundManagement.Domain/Entities/Instrument.cs +++ b/PostFundManagement.Domain/Entities/Instrument.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Instrument : Models.Instrument +public class Instrument : Models.Instrument, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual User? Creator { get; set; } public virtual Programme? Programme { get; set; } @@ -17,6 +19,7 @@ public sealed class InstrumentConfiguration : IEntityTypeConfiguration pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProgrammeId).IsRequired(); builder.Property(f => f.Code).IsRequired().HasMaxLength(ShortLabelLength); builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength); @@ -26,6 +29,12 @@ public sealed class InstrumentConfiguration : IEntityTypeConfiguration f.CreatedBy).IsRequired(); builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Programme) .WithMany(f => f.Instruments) .HasForeignKey(fk => fk.ProgrammeId) diff --git a/PostFundManagement.Domain/Entities/Invite.cs b/PostFundManagement.Domain/Entities/Invite.cs index 07e3cba..c89c51e 100644 --- a/PostFundManagement.Domain/Entities/Invite.cs +++ b/PostFundManagement.Domain/Entities/Invite.cs @@ -1,8 +1,11 @@ +using PostFundManagement.Domain.Abstractions; + namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Invite : Models.Invite +public class Invite : Models.Invite, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Organisation? Organisation { get; set; } public virtual Organisation? InvitedOrganisation { get; set; } @@ -21,6 +24,7 @@ public sealed class InviteConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Invite).Pluralize()); builder.HasKey(pk => pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.OrganisationId).IsRequired(); builder.Property(f => f.InvitedOrganisationId).IsRequired(); builder.Property(f => f.AwardId).IsRequired(); @@ -31,6 +35,12 @@ public sealed class InviteConfiguration : IEntityTypeConfiguration builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); builder.Property(f => f.UpdatedAt).IsRequired(false); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Organisation) .WithMany() .HasForeignKey(fk => fk.OrganisationId) diff --git a/PostFundManagement.Domain/Entities/Issue.cs b/PostFundManagement.Domain/Entities/Issue.cs index b4e8642..7b97825 100644 --- a/PostFundManagement.Domain/Entities/Issue.cs +++ b/PostFundManagement.Domain/Entities/Issue.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Issue : Models.Issue +public class Issue : Models.Issue, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual User? Creator { get; set; } @@ -19,6 +21,7 @@ public sealed class IssueConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Issue).Pluralize()); builder.HasKey(pk => pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); @@ -32,6 +35,12 @@ public sealed class IssueConfiguration : IEntityTypeConfiguration .HasSentinel(ActivityStatus.Active); builder.Property(f => f.Resolution).IsRequired(); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/Milestone.cs b/PostFundManagement.Domain/Entities/Milestone.cs index 693f342..b3d2056 100644 --- a/PostFundManagement.Domain/Entities/Milestone.cs +++ b/PostFundManagement.Domain/Entities/Milestone.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Milestone : Models.Milestone +public class Milestone : Models.Milestone, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual User? Creator { get; set; } @@ -19,6 +21,7 @@ public sealed class MilestoneConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Milestone).Pluralize()); builder.HasKey(pk => pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.UpdatedBy).IsRequired(false); @@ -31,6 +34,12 @@ public sealed class MilestoneConfiguration : IEntityTypeConfiguration builder.Property(f => f.Priority).IsRequired().HasConversion().HasDefaultValueSql("1") .HasSentinel(Priority.Low); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/Notification.cs b/PostFundManagement.Domain/Entities/Notification.cs index d6cfc05..29df920 100644 --- a/PostFundManagement.Domain/Entities/Notification.cs +++ b/PostFundManagement.Domain/Entities/Notification.cs @@ -1,9 +1,9 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Notification : Models.Notification +public class Notification : Models.Notification, ITenantEntity { public virtual Tenant? Tenant { get; set; } diff --git a/PostFundManagement.Domain/Entities/Organisation.cs b/PostFundManagement.Domain/Entities/Organisation.cs index eb8a2ef..3da43f3 100644 --- a/PostFundManagement.Domain/Entities/Organisation.cs +++ b/PostFundManagement.Domain/Entities/Organisation.cs @@ -2,7 +2,6 @@ using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] public class Organisation : Models.Organisation { public virtual User? Creator { get; set; } diff --git a/PostFundManagement.Domain/Entities/Outcome.cs b/PostFundManagement.Domain/Entities/Outcome.cs index dc6f43b..7b0697c 100644 --- a/PostFundManagement.Domain/Entities/Outcome.cs +++ b/PostFundManagement.Domain/Entities/Outcome.cs @@ -2,7 +2,6 @@ using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] public class Outcome : Models.Outcome { public virtual Beneficiary? Beneficiary { get; set; } diff --git a/PostFundManagement.Domain/Entities/Portfolio.cs b/PostFundManagement.Domain/Entities/Portfolio.cs index 00f9215..02b5c93 100644 --- a/PostFundManagement.Domain/Entities/Portfolio.cs +++ b/PostFundManagement.Domain/Entities/Portfolio.cs @@ -1,9 +1,9 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Portfolio : Models.Portfolio +public class Portfolio : Models.Portfolio, ITenantEntity { public virtual User? Creator { get; set; } @@ -32,7 +32,7 @@ public sealed class PortfolioConfiguration : IEntityTypeConfiguration builder.Property(f => f.Description).IsRequired(false).HasMaxLength(TextLength); builder.HasOne(f => f.Tenant) - .WithMany(f => f.Portfolios) + .WithMany() .HasForeignKey(fk => fk.TenantId) .IsRequired() .OnDelete(DeleteBehavior.Restrict); diff --git a/PostFundManagement.Domain/Entities/Programme.cs b/PostFundManagement.Domain/Entities/Programme.cs index fde66d7..7a0ef6b 100644 --- a/PostFundManagement.Domain/Entities/Programme.cs +++ b/PostFundManagement.Domain/Entities/Programme.cs @@ -1,9 +1,9 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Programme : Models.Programme +public class Programme : Models.Programme, ITenantEntity { public virtual User? Creator { get; set; } @@ -41,7 +41,7 @@ public sealed class ProgrammeConfiguration : IEntityTypeConfiguration .HasSentinel(ApprovalStatus.Pending); builder.HasOne(f => f.Tenant) - .WithMany(f => f.Programmes) + .WithMany() .HasForeignKey(fk => fk.TenantId) .IsRequired() .OnDelete(DeleteBehavior.NoAction); diff --git a/PostFundManagement.Domain/Entities/Project.cs b/PostFundManagement.Domain/Entities/Project.cs index d3bde29..60a9ff4 100644 --- a/PostFundManagement.Domain/Entities/Project.cs +++ b/PostFundManagement.Domain/Entities/Project.cs @@ -1,9 +1,9 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Project : Models.Project +public class Project : Models.Project, ITenantEntity { public virtual User? Creator { get; set; } @@ -41,7 +41,7 @@ public sealed class ProjectConfiguration : IEntityTypeConfiguration .HasSentinel(ApprovalStatus.Pending); builder.HasOne(f => f.Tenant) - .WithMany(f => f.Projects) + .WithMany() .HasForeignKey(fk => fk.TenantId) .IsRequired() .OnDelete(DeleteBehavior.Restrict); diff --git a/PostFundManagement.Domain/Entities/Risk.cs b/PostFundManagement.Domain/Entities/Risk.cs index 9686fa9..1be7a3f 100644 --- a/PostFundManagement.Domain/Entities/Risk.cs +++ b/PostFundManagement.Domain/Entities/Risk.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Risk : Models.Risk +public class Risk : Models.Risk, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual Project? Project { get; set; } public virtual User? Creator { get; set; } @@ -17,6 +19,7 @@ public sealed class RiskConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Risk).Pluralize()); builder.HasKey(pk => pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); @@ -27,6 +30,12 @@ public sealed class RiskConfiguration : IEntityTypeConfiguration builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength); builder.Property(f => f.Description).IsRequired().HasMaxLength(TextLength); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/Rule.cs b/PostFundManagement.Domain/Entities/Rule.cs index cac2969..bfe9435 100644 --- a/PostFundManagement.Domain/Entities/Rule.cs +++ b/PostFundManagement.Domain/Entities/Rule.cs @@ -1,10 +1,12 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class Rule : Models.Rule +public class Rule : Models.Rule, ITenantEntity { + public virtual Tenant? Tenant { get; set; } + public virtual User? Creator { get; set; } public virtual User? Updator { get; set; } @@ -19,6 +21,7 @@ public sealed class RuleConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(Rule).Pluralize()); builder.HasKey(fk => fk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProgrammeId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.UpdatedBy).IsRequired(false); @@ -29,6 +32,12 @@ public sealed class RuleConfiguration : IEntityTypeConfiguration builder.Property(f => f.Status).IsRequired().HasConversion().HasDefaultValueSql("2") .HasSentinel(ActivityStatus.Inactive); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Programme) .WithMany(f => f.Rules) .HasForeignKey(fk => fk.ProgrammeId) diff --git a/PostFundManagement.Domain/Entities/SiteVisit.cs b/PostFundManagement.Domain/Entities/SiteVisit.cs index 9d46ce9..ec5782b 100644 --- a/PostFundManagement.Domain/Entities/SiteVisit.cs +++ b/PostFundManagement.Domain/Entities/SiteVisit.cs @@ -1,11 +1,13 @@ +using PostFundManagement.Domain.Abstractions; using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] -public class SiteVisit : Models.SiteVisit +public class SiteVisit : Models.SiteVisit, ITenantEntity { - public virtual Project? Project { get; set; } + public virtual Tenant? Tenant { get; set; } + + public virtual Project? Project { get; set; } public virtual User? Creator { get; set; } } @@ -17,6 +19,7 @@ public sealed class SiteVisitConfiguration : IEntityTypeConfiguration builder.ToTable(nameof(SiteVisit).Pluralize()); builder.HasKey(pk => pk.Id); + builder.Property(f => f.TenantId).IsRequired(); builder.Property(f => f.ProjectId).IsRequired(); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); @@ -26,6 +29,12 @@ public sealed class SiteVisitConfiguration : IEntityTypeConfiguration builder.Property(f => f.Status).IsRequired().HasConversion().HasDefaultValueSql("1") .HasSentinel(ApprovalStatus.Pending); + builder.HasOne(f => f.Tenant) + .WithMany() + .HasForeignKey(fk => fk.TenantId) + .IsRequired() + .OnDelete(DeleteBehavior.NoAction); + builder.HasOne(f => f.Project) .WithMany() .HasForeignKey(fk => fk.ProjectId) diff --git a/PostFundManagement.Domain/Entities/Tenant.cs b/PostFundManagement.Domain/Entities/Tenant.cs index a318768..cd38fc8 100644 --- a/PostFundManagement.Domain/Entities/Tenant.cs +++ b/PostFundManagement.Domain/Entities/Tenant.cs @@ -2,20 +2,11 @@ namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] public class Tenant : Models.Tenant { public virtual User? Creator { get; set; } public virtual User? Updator { get; set; } - - public ICollection Awards { get; set; } = []; - - public ICollection Projects { get; set; } = []; - - public ICollection Programmes { get; set; } = []; - - public ICollection Portfolios { get; set; } = []; } public sealed class TenantConfiguration : IEntityTypeConfiguration diff --git a/PostFundManagement.Domain/Entities/TenantOrganisation.cs b/PostFundManagement.Domain/Entities/TenantOrganisation.cs index bf3cc15..28c3a75 100644 --- a/PostFundManagement.Domain/Entities/TenantOrganisation.cs +++ b/PostFundManagement.Domain/Entities/TenantOrganisation.cs @@ -1,6 +1,5 @@ namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] public class TenantOrganisation : Models.TenantOrganisation { public virtual Tenant? Tenant { get; set; } @@ -17,6 +16,8 @@ public sealed class TenantOrganisationConfiguration : IEntityTypeConfiguration pk.Id); + builder.HasIndex(to => new { to.TenantId, to.OrganisationId }).IsUnique(); + builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.TenantId).IsRequired(); diff --git a/PostFundManagement.Domain/Entities/TenantUser.cs b/PostFundManagement.Domain/Entities/TenantUser.cs index 0d9f570..fc66292 100644 --- a/PostFundManagement.Domain/Entities/TenantUser.cs +++ b/PostFundManagement.Domain/Entities/TenantUser.cs @@ -1,12 +1,13 @@ namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] public class TenantUser : Models.TenantUser { public virtual Tenant? Tenant { get; set; } + [ForeignKey(nameof(CreatedBy))] public virtual User? Creator { get; set; } + [ForeignKey(nameof(UserId))] public virtual User? User { get; set; } } @@ -17,6 +18,8 @@ public sealed class TenantUserConfiguration : IEntityTypeConfiguration pk.Id); + builder.HasIndex(tu => new { tu.TenantId, tu.UserId }).IsUnique(); + builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()"); builder.Property(f => f.CreatedBy).IsRequired(); builder.Property(f => f.UserId).IsRequired(); diff --git a/PostFundManagement.Domain/Entities/User.cs b/PostFundManagement.Domain/Entities/User.cs index da7a74e..eaaa510 100644 --- a/PostFundManagement.Domain/Entities/User.cs +++ b/PostFundManagement.Domain/Entities/User.cs @@ -2,7 +2,6 @@ using static PostFundManagement.Domain.Extensions.Constants; namespace PostFundManagement.Domain.Entities; -[EntityTypeConfiguration] public sealed class User : Models.User; public sealed class UserConfiguration : IEntityTypeConfiguration diff --git a/PostFundManagement.Domain/Models/Activity.cs b/PostFundManagement.Domain/Models/Activity.cs index 8235199..feeaf6b 100644 --- a/PostFundManagement.Domain/Models/Activity.cs +++ b/PostFundManagement.Domain/Models/Activity.cs @@ -3,6 +3,8 @@ namespace PostFundManagement.Domain.Models; public class Activity { public long Id { get; set; } + + public long TenantId { get; set; } public long? ProjectId { get; set; } diff --git a/PostFundManagement.Domain/Models/AuditChanges.cs b/PostFundManagement.Domain/Models/AuditChanges.cs new file mode 100644 index 0000000..f6acc5f --- /dev/null +++ b/PostFundManagement.Domain/Models/AuditChanges.cs @@ -0,0 +1,6 @@ +namespace PostFundManagement.Domain.Models; + +public sealed class AuditChanges +{ + public string[]? Logs { get; set; } +} diff --git a/PostFundManagement.Domain/Models/AuditLog.cs b/PostFundManagement.Domain/Models/AuditLog.cs index 1bcd1a2..3bfbfbb 100644 --- a/PostFundManagement.Domain/Models/AuditLog.cs +++ b/PostFundManagement.Domain/Models/AuditLog.cs @@ -12,7 +12,8 @@ public class AuditLog public string? Action { get; set; } - public string[]? Changes { get; set; } + [NotMapped] + public AuditChanges? Changes { get; set; } public Guid PerformedBy { get; set; } diff --git a/PostFundManagement.Domain/Models/Beneficiary.cs b/PostFundManagement.Domain/Models/Beneficiary.cs index b7aefb7..faccad1 100644 --- a/PostFundManagement.Domain/Models/Beneficiary.cs +++ b/PostFundManagement.Domain/Models/Beneficiary.cs @@ -4,6 +4,8 @@ public class Beneficiary { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public Guid UserId { get; set; } diff --git a/PostFundManagement.Domain/Models/Budget.cs b/PostFundManagement.Domain/Models/Budget.cs index c4b6346..5b606b1 100644 --- a/PostFundManagement.Domain/Models/Budget.cs +++ b/PostFundManagement.Domain/Models/Budget.cs @@ -4,6 +4,8 @@ public class Budget { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public Guid CreatedBy { get; set; } diff --git a/PostFundManagement.Domain/Models/ChangeRequest.cs b/PostFundManagement.Domain/Models/ChangeRequest.cs index 65f6358..529d666 100644 --- a/PostFundManagement.Domain/Models/ChangeRequest.cs +++ b/PostFundManagement.Domain/Models/ChangeRequest.cs @@ -4,6 +4,8 @@ public class ChangeRequest { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public string? Title { get; set; } diff --git a/PostFundManagement.Domain/Models/ComplianceItem.cs b/PostFundManagement.Domain/Models/ComplianceItem.cs index f16036b..d8a1bb7 100644 --- a/PostFundManagement.Domain/Models/ComplianceItem.cs +++ b/PostFundManagement.Domain/Models/ComplianceItem.cs @@ -4,6 +4,8 @@ public class ComplianceItem { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public string? Title { get; set; } diff --git a/PostFundManagement.Domain/Models/Contract.cs b/PostFundManagement.Domain/Models/Contract.cs index 2e0b197..6d3782b 100644 --- a/PostFundManagement.Domain/Models/Contract.cs +++ b/PostFundManagement.Domain/Models/Contract.cs @@ -4,6 +4,8 @@ public class Contract { public long Id { get; set; } + public long TenantId { get; set; } + public long AwardId { get; set; } public string? ExternalSignatureId { get; set; } diff --git a/PostFundManagement.Domain/Models/Disbursement.cs b/PostFundManagement.Domain/Models/Disbursement.cs index e06e7e1..4d3919f 100644 --- a/PostFundManagement.Domain/Models/Disbursement.cs +++ b/PostFundManagement.Domain/Models/Disbursement.cs @@ -4,6 +4,8 @@ public class Disbursement { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public long? MilestoneId { get; set; } diff --git a/PostFundManagement.Domain/Models/Evidence.cs b/PostFundManagement.Domain/Models/Evidence.cs index ac4bd82..2a1917e 100644 --- a/PostFundManagement.Domain/Models/Evidence.cs +++ b/PostFundManagement.Domain/Models/Evidence.cs @@ -4,6 +4,8 @@ public class Evidence { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public long MilestoneId { get; set; } diff --git a/PostFundManagement.Domain/Models/Indicator.cs b/PostFundManagement.Domain/Models/Indicator.cs index 1787d4f..9dbccde 100644 --- a/PostFundManagement.Domain/Models/Indicator.cs +++ b/PostFundManagement.Domain/Models/Indicator.cs @@ -4,6 +4,8 @@ public class Indicator { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public Guid CreatedBy { get; set; } diff --git a/PostFundManagement.Domain/Models/Instrument.cs b/PostFundManagement.Domain/Models/Instrument.cs index 3cd09ab..8876ec4 100644 --- a/PostFundManagement.Domain/Models/Instrument.cs +++ b/PostFundManagement.Domain/Models/Instrument.cs @@ -4,6 +4,8 @@ public class Instrument { public long Id { get; set; } + public long TenantId { get; set; } + public long ProgrammeId { get; set; } public string? Code { get; set; } diff --git a/PostFundManagement.Domain/Models/Invite.cs b/PostFundManagement.Domain/Models/Invite.cs index f78ac27..615d5b9 100644 --- a/PostFundManagement.Domain/Models/Invite.cs +++ b/PostFundManagement.Domain/Models/Invite.cs @@ -4,6 +4,8 @@ public class Invite { public long Id { get; set; } + public long TenantId { get; set; } + public long OrganisationId { get; set; } public long InvitedOrganisationId { get; set; } diff --git a/PostFundManagement.Domain/Models/Issue.cs b/PostFundManagement.Domain/Models/Issue.cs index 4bdbf45..da37660 100644 --- a/PostFundManagement.Domain/Models/Issue.cs +++ b/PostFundManagement.Domain/Models/Issue.cs @@ -4,6 +4,8 @@ public class Issue { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public string? Title { get; set; } diff --git a/PostFundManagement.Domain/Models/Milestone.cs b/PostFundManagement.Domain/Models/Milestone.cs index c42d74e..d1dc1ed 100644 --- a/PostFundManagement.Domain/Models/Milestone.cs +++ b/PostFundManagement.Domain/Models/Milestone.cs @@ -4,6 +4,8 @@ public class Milestone { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public Guid CreatedBy { get; set; } diff --git a/PostFundManagement.Domain/Models/Risk.cs b/PostFundManagement.Domain/Models/Risk.cs index e22b458..857bef8 100644 --- a/PostFundManagement.Domain/Models/Risk.cs +++ b/PostFundManagement.Domain/Models/Risk.cs @@ -4,6 +4,8 @@ public class Risk { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public Guid CreatedBy { get; set; } diff --git a/PostFundManagement.Domain/Models/Rule.cs b/PostFundManagement.Domain/Models/Rule.cs index ba15a16..79de468 100644 --- a/PostFundManagement.Domain/Models/Rule.cs +++ b/PostFundManagement.Domain/Models/Rule.cs @@ -4,6 +4,8 @@ public class Rule { public long Id { get; set; } + public long TenantId { get; set; } + public long ProgrammeId { get; set; } public Guid CreatedBy { get; set; } diff --git a/PostFundManagement.Domain/Models/SiteVisit.cs b/PostFundManagement.Domain/Models/SiteVisit.cs index 9a94b7a..8a7b778 100644 --- a/PostFundManagement.Domain/Models/SiteVisit.cs +++ b/PostFundManagement.Domain/Models/SiteVisit.cs @@ -4,6 +4,8 @@ public class SiteVisit { public long Id { get; set; } + public long TenantId { get; set; } + public long ProjectId { get; set; } public DateTime VisitedAt { get; set; } diff --git a/PostFundManagement.Domain/PostFundManagement.Domain.csproj b/PostFundManagement.Domain/PostFundManagement.Domain.csproj index 52e4769..7222148 100644 --- a/PostFundManagement.Domain/PostFundManagement.Domain.csproj +++ b/PostFundManagement.Domain/PostFundManagement.Domain.csproj @@ -199,6 +199,7 @@ + diff --git a/PostFundManagement.Infrastructure/Database/ApplicationDbContext.cs b/PostFundManagement.Infrastructure/Database/ApplicationDbContext.cs index df81852..e7dbaf5 100644 --- a/PostFundManagement.Infrastructure/Database/ApplicationDbContext.cs +++ b/PostFundManagement.Infrastructure/Database/ApplicationDbContext.cs @@ -65,35 +65,60 @@ public sealed class ApplicationDbContext(DbContextOptions public DbSet Users => Set(); + private void ApplyGlobalTenantFilter(ModelBuilder modelBuilder) + where TEntity : class, ITenantEntity => + modelBuilder.Entity().HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); + protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); - modelBuilder.Entity() - .HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); - modelBuilder.Entity() - .HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); + foreach (var entityType in modelBuilder.Model.GetEntityTypes()) + { + if (typeof(ITenantEntity).IsAssignableFrom(entityType.ClrType)) + { + var method = typeof(ApplicationDbContext).GetMethod(nameof(ApplyGlobalTenantFilter), + BindingFlags.NonPublic | BindingFlags.Instance)?.MakeGenericMethod(entityType.ClrType); - modelBuilder.Entity() - .HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); - - modelBuilder.Entity() - .HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); - - modelBuilder.Entity() - .HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); - - modelBuilder.Entity() - .HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); - - modelBuilder.Entity() - .HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); - - modelBuilder.Entity() - .HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId); + method?.Invoke(this, [modelBuilder]); + } + } modelBuilder.Entity().HasQueryFilter(o => BypassFilter || Set().Any(to => to.TenantId == CurrentTenantId && to.OrganisationId == o.Id)); + + modelBuilder.Entity().HasQueryFilter(o => BypassFilter || + Set().Any(to => to.TenantId == CurrentTenantId && to.UserId == o.Id)); + } + + public override Task SaveChangesAsync(CancellationToken cancellationToken = default) + { + AlterQualifyingTenantEntity(); + + return base.SaveChangesAsync(cancellationToken); + } + + public override int SaveChanges() + { + AlterQualifyingTenantEntity(); + + return base.SaveChanges(); + } + + private void AlterQualifyingTenantEntity() + { + var entries = ChangeTracker.Entries() + .Where(e => e.State == EntityState.Added && e.Entity.TenantId == 0) + .ToList(); + + if (entries.Count == 0) return; + + if (CurrentTenantId <= 0 && !BypassFilter) + throw new InvalidOperationException("Cannot save multi-tenant entity: CurrentTenantId is not set in the active execution context."); + + foreach (var entry in entries) + entry.Entity.TenantId = CurrentTenantId; } } \ No newline at end of file diff --git a/PostFundManagement.Infrastructure/Database/Migrations/20260923052735_OptimisedMultitenancy.Designer.cs b/PostFundManagement.Infrastructure/Database/Migrations/20260923052735_OptimisedMultitenancy.Designer.cs new file mode 100644 index 0000000..027e7cb --- /dev/null +++ b/PostFundManagement.Infrastructure/Database/Migrations/20260923052735_OptimisedMultitenancy.Designer.cs @@ -0,0 +1,2272 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PostFundManagement.Infrastructure.Database; + +#nullable disable + +namespace PostFundManagement.Infrastructure.Database.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260923052735_OptimisedMultitenancy")] + partial class OptimisedMultitenancy + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.12") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Activity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("ApprovedBy") + .HasColumnType("uuid"); + + b.Property("ApproverId") + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("MilestoneId") + .HasColumnType("bigint"); + + b.Property("PerformedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("Title") + .HasColumnType("text"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ApproverId"); + + b.HasIndex("CreatorId"); + + b.HasIndex("MilestoneId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); + + b.ToTable("Activities"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Action") + .HasColumnType("text"); + + b.Property("EntityId") + .HasColumnType("text"); + + b.Property("EntityName") + .HasColumnType("text"); + + b.Property("PerformedBy") + .HasColumnType("uuid"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.ToTable("AuditLogs"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Award", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("ApprovedBy") + .HasColumnType("uuid"); + + b.Property("ApproverId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("OrganisationId") + .HasColumnType("bigint"); + + b.Property("ProgrammeId") + .HasColumnType("bigint"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ApproverId"); + + b.HasIndex("CreatorId"); + + b.HasIndex("OrganisationId"); + + b.HasIndex("ProgrammeId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); + + b.ToTable("Awards"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Beneficiary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("Location") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("ReachedCount") + .HasColumnType("integer"); + + b.Property("TargetCount") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.HasIndex("UserId"); + + b.ToTable("Beneficiaries"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Budget", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("ApprovedBy") + .HasColumnType("uuid"); + + b.Property("ApproverId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ApproverId"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.ToTable("Budgets"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.ChangeRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApprovedBy") + .HasColumnType("uuid"); + + b.Property("ApproverId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Justification") + .HasColumnType("text"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("RevisedBudget") + .HasColumnType("numeric"); + + b.Property("RevisedEndedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("Title") + .HasColumnType("text"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ApproverId"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.ToTable("ChangeRequests"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.ComplianceItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("Requirements") + .HasColumnType("text"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("Title") + .HasColumnType("text"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("VerifiedBy") + .HasColumnType("uuid"); + + b.Property("VerifierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.HasIndex("VerifierId"); + + b.ToTable("ComplianceItems"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Contract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AwardId") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("EffectiveAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ExternalSignatureId") + .HasColumnType("text"); + + b.Property("SignedDocumentUrl") + .HasColumnType("text"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("TotalValue") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.HasIndex("AwardId") + .IsUnique(); + + b.HasIndex("CreatorId"); + + b.HasIndex("TenantId"); + + b.ToTable("Contracts"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Disbursement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("MilestoneId") + .HasColumnType("bigint"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("MilestoneId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); + + b.ToTable("Disbursements"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Evidence", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActivityId") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("DocumentUrl") + .HasColumnType("text"); + + b.Property("IndicatorId") + .HasColumnType("bigint"); + + b.Property("MilestoneId") + .HasColumnType("bigint"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") + .HasColumnType("uuid"); + + b.Property("Version") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ActivityId"); + + b.HasIndex("CreatorId"); + + b.HasIndex("IndicatorId"); + + b.HasIndex("MilestoneId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); + + b.ToTable("Evidences"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Indicator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActualAmount") + .HasColumnType("numeric"); + + b.Property("BaselineAmount") + .HasColumnType("numeric"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("TargetAmount") + .HasColumnType("numeric"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UnitOfMeasure") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.ToTable("Indicators"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Instrument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ProgrammeId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProgrammeId"); + + b.HasIndex("TenantId"); + + b.ToTable("Instruments"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AwardId") + .HasColumnType("bigint"); + + b.Property("ContractId") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("InvitedOrganisationId") + .HasColumnType("bigint"); + + b.Property("OrganisationId") + .HasColumnType("bigint"); + + b.Property("Recipient") + .HasColumnType("uuid"); + + b.Property("RecipientUserId") + .HasColumnType("uuid"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("AwardId"); + + b.HasIndex("ContractId"); + + b.HasIndex("InvitedOrganisationId"); + + b.HasIndex("OrganisationId"); + + b.HasIndex("RecipientUserId"); + + b.HasIndex("TenantId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Issue", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AssignedTo") + .HasColumnType("uuid"); + + b.Property("AssigneeId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Priority") + .HasColumnType("integer"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("Resolution") + .HasColumnType("text"); + + b.Property("ResolvedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("Title") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("AssigneeId"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.ToTable("Issues"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Milestone", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("DueAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Priority") + .HasColumnType("integer"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); + + b.ToTable("Milestones"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Destination") + .HasColumnType("text"); + + b.Property("Error") + .HasColumnType("text"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("OrganisationId") + .HasColumnType("bigint"); + + b.Property("Platform") + .HasColumnType("integer"); + + b.Property("Recipient") + .HasColumnType("uuid"); + + b.Property("RecipientUserId") + .HasColumnType("uuid"); + + b.Property("SentAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Subject") + .HasColumnType("text"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("OrganisationId"); + + b.HasIndex("RecipientUserId"); + + b.HasIndex("TenantId"); + + b.ToTable("Notifications"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Organisation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("RegistrationNo") + .HasColumnType("text"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("Organisations"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Outcome", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BeneficiaryId") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("BeneficiaryId"); + + b.HasIndex("CreatorId"); + + b.ToTable("Outcomes"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Portfolio", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("OrganisationId") + .HasColumnType("bigint"); + + b.Property("OwnedBy") + .HasColumnType("uuid"); + + b.Property("OwnerId") + .HasColumnType("uuid"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("OrganisationId"); + + b.HasIndex("OwnerId"); + + b.HasIndex("TenantId"); + + b.ToTable("Portfolios"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Programme", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("OwnedBy") + .HasColumnType("uuid"); + + b.Property("OwnerId") + .HasColumnType("uuid"); + + b.Property("PortfolioId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("OwnerId"); + + b.HasIndex("PortfolioId"); + + b.HasIndex("TenantId"); + + b.ToTable("Programmes"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("EndedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ProgrammeId") + .HasColumnType("bigint"); + + b.Property("ProjectType") + .HasColumnType("integer"); + + b.Property("Sector") + .HasColumnType("integer"); + + b.Property("StartedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProgrammeId"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Risk", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Impact") + .HasColumnType("integer"); + + b.Property("Likelihood") + .HasColumnType("integer"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.ToTable("Risks"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Rule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ProgrammeId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") + .HasColumnType("uuid"); + + b.Property("Version") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProgrammeId"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); + + b.ToTable("Rules"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.SiteVisit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Findings") + .HasColumnType("text"); + + b.Property("InspectorName") + .HasColumnType("text"); + + b.Property("ProjectId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("VisitedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("TenantId"); + + b.ToTable("SiteVisits"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Tenant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("UpdatorId"); + + b.ToTable("Tenants"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.TenantOrganisation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("OrganisationId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("OrganisationId"); + + b.HasIndex("TenantId"); + + b.ToTable("TenantOrganisations"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.TenantUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("TenantId"); + + b.HasIndex("UserId"); + + b.ToTable("TenantUsers"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("LastLoginAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Activity", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Approver") + .WithMany() + .HasForeignKey("ApproverId"); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Milestone", "Milestone") + .WithMany() + .HasForeignKey("MilestoneId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") + .WithMany() + .HasForeignKey("UpdatorId"); + + b.Navigation("Approver"); + + b.Navigation("Creator"); + + b.Navigation("Milestone"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + + b.Navigation("Updator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Award", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Approver") + .WithMany() + .HasForeignKey("ApproverId"); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") + .WithMany() + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Programme", "Programme") + .WithMany("Awards") + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany("Awards") + .HasForeignKey("ProjectId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") + .WithMany() + .HasForeignKey("UpdatorId"); + + b.Navigation("Approver"); + + b.Navigation("Creator"); + + b.Navigation("Organisation"); + + b.Navigation("Programme"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + + b.Navigation("Updator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Beneficiary", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatedBy") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Budget", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Approver") + .WithMany() + .HasForeignKey("ApproverId"); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Approver"); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.ChangeRequest", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Approver") + .WithMany() + .HasForeignKey("ApproverId"); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Approver"); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.ComplianceItem", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Verifier") + .WithMany() + .HasForeignKey("VerifierId"); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + + b.Navigation("Verifier"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Contract", b => + { + b.HasOne("PostFundManagement.Domain.Entities.Award", "Award") + .WithOne("Contract") + .HasForeignKey("PostFundManagement.Domain.Entities.Contract", "AwardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Award"); + + b.Navigation("Creator"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Disbursement", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Milestone", "Milestone") + .WithMany() + .HasForeignKey("MilestoneId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") + .WithMany() + .HasForeignKey("UpdatorId"); + + b.Navigation("Creator"); + + b.Navigation("Milestone"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + + b.Navigation("Updator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Evidence", b => + { + b.HasOne("PostFundManagement.Domain.Entities.Activity", "Activity") + .WithMany("Evidences") + .HasForeignKey("ActivityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Indicator", "Indicator") + .WithMany() + .HasForeignKey("IndicatorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Milestone", "Milestone") + .WithMany() + .HasForeignKey("MilestoneId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") + .WithMany() + .HasForeignKey("UpdatorId"); + + b.Navigation("Activity"); + + b.Navigation("Creator"); + + b.Navigation("Indicator"); + + b.Navigation("Milestone"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + + b.Navigation("Updator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Indicator", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Instrument", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Programme", "Programme") + .WithMany("Instruments") + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Programme"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Invite", b => + { + b.HasOne("PostFundManagement.Domain.Entities.Award", "Award") + .WithMany() + .HasForeignKey("AwardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Contract", "Contract") + .WithMany() + .HasForeignKey("ContractId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Organisation", "InvitedOrganisation") + .WithMany() + .HasForeignKey("InvitedOrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") + .WithMany() + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "RecipientUser") + .WithMany() + .HasForeignKey("RecipientUserId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Award"); + + b.Navigation("Contract"); + + b.Navigation("InvitedOrganisation"); + + b.Navigation("Organisation"); + + b.Navigation("RecipientUser"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Issue", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Assignee") + .WithMany() + .HasForeignKey("AssigneeId"); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assignee"); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Milestone", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") + .WithMany() + .HasForeignKey("UpdatorId"); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + + b.Navigation("Updator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Notification", b => + { + b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") + .WithMany() + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "RecipientUser") + .WithMany() + .HasForeignKey("RecipientUserId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Organisation"); + + b.Navigation("RecipientUser"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Organisation", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Outcome", b => + { + b.HasOne("PostFundManagement.Domain.Entities.Beneficiary", "Beneficiary") + .WithMany() + .HasForeignKey("BeneficiaryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.Navigation("Beneficiary"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Portfolio", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") + .WithMany() + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Organisation"); + + b.Navigation("Owner"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Programme", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId"); + + b.HasOne("PostFundManagement.Domain.Entities.Portfolio", "Portfolio") + .WithMany("Programmes") + .HasForeignKey("PortfolioId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Owner"); + + b.Navigation("Portfolio"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Project", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Programme", "Programme") + .WithMany("Projects") + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") + .WithMany() + .HasForeignKey("UpdatorId"); + + b.Navigation("Creator"); + + b.Navigation("Programme"); + + b.Navigation("Tenant"); + + b.Navigation("Updator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Risk", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Rule", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Programme", "Programme") + .WithMany("Rules") + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") + .WithMany() + .HasForeignKey("UpdatorId"); + + b.Navigation("Creator"); + + b.Navigation("Programme"); + + b.Navigation("Tenant"); + + b.Navigation("Updator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.SiteVisit", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Project"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Tenant", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") + .WithMany() + .HasForeignKey("UpdatorId"); + + b.Navigation("Creator"); + + b.Navigation("Updator"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.TenantOrganisation", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") + .WithMany() + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Organisation"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.TenantUser", b => + { + b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") + .WithMany() + .HasForeignKey("CreatedBy") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Tenant"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Activity", b => + { + b.Navigation("Evidences"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Award", b => + { + b.Navigation("Contract"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Portfolio", b => + { + b.Navigation("Programmes"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Programme", b => + { + b.Navigation("Awards"); + + b.Navigation("Instruments"); + + b.Navigation("Projects"); + + b.Navigation("Rules"); + }); + + modelBuilder.Entity("PostFundManagement.Domain.Entities.Project", b => + { + b.Navigation("Awards"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PostFundManagement.Infrastructure/Database/Migrations/20260923052735_OptimisedMultitenancy.cs b/PostFundManagement.Infrastructure/Database/Migrations/20260923052735_OptimisedMultitenancy.cs new file mode 100644 index 0000000..869bbed --- /dev/null +++ b/PostFundManagement.Infrastructure/Database/Migrations/20260923052735_OptimisedMultitenancy.cs @@ -0,0 +1,5767 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PostFundManagement.Infrastructure.Database.Migrations +{ + /// + public partial class OptimisedMultitenancy : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Activities_Milestones_MilestoneId", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Projects_ProjectId", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Users_ApprovedBy", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Users_CreatedBy", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Users_UpdatedBy", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Organisations_OrganisationId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Programmes_ProgrammeId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Projects_ProjectId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Tenants_TenantId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Users_ApprovedBy", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Users_CreatedBy", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Users_UpdatedBy", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Beneficiaries_Projects_ProjectId", + table: "Beneficiaries"); + + migrationBuilder.DropForeignKey( + name: "FK_Beneficiaries_Users_CreatedBy", + table: "Beneficiaries"); + + migrationBuilder.DropForeignKey( + name: "FK_Beneficiaries_Users_UserId", + table: "Beneficiaries"); + + migrationBuilder.DropForeignKey( + name: "FK_Budgets_Projects_ProjectId", + table: "Budgets"); + + migrationBuilder.DropForeignKey( + name: "FK_Budgets_Users_ApprovedBy", + table: "Budgets"); + + migrationBuilder.DropForeignKey( + name: "FK_Budgets_Users_CreatedBy", + table: "Budgets"); + + migrationBuilder.DropForeignKey( + name: "FK_ChangeRequests_Projects_ProjectId", + table: "ChangeRequests"); + + migrationBuilder.DropForeignKey( + name: "FK_ChangeRequests_Users_ApprovedBy", + table: "ChangeRequests"); + + migrationBuilder.DropForeignKey( + name: "FK_ChangeRequests_Users_CreatedBy", + table: "ChangeRequests"); + + migrationBuilder.DropForeignKey( + name: "FK_ComplianceItems_Projects_ProjectId", + table: "ComplianceItems"); + + migrationBuilder.DropForeignKey( + name: "FK_ComplianceItems_Users_CreatedBy", + table: "ComplianceItems"); + + migrationBuilder.DropForeignKey( + name: "FK_ComplianceItems_Users_VerifiedBy", + table: "ComplianceItems"); + + migrationBuilder.DropForeignKey( + name: "FK_Contracts_Awards_AwardId", + table: "Contracts"); + + migrationBuilder.DropForeignKey( + name: "FK_Contracts_Users_CreatedBy", + table: "Contracts"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Milestones_MilestoneId", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Projects_ProjectId", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Users_CreatedBy", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Users_UpdatedBy", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Activities_ActivityId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Indicators_IndicatorId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Milestones_MilestoneId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Projects_ProjectId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Users_CreatedBy", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Users_UpdatedBy", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Indicators_Projects_ProjectId", + table: "Indicators"); + + migrationBuilder.DropForeignKey( + name: "FK_Indicators_Users_CreatedBy", + table: "Indicators"); + + migrationBuilder.DropForeignKey( + name: "FK_Instruments_Programmes_ProgrammeId", + table: "Instruments"); + + migrationBuilder.DropForeignKey( + name: "FK_Instruments_Users_CreatedBy", + table: "Instruments"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Awards_AwardId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Contracts_ContractId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Organisations_InvitedOrganisationId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Organisations_OrganisationId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Users_Recipient", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Issues_Projects_ProjectId", + table: "Issues"); + + migrationBuilder.DropForeignKey( + name: "FK_Issues_Users_AssignedTo", + table: "Issues"); + + migrationBuilder.DropForeignKey( + name: "FK_Issues_Users_CreatedBy", + table: "Issues"); + + migrationBuilder.DropForeignKey( + name: "FK_Milestones_Projects_ProjectId", + table: "Milestones"); + + migrationBuilder.DropForeignKey( + name: "FK_Milestones_Users_CreatedBy", + table: "Milestones"); + + migrationBuilder.DropForeignKey( + name: "FK_Milestones_Users_UpdatedBy", + table: "Milestones"); + + migrationBuilder.DropForeignKey( + name: "FK_Notifications_Organisations_OrganisationId", + table: "Notifications"); + + migrationBuilder.DropForeignKey( + name: "FK_Notifications_Tenants_TenantId", + table: "Notifications"); + + migrationBuilder.DropForeignKey( + name: "FK_Notifications_Users_Recipient", + table: "Notifications"); + + migrationBuilder.DropForeignKey( + name: "FK_Organisations_Users_CreatedBy", + table: "Organisations"); + + migrationBuilder.DropForeignKey( + name: "FK_Outcomes_Beneficiaries_BeneficiaryId", + table: "Outcomes"); + + migrationBuilder.DropForeignKey( + name: "FK_Outcomes_Users_CreatedBy", + table: "Outcomes"); + + migrationBuilder.DropForeignKey( + name: "FK_Portfolios_Organisations_OrganisationId", + table: "Portfolios"); + + migrationBuilder.DropForeignKey( + name: "FK_Portfolios_Tenants_TenantId", + table: "Portfolios"); + + migrationBuilder.DropForeignKey( + name: "FK_Portfolios_Users_CreatedBy", + table: "Portfolios"); + + migrationBuilder.DropForeignKey( + name: "FK_Portfolios_Users_OwnedBy", + table: "Portfolios"); + + migrationBuilder.DropForeignKey( + name: "FK_Programmes_Portfolios_PortfolioId", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_Programmes_Tenants_TenantId", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_Programmes_Users_CreatedBy", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_Programmes_Users_OwnedBy", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_Projects_Programmes_ProgrammeId", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_Projects_Tenants_TenantId", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_Projects_Users_CreatedBy", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_Projects_Users_UpdatedBy", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_Risks_Projects_ProjectId", + table: "Risks"); + + migrationBuilder.DropForeignKey( + name: "FK_Risks_Users_CreatedBy", + table: "Risks"); + + migrationBuilder.DropForeignKey( + name: "FK_Rules_Programmes_ProgrammeId", + table: "Rules"); + + migrationBuilder.DropForeignKey( + name: "FK_Rules_Users_CreatedBy", + table: "Rules"); + + migrationBuilder.DropForeignKey( + name: "FK_Rules_Users_UpdatedBy", + table: "Rules"); + + migrationBuilder.DropForeignKey( + name: "FK_SiteVisits_Projects_ProjectId", + table: "SiteVisits"); + + migrationBuilder.DropForeignKey( + name: "FK_SiteVisits_Users_CreatedBy", + table: "SiteVisits"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantOrganisations_Organisations_OrganisationId", + table: "TenantOrganisations"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantOrganisations_Tenants_TenantId", + table: "TenantOrganisations"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantOrganisations_Users_CreatedBy", + table: "TenantOrganisations"); + + migrationBuilder.DropForeignKey( + name: "FK_Tenants_Users_CreatedBy", + table: "Tenants"); + + migrationBuilder.DropForeignKey( + name: "FK_Tenants_Users_UpdatedBy", + table: "Tenants"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantUsers_Tenants_TenantId", + table: "TenantUsers"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantUsers_Users_CreatedBy", + table: "TenantUsers"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantUsers_Users_UserId", + table: "TenantUsers"); + + migrationBuilder.DropIndex( + name: "IX_Tenants_CreatedBy", + table: "Tenants"); + + migrationBuilder.DropIndex( + name: "IX_Tenants_UpdatedBy", + table: "Tenants"); + + migrationBuilder.DropIndex( + name: "IX_TenantOrganisations_CreatedBy", + table: "TenantOrganisations"); + + migrationBuilder.DropIndex( + name: "IX_SiteVisits_CreatedBy", + table: "SiteVisits"); + + migrationBuilder.DropIndex( + name: "IX_Rules_CreatedBy", + table: "Rules"); + + migrationBuilder.DropIndex( + name: "IX_Rules_UpdatedBy", + table: "Rules"); + + migrationBuilder.DropIndex( + name: "IX_Risks_CreatedBy", + table: "Risks"); + + migrationBuilder.DropIndex( + name: "IX_Projects_CreatedBy", + table: "Projects"); + + migrationBuilder.DropIndex( + name: "IX_Projects_UpdatedBy", + table: "Projects"); + + migrationBuilder.DropIndex( + name: "IX_Programmes_CreatedBy", + table: "Programmes"); + + migrationBuilder.DropIndex( + name: "IX_Programmes_OwnedBy", + table: "Programmes"); + + migrationBuilder.DropIndex( + name: "IX_Portfolios_CreatedBy", + table: "Portfolios"); + + migrationBuilder.DropIndex( + name: "IX_Portfolios_OwnedBy", + table: "Portfolios"); + + migrationBuilder.DropIndex( + name: "IX_Outcomes_CreatedBy", + table: "Outcomes"); + + migrationBuilder.DropIndex( + name: "IX_Organisations_CreatedBy", + table: "Organisations"); + + migrationBuilder.DropIndex( + name: "IX_Notifications_Recipient", + table: "Notifications"); + + migrationBuilder.DropIndex( + name: "IX_Milestones_CreatedBy", + table: "Milestones"); + + migrationBuilder.DropIndex( + name: "IX_Milestones_UpdatedBy", + table: "Milestones"); + + migrationBuilder.DropIndex( + name: "IX_Issues_AssignedTo", + table: "Issues"); + + migrationBuilder.DropIndex( + name: "IX_Issues_CreatedBy", + table: "Issues"); + + migrationBuilder.DropIndex( + name: "IX_Invites_Recipient", + table: "Invites"); + + migrationBuilder.DropIndex( + name: "IX_Instruments_CreatedBy", + table: "Instruments"); + + migrationBuilder.DropIndex( + name: "IX_Indicators_CreatedBy", + table: "Indicators"); + + migrationBuilder.DropIndex( + name: "IX_Evidences_CreatedBy", + table: "Evidences"); + + migrationBuilder.DropIndex( + name: "IX_Evidences_UpdatedBy", + table: "Evidences"); + + migrationBuilder.DropIndex( + name: "IX_Disbursements_CreatedBy", + table: "Disbursements"); + + migrationBuilder.DropIndex( + name: "IX_Disbursements_UpdatedBy", + table: "Disbursements"); + + migrationBuilder.DropIndex( + name: "IX_Contracts_CreatedBy", + table: "Contracts"); + + migrationBuilder.DropIndex( + name: "IX_ComplianceItems_CreatedBy", + table: "ComplianceItems"); + + migrationBuilder.DropIndex( + name: "IX_ComplianceItems_VerifiedBy", + table: "ComplianceItems"); + + migrationBuilder.DropIndex( + name: "IX_ChangeRequests_ApprovedBy", + table: "ChangeRequests"); + + migrationBuilder.DropIndex( + name: "IX_ChangeRequests_CreatedBy", + table: "ChangeRequests"); + + migrationBuilder.DropIndex( + name: "IX_Budgets_ApprovedBy", + table: "Budgets"); + + migrationBuilder.DropIndex( + name: "IX_Budgets_CreatedBy", + table: "Budgets"); + + migrationBuilder.DropIndex( + name: "IX_Awards_ApprovedBy", + table: "Awards"); + + migrationBuilder.DropIndex( + name: "IX_Awards_CreatedBy", + table: "Awards"); + + migrationBuilder.DropIndex( + name: "IX_Awards_UpdatedBy", + table: "Awards"); + + migrationBuilder.DropIndex( + name: "IX_Activities_ApprovedBy", + table: "Activities"); + + migrationBuilder.DropIndex( + name: "IX_Activities_CreatedBy", + table: "Activities"); + + migrationBuilder.DropIndex( + name: "IX_Activities_UpdatedBy", + table: "Activities"); + + migrationBuilder.DropColumn( + name: "Changes", + table: "AuditLogs"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Users", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "2"); + + migrationBuilder.AlterColumn( + name: "Email", + table: "Users", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Status", + table: "TenantUsers", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "TenantUsers", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Tenants", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Tenants", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Tenants", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Tenants", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "UpdatorId", + table: "Tenants", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "TenantOrganisations", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "TenantOrganisations", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "TenantOrganisations", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "SiteVisits", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "InspectorName", + table: "SiteVisits", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Findings", + table: "SiteVisits", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(4096)", + oldMaxLength: 4096, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "SiteVisits", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "SiteVisits", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "SiteVisits", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "Version", + table: "Rules", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValue: 1); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Rules", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "2"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Rules", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Rules", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Rules", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Rules", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AddColumn( + name: "UpdatorId", + table: "Rules", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Risks", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Likelihood", + table: "Risks", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "3"); + + migrationBuilder.AlterColumn( + name: "Impact", + table: "Risks", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Risks", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Risks", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Risks", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Risks", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Projects", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Sector", + table: "Projects", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "11"); + + migrationBuilder.AlterColumn( + name: "ProjectType", + table: "Projects", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "10"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Projects", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Projects", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Projects", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Projects", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "UpdatorId", + table: "Projects", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Programmes", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Programmes", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Programmes", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Programmes", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "OwnerId", + table: "Programmes", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Portfolios", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Portfolios", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Portfolios", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Portfolios", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "OwnerId", + table: "Portfolios", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Outcomes", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Outcomes", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Outcomes", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Outcomes", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Organisations", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "5"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Organisations", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "RegistrationNo", + table: "Organisations", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Organisations", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Email", + table: "Organisations", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Organisations", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Organisations", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Subject", + table: "Notifications", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Notifications", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Platform", + table: "Notifications", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Message", + table: "Notifications", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(4096)", + oldMaxLength: 4096); + + migrationBuilder.AlterColumn( + name: "Destination", + table: "Notifications", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Notifications", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "RecipientUserId", + table: "Notifications", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Milestones", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Priority", + table: "Milestones", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Milestones", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Milestones", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Milestones", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Milestones", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AddColumn( + name: "UpdatorId", + table: "Milestones", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Title", + table: "Issues", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Issues", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Resolution", + table: "Issues", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Priority", + table: "Issues", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Issues", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Issues", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "AssigneeId", + table: "Issues", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Issues", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Issues", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Invites", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "RecipientUserId", + table: "Invites", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Invites", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Instruments", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "2"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Instruments", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Instruments", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Instruments", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "Code", + table: "Instruments", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Instruments", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Instruments", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "UnitOfMeasure", + table: "Indicators", + type: "integer", + nullable: true, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "2"); + + migrationBuilder.AlterColumn( + name: "TargetAmount", + table: "Indicators", + type: "numeric", + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Indicators", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Indicators", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "BaselineAmount", + table: "Indicators", + type: "numeric", + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2); + + migrationBuilder.AlterColumn( + name: "ActualAmount", + table: "Indicators", + type: "numeric", + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Indicators", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Indicators", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "Version", + table: "Evidences", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValue: 1); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Evidences", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Evidences", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "9"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Evidences", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "DocumentUrl", + table: "Evidences", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Evidences", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Evidences", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Evidences", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AddColumn( + name: "UpdatorId", + table: "Evidences", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Disbursements", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Disbursements", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "Amount", + table: "Disbursements", + type: "numeric", + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Disbursements", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Disbursements", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AddColumn( + name: "UpdatorId", + table: "Disbursements", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "TotalValue", + table: "Contracts", + type: "numeric", + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Contracts", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Contracts", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Contracts", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Contracts", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "Title", + table: "ComplianceItems", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Status", + table: "ComplianceItems", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "Requirements", + table: "ComplianceItems", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(2048)", + oldMaxLength: 2048); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "ComplianceItems", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "ComplianceItems", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "ComplianceItems", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AddColumn( + name: "VerifierId", + table: "ComplianceItems", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Title", + table: "ChangeRequests", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Status", + table: "ChangeRequests", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "RevisedBudget", + table: "ChangeRequests", + type: "numeric", + nullable: true, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Justification", + table: "ChangeRequests", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "ChangeRequests", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "ApproverId", + table: "ChangeRequests", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "ChangeRequests", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "ChangeRequests", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Budgets", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Budgets", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "Amount", + table: "Budgets", + type: "numeric", + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2); + + migrationBuilder.AddColumn( + name: "ApproverId", + table: "Budgets", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Budgets", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Budgets", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Beneficiaries", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Location", + table: "Beneficiaries", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Beneficiaries", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "Category", + table: "Beneficiaries", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Beneficiaries", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Awards", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Awards", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "Amount", + table: "Awards", + type: "numeric", + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2); + + migrationBuilder.AddColumn( + name: "ApproverId", + table: "Awards", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Awards", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "UpdatorId", + table: "Awards", + type: "uuid", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Timestamp", + table: "AuditLogs", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "EntityName", + table: "AuditLogs", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "EntityId", + table: "AuditLogs", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Action", + table: "AuditLogs", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100); + + migrationBuilder.AlterColumn( + name: "Title", + table: "Activities", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Activities", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "integer", + oldDefaultValueSql: "1"); + + migrationBuilder.AlterColumn( + name: "ProjectId", + table: "Activities", + type: "bigint", + nullable: true, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "MilestoneId", + table: "Activities", + type: "bigint", + nullable: true, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Activities", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Activities", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + + migrationBuilder.AlterColumn( + name: "Category", + table: "Activities", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256); + + migrationBuilder.AlterColumn( + name: "Amount", + table: "Activities", + type: "numeric", + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric(18,2)", + oldPrecision: 18, + oldScale: 2); + + migrationBuilder.AddColumn( + name: "ApproverId", + table: "Activities", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "CreatorId", + table: "Activities", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "TenantId", + table: "Activities", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AddColumn( + name: "UpdatorId", + table: "Activities", + type: "uuid", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Tenants_CreatorId", + table: "Tenants", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Tenants_UpdatorId", + table: "Tenants", + column: "UpdatorId"); + + migrationBuilder.CreateIndex( + name: "IX_TenantOrganisations_CreatorId", + table: "TenantOrganisations", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_SiteVisits_CreatorId", + table: "SiteVisits", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_SiteVisits_TenantId", + table: "SiteVisits", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Rules_CreatorId", + table: "Rules", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Rules_TenantId", + table: "Rules", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Rules_UpdatorId", + table: "Rules", + column: "UpdatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Risks_CreatorId", + table: "Risks", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Risks_TenantId", + table: "Risks", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Projects_CreatorId", + table: "Projects", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Projects_UpdatorId", + table: "Projects", + column: "UpdatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Programmes_CreatorId", + table: "Programmes", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Programmes_OwnerId", + table: "Programmes", + column: "OwnerId"); + + migrationBuilder.CreateIndex( + name: "IX_Portfolios_CreatorId", + table: "Portfolios", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Portfolios_OwnerId", + table: "Portfolios", + column: "OwnerId"); + + migrationBuilder.CreateIndex( + name: "IX_Outcomes_CreatorId", + table: "Outcomes", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Organisations_CreatorId", + table: "Organisations", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Notifications_RecipientUserId", + table: "Notifications", + column: "RecipientUserId"); + + migrationBuilder.CreateIndex( + name: "IX_Milestones_CreatorId", + table: "Milestones", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Milestones_TenantId", + table: "Milestones", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Milestones_UpdatorId", + table: "Milestones", + column: "UpdatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Issues_AssigneeId", + table: "Issues", + column: "AssigneeId"); + + migrationBuilder.CreateIndex( + name: "IX_Issues_CreatorId", + table: "Issues", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Issues_TenantId", + table: "Issues", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Invites_RecipientUserId", + table: "Invites", + column: "RecipientUserId"); + + migrationBuilder.CreateIndex( + name: "IX_Invites_TenantId", + table: "Invites", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Instruments_CreatorId", + table: "Instruments", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Instruments_TenantId", + table: "Instruments", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Indicators_CreatorId", + table: "Indicators", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Indicators_TenantId", + table: "Indicators", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Evidences_CreatorId", + table: "Evidences", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Evidences_TenantId", + table: "Evidences", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Evidences_UpdatorId", + table: "Evidences", + column: "UpdatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Disbursements_CreatorId", + table: "Disbursements", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Disbursements_TenantId", + table: "Disbursements", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Disbursements_UpdatorId", + table: "Disbursements", + column: "UpdatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Contracts_CreatorId", + table: "Contracts", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Contracts_TenantId", + table: "Contracts", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_ComplianceItems_CreatorId", + table: "ComplianceItems", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_ComplianceItems_TenantId", + table: "ComplianceItems", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_ComplianceItems_VerifierId", + table: "ComplianceItems", + column: "VerifierId"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeRequests_ApproverId", + table: "ChangeRequests", + column: "ApproverId"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeRequests_CreatorId", + table: "ChangeRequests", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeRequests_TenantId", + table: "ChangeRequests", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Budgets_ApproverId", + table: "Budgets", + column: "ApproverId"); + + migrationBuilder.CreateIndex( + name: "IX_Budgets_CreatorId", + table: "Budgets", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Budgets_TenantId", + table: "Budgets", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Beneficiaries_TenantId", + table: "Beneficiaries", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Awards_ApproverId", + table: "Awards", + column: "ApproverId"); + + migrationBuilder.CreateIndex( + name: "IX_Awards_CreatorId", + table: "Awards", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Awards_UpdatorId", + table: "Awards", + column: "UpdatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Activities_ApproverId", + table: "Activities", + column: "ApproverId"); + + migrationBuilder.CreateIndex( + name: "IX_Activities_CreatorId", + table: "Activities", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Activities_TenantId", + table: "Activities", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Activities_UpdatorId", + table: "Activities", + column: "UpdatorId"); + + migrationBuilder.Sql(@" + UPDATE ""SiteVisits"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Rules"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Risks"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Programmes"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Portfolios"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Notifications"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Milestones"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Issues"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Invites"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Instruments"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Indicators"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Evidences"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Disbursements"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Contracts"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""ComplianceItems"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""ChangeRequests"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Budgets"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Beneficiaries"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Awards"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Activities"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + UPDATE ""Projects"" SET ""TenantId"" = 1 WHERE ""TenantId"" = 0; + "); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Milestones_MilestoneId", + table: "Activities", + column: "MilestoneId", + principalTable: "Milestones", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Projects_ProjectId", + table: "Activities", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Tenants_TenantId", + table: "Activities", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Users_ApproverId", + table: "Activities", + column: "ApproverId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Users_CreatorId", + table: "Activities", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Users_UpdatorId", + table: "Activities", + column: "UpdatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Organisations_OrganisationId", + table: "Awards", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Programmes_ProgrammeId", + table: "Awards", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Projects_ProjectId", + table: "Awards", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Tenants_TenantId", + table: "Awards", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Users_ApproverId", + table: "Awards", + column: "ApproverId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Users_CreatorId", + table: "Awards", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Users_UpdatorId", + table: "Awards", + column: "UpdatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Beneficiaries_Projects_ProjectId", + table: "Beneficiaries", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Beneficiaries_Tenants_TenantId", + table: "Beneficiaries", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Beneficiaries_Users_CreatedBy", + table: "Beneficiaries", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Beneficiaries_Users_UserId", + table: "Beneficiaries", + column: "UserId", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Budgets_Projects_ProjectId", + table: "Budgets", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Budgets_Tenants_TenantId", + table: "Budgets", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Budgets_Users_ApproverId", + table: "Budgets", + column: "ApproverId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Budgets_Users_CreatorId", + table: "Budgets", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ChangeRequests_Projects_ProjectId", + table: "ChangeRequests", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_ChangeRequests_Tenants_TenantId", + table: "ChangeRequests", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_ChangeRequests_Users_ApproverId", + table: "ChangeRequests", + column: "ApproverId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ChangeRequests_Users_CreatorId", + table: "ChangeRequests", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ComplianceItems_Projects_ProjectId", + table: "ComplianceItems", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_ComplianceItems_Tenants_TenantId", + table: "ComplianceItems", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_ComplianceItems_Users_CreatorId", + table: "ComplianceItems", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ComplianceItems_Users_VerifierId", + table: "ComplianceItems", + column: "VerifierId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Contracts_Awards_AwardId", + table: "Contracts", + column: "AwardId", + principalTable: "Awards", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Contracts_Tenants_TenantId", + table: "Contracts", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Contracts_Users_CreatorId", + table: "Contracts", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Milestones_MilestoneId", + table: "Disbursements", + column: "MilestoneId", + principalTable: "Milestones", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Projects_ProjectId", + table: "Disbursements", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Tenants_TenantId", + table: "Disbursements", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Users_CreatorId", + table: "Disbursements", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Users_UpdatorId", + table: "Disbursements", + column: "UpdatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Activities_ActivityId", + table: "Evidences", + column: "ActivityId", + principalTable: "Activities", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Indicators_IndicatorId", + table: "Evidences", + column: "IndicatorId", + principalTable: "Indicators", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Milestones_MilestoneId", + table: "Evidences", + column: "MilestoneId", + principalTable: "Milestones", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Projects_ProjectId", + table: "Evidences", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Tenants_TenantId", + table: "Evidences", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Users_CreatorId", + table: "Evidences", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Users_UpdatorId", + table: "Evidences", + column: "UpdatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Indicators_Projects_ProjectId", + table: "Indicators", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Indicators_Tenants_TenantId", + table: "Indicators", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Indicators_Users_CreatorId", + table: "Indicators", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Instruments_Programmes_ProgrammeId", + table: "Instruments", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Instruments_Tenants_TenantId", + table: "Instruments", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Instruments_Users_CreatorId", + table: "Instruments", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Awards_AwardId", + table: "Invites", + column: "AwardId", + principalTable: "Awards", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Contracts_ContractId", + table: "Invites", + column: "ContractId", + principalTable: "Contracts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Organisations_InvitedOrganisationId", + table: "Invites", + column: "InvitedOrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Organisations_OrganisationId", + table: "Invites", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Tenants_TenantId", + table: "Invites", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Users_RecipientUserId", + table: "Invites", + column: "RecipientUserId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Issues_Projects_ProjectId", + table: "Issues", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Issues_Tenants_TenantId", + table: "Issues", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Issues_Users_AssigneeId", + table: "Issues", + column: "AssigneeId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Issues_Users_CreatorId", + table: "Issues", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Milestones_Projects_ProjectId", + table: "Milestones", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Milestones_Tenants_TenantId", + table: "Milestones", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Milestones_Users_CreatorId", + table: "Milestones", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Milestones_Users_UpdatorId", + table: "Milestones", + column: "UpdatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Notifications_Organisations_OrganisationId", + table: "Notifications", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Notifications_Tenants_TenantId", + table: "Notifications", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Notifications_Users_RecipientUserId", + table: "Notifications", + column: "RecipientUserId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Organisations_Users_CreatorId", + table: "Organisations", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Outcomes_Beneficiaries_BeneficiaryId", + table: "Outcomes", + column: "BeneficiaryId", + principalTable: "Beneficiaries", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Outcomes_Users_CreatorId", + table: "Outcomes", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Portfolios_Organisations_OrganisationId", + table: "Portfolios", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Portfolios_Tenants_TenantId", + table: "Portfolios", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Portfolios_Users_CreatorId", + table: "Portfolios", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Portfolios_Users_OwnerId", + table: "Portfolios", + column: "OwnerId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_Portfolios_PortfolioId", + table: "Programmes", + column: "PortfolioId", + principalTable: "Portfolios", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_Tenants_TenantId", + table: "Programmes", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_Users_CreatorId", + table: "Programmes", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_Users_OwnerId", + table: "Programmes", + column: "OwnerId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Programmes_ProgrammeId", + table: "Projects", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Tenants_TenantId", + table: "Projects", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Users_CreatorId", + table: "Projects", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Users_UpdatorId", + table: "Projects", + column: "UpdatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Risks_Projects_ProjectId", + table: "Risks", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Risks_Tenants_TenantId", + table: "Risks", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Risks_Users_CreatorId", + table: "Risks", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Rules_Programmes_ProgrammeId", + table: "Rules", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Rules_Tenants_TenantId", + table: "Rules", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Rules_Users_CreatorId", + table: "Rules", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Rules_Users_UpdatorId", + table: "Rules", + column: "UpdatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_SiteVisits_Projects_ProjectId", + table: "SiteVisits", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_SiteVisits_Tenants_TenantId", + table: "SiteVisits", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_SiteVisits_Users_CreatorId", + table: "SiteVisits", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_TenantOrganisations_Organisations_OrganisationId", + table: "TenantOrganisations", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_TenantOrganisations_Tenants_TenantId", + table: "TenantOrganisations", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_TenantOrganisations_Users_CreatorId", + table: "TenantOrganisations", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Tenants_Users_CreatorId", + table: "Tenants", + column: "CreatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Tenants_Users_UpdatorId", + table: "Tenants", + column: "UpdatorId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_TenantUsers_Tenants_TenantId", + table: "TenantUsers", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_TenantUsers_Users_CreatedBy", + table: "TenantUsers", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_TenantUsers_Users_UserId", + table: "TenantUsers", + column: "UserId", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Activities_Milestones_MilestoneId", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Projects_ProjectId", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Tenants_TenantId", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Users_ApproverId", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Users_CreatorId", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Activities_Users_UpdatorId", + table: "Activities"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Organisations_OrganisationId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Programmes_ProgrammeId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Projects_ProjectId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Tenants_TenantId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Users_ApproverId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Users_CreatorId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Awards_Users_UpdatorId", + table: "Awards"); + + migrationBuilder.DropForeignKey( + name: "FK_Beneficiaries_Projects_ProjectId", + table: "Beneficiaries"); + + migrationBuilder.DropForeignKey( + name: "FK_Beneficiaries_Tenants_TenantId", + table: "Beneficiaries"); + + migrationBuilder.DropForeignKey( + name: "FK_Beneficiaries_Users_CreatedBy", + table: "Beneficiaries"); + + migrationBuilder.DropForeignKey( + name: "FK_Beneficiaries_Users_UserId", + table: "Beneficiaries"); + + migrationBuilder.DropForeignKey( + name: "FK_Budgets_Projects_ProjectId", + table: "Budgets"); + + migrationBuilder.DropForeignKey( + name: "FK_Budgets_Tenants_TenantId", + table: "Budgets"); + + migrationBuilder.DropForeignKey( + name: "FK_Budgets_Users_ApproverId", + table: "Budgets"); + + migrationBuilder.DropForeignKey( + name: "FK_Budgets_Users_CreatorId", + table: "Budgets"); + + migrationBuilder.DropForeignKey( + name: "FK_ChangeRequests_Projects_ProjectId", + table: "ChangeRequests"); + + migrationBuilder.DropForeignKey( + name: "FK_ChangeRequests_Tenants_TenantId", + table: "ChangeRequests"); + + migrationBuilder.DropForeignKey( + name: "FK_ChangeRequests_Users_ApproverId", + table: "ChangeRequests"); + + migrationBuilder.DropForeignKey( + name: "FK_ChangeRequests_Users_CreatorId", + table: "ChangeRequests"); + + migrationBuilder.DropForeignKey( + name: "FK_ComplianceItems_Projects_ProjectId", + table: "ComplianceItems"); + + migrationBuilder.DropForeignKey( + name: "FK_ComplianceItems_Tenants_TenantId", + table: "ComplianceItems"); + + migrationBuilder.DropForeignKey( + name: "FK_ComplianceItems_Users_CreatorId", + table: "ComplianceItems"); + + migrationBuilder.DropForeignKey( + name: "FK_ComplianceItems_Users_VerifierId", + table: "ComplianceItems"); + + migrationBuilder.DropForeignKey( + name: "FK_Contracts_Awards_AwardId", + table: "Contracts"); + + migrationBuilder.DropForeignKey( + name: "FK_Contracts_Tenants_TenantId", + table: "Contracts"); + + migrationBuilder.DropForeignKey( + name: "FK_Contracts_Users_CreatorId", + table: "Contracts"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Milestones_MilestoneId", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Projects_ProjectId", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Tenants_TenantId", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Users_CreatorId", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Disbursements_Users_UpdatorId", + table: "Disbursements"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Activities_ActivityId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Indicators_IndicatorId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Milestones_MilestoneId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Projects_ProjectId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Tenants_TenantId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Users_CreatorId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Evidences_Users_UpdatorId", + table: "Evidences"); + + migrationBuilder.DropForeignKey( + name: "FK_Indicators_Projects_ProjectId", + table: "Indicators"); + + migrationBuilder.DropForeignKey( + name: "FK_Indicators_Tenants_TenantId", + table: "Indicators"); + + migrationBuilder.DropForeignKey( + name: "FK_Indicators_Users_CreatorId", + table: "Indicators"); + + migrationBuilder.DropForeignKey( + name: "FK_Instruments_Programmes_ProgrammeId", + table: "Instruments"); + + migrationBuilder.DropForeignKey( + name: "FK_Instruments_Tenants_TenantId", + table: "Instruments"); + + migrationBuilder.DropForeignKey( + name: "FK_Instruments_Users_CreatorId", + table: "Instruments"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Awards_AwardId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Contracts_ContractId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Organisations_InvitedOrganisationId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Organisations_OrganisationId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Tenants_TenantId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Invites_Users_RecipientUserId", + table: "Invites"); + + migrationBuilder.DropForeignKey( + name: "FK_Issues_Projects_ProjectId", + table: "Issues"); + + migrationBuilder.DropForeignKey( + name: "FK_Issues_Tenants_TenantId", + table: "Issues"); + + migrationBuilder.DropForeignKey( + name: "FK_Issues_Users_AssigneeId", + table: "Issues"); + + migrationBuilder.DropForeignKey( + name: "FK_Issues_Users_CreatorId", + table: "Issues"); + + migrationBuilder.DropForeignKey( + name: "FK_Milestones_Projects_ProjectId", + table: "Milestones"); + + migrationBuilder.DropForeignKey( + name: "FK_Milestones_Tenants_TenantId", + table: "Milestones"); + + migrationBuilder.DropForeignKey( + name: "FK_Milestones_Users_CreatorId", + table: "Milestones"); + + migrationBuilder.DropForeignKey( + name: "FK_Milestones_Users_UpdatorId", + table: "Milestones"); + + migrationBuilder.DropForeignKey( + name: "FK_Notifications_Organisations_OrganisationId", + table: "Notifications"); + + migrationBuilder.DropForeignKey( + name: "FK_Notifications_Tenants_TenantId", + table: "Notifications"); + + migrationBuilder.DropForeignKey( + name: "FK_Notifications_Users_RecipientUserId", + table: "Notifications"); + + migrationBuilder.DropForeignKey( + name: "FK_Organisations_Users_CreatorId", + table: "Organisations"); + + migrationBuilder.DropForeignKey( + name: "FK_Outcomes_Beneficiaries_BeneficiaryId", + table: "Outcomes"); + + migrationBuilder.DropForeignKey( + name: "FK_Outcomes_Users_CreatorId", + table: "Outcomes"); + + migrationBuilder.DropForeignKey( + name: "FK_Portfolios_Organisations_OrganisationId", + table: "Portfolios"); + + migrationBuilder.DropForeignKey( + name: "FK_Portfolios_Tenants_TenantId", + table: "Portfolios"); + + migrationBuilder.DropForeignKey( + name: "FK_Portfolios_Users_CreatorId", + table: "Portfolios"); + + migrationBuilder.DropForeignKey( + name: "FK_Portfolios_Users_OwnerId", + table: "Portfolios"); + + migrationBuilder.DropForeignKey( + name: "FK_Programmes_Portfolios_PortfolioId", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_Programmes_Tenants_TenantId", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_Programmes_Users_CreatorId", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_Programmes_Users_OwnerId", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_Projects_Programmes_ProgrammeId", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_Projects_Tenants_TenantId", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_Projects_Users_CreatorId", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_Projects_Users_UpdatorId", + table: "Projects"); + + migrationBuilder.DropForeignKey( + name: "FK_Risks_Projects_ProjectId", + table: "Risks"); + + migrationBuilder.DropForeignKey( + name: "FK_Risks_Tenants_TenantId", + table: "Risks"); + + migrationBuilder.DropForeignKey( + name: "FK_Risks_Users_CreatorId", + table: "Risks"); + + migrationBuilder.DropForeignKey( + name: "FK_Rules_Programmes_ProgrammeId", + table: "Rules"); + + migrationBuilder.DropForeignKey( + name: "FK_Rules_Tenants_TenantId", + table: "Rules"); + + migrationBuilder.DropForeignKey( + name: "FK_Rules_Users_CreatorId", + table: "Rules"); + + migrationBuilder.DropForeignKey( + name: "FK_Rules_Users_UpdatorId", + table: "Rules"); + + migrationBuilder.DropForeignKey( + name: "FK_SiteVisits_Projects_ProjectId", + table: "SiteVisits"); + + migrationBuilder.DropForeignKey( + name: "FK_SiteVisits_Tenants_TenantId", + table: "SiteVisits"); + + migrationBuilder.DropForeignKey( + name: "FK_SiteVisits_Users_CreatorId", + table: "SiteVisits"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantOrganisations_Organisations_OrganisationId", + table: "TenantOrganisations"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantOrganisations_Tenants_TenantId", + table: "TenantOrganisations"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantOrganisations_Users_CreatorId", + table: "TenantOrganisations"); + + migrationBuilder.DropForeignKey( + name: "FK_Tenants_Users_CreatorId", + table: "Tenants"); + + migrationBuilder.DropForeignKey( + name: "FK_Tenants_Users_UpdatorId", + table: "Tenants"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantUsers_Tenants_TenantId", + table: "TenantUsers"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantUsers_Users_CreatedBy", + table: "TenantUsers"); + + migrationBuilder.DropForeignKey( + name: "FK_TenantUsers_Users_UserId", + table: "TenantUsers"); + + migrationBuilder.DropIndex( + name: "IX_Tenants_CreatorId", + table: "Tenants"); + + migrationBuilder.DropIndex( + name: "IX_Tenants_UpdatorId", + table: "Tenants"); + + migrationBuilder.DropIndex( + name: "IX_TenantOrganisations_CreatorId", + table: "TenantOrganisations"); + + migrationBuilder.DropIndex( + name: "IX_SiteVisits_CreatorId", + table: "SiteVisits"); + + migrationBuilder.DropIndex( + name: "IX_SiteVisits_TenantId", + table: "SiteVisits"); + + migrationBuilder.DropIndex( + name: "IX_Rules_CreatorId", + table: "Rules"); + + migrationBuilder.DropIndex( + name: "IX_Rules_TenantId", + table: "Rules"); + + migrationBuilder.DropIndex( + name: "IX_Rules_UpdatorId", + table: "Rules"); + + migrationBuilder.DropIndex( + name: "IX_Risks_CreatorId", + table: "Risks"); + + migrationBuilder.DropIndex( + name: "IX_Risks_TenantId", + table: "Risks"); + + migrationBuilder.DropIndex( + name: "IX_Projects_CreatorId", + table: "Projects"); + + migrationBuilder.DropIndex( + name: "IX_Projects_UpdatorId", + table: "Projects"); + + migrationBuilder.DropIndex( + name: "IX_Programmes_CreatorId", + table: "Programmes"); + + migrationBuilder.DropIndex( + name: "IX_Programmes_OwnerId", + table: "Programmes"); + + migrationBuilder.DropIndex( + name: "IX_Portfolios_CreatorId", + table: "Portfolios"); + + migrationBuilder.DropIndex( + name: "IX_Portfolios_OwnerId", + table: "Portfolios"); + + migrationBuilder.DropIndex( + name: "IX_Outcomes_CreatorId", + table: "Outcomes"); + + migrationBuilder.DropIndex( + name: "IX_Organisations_CreatorId", + table: "Organisations"); + + migrationBuilder.DropIndex( + name: "IX_Notifications_RecipientUserId", + table: "Notifications"); + + migrationBuilder.DropIndex( + name: "IX_Milestones_CreatorId", + table: "Milestones"); + + migrationBuilder.DropIndex( + name: "IX_Milestones_TenantId", + table: "Milestones"); + + migrationBuilder.DropIndex( + name: "IX_Milestones_UpdatorId", + table: "Milestones"); + + migrationBuilder.DropIndex( + name: "IX_Issues_AssigneeId", + table: "Issues"); + + migrationBuilder.DropIndex( + name: "IX_Issues_CreatorId", + table: "Issues"); + + migrationBuilder.DropIndex( + name: "IX_Issues_TenantId", + table: "Issues"); + + migrationBuilder.DropIndex( + name: "IX_Invites_RecipientUserId", + table: "Invites"); + + migrationBuilder.DropIndex( + name: "IX_Invites_TenantId", + table: "Invites"); + + migrationBuilder.DropIndex( + name: "IX_Instruments_CreatorId", + table: "Instruments"); + + migrationBuilder.DropIndex( + name: "IX_Instruments_TenantId", + table: "Instruments"); + + migrationBuilder.DropIndex( + name: "IX_Indicators_CreatorId", + table: "Indicators"); + + migrationBuilder.DropIndex( + name: "IX_Indicators_TenantId", + table: "Indicators"); + + migrationBuilder.DropIndex( + name: "IX_Evidences_CreatorId", + table: "Evidences"); + + migrationBuilder.DropIndex( + name: "IX_Evidences_TenantId", + table: "Evidences"); + + migrationBuilder.DropIndex( + name: "IX_Evidences_UpdatorId", + table: "Evidences"); + + migrationBuilder.DropIndex( + name: "IX_Disbursements_CreatorId", + table: "Disbursements"); + + migrationBuilder.DropIndex( + name: "IX_Disbursements_TenantId", + table: "Disbursements"); + + migrationBuilder.DropIndex( + name: "IX_Disbursements_UpdatorId", + table: "Disbursements"); + + migrationBuilder.DropIndex( + name: "IX_Contracts_CreatorId", + table: "Contracts"); + + migrationBuilder.DropIndex( + name: "IX_Contracts_TenantId", + table: "Contracts"); + + migrationBuilder.DropIndex( + name: "IX_ComplianceItems_CreatorId", + table: "ComplianceItems"); + + migrationBuilder.DropIndex( + name: "IX_ComplianceItems_TenantId", + table: "ComplianceItems"); + + migrationBuilder.DropIndex( + name: "IX_ComplianceItems_VerifierId", + table: "ComplianceItems"); + + migrationBuilder.DropIndex( + name: "IX_ChangeRequests_ApproverId", + table: "ChangeRequests"); + + migrationBuilder.DropIndex( + name: "IX_ChangeRequests_CreatorId", + table: "ChangeRequests"); + + migrationBuilder.DropIndex( + name: "IX_ChangeRequests_TenantId", + table: "ChangeRequests"); + + migrationBuilder.DropIndex( + name: "IX_Budgets_ApproverId", + table: "Budgets"); + + migrationBuilder.DropIndex( + name: "IX_Budgets_CreatorId", + table: "Budgets"); + + migrationBuilder.DropIndex( + name: "IX_Budgets_TenantId", + table: "Budgets"); + + migrationBuilder.DropIndex( + name: "IX_Beneficiaries_TenantId", + table: "Beneficiaries"); + + migrationBuilder.DropIndex( + name: "IX_Awards_ApproverId", + table: "Awards"); + + migrationBuilder.DropIndex( + name: "IX_Awards_CreatorId", + table: "Awards"); + + migrationBuilder.DropIndex( + name: "IX_Awards_UpdatorId", + table: "Awards"); + + migrationBuilder.DropIndex( + name: "IX_Activities_ApproverId", + table: "Activities"); + + migrationBuilder.DropIndex( + name: "IX_Activities_CreatorId", + table: "Activities"); + + migrationBuilder.DropIndex( + name: "IX_Activities_TenantId", + table: "Activities"); + + migrationBuilder.DropIndex( + name: "IX_Activities_UpdatorId", + table: "Activities"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Tenants"); + + migrationBuilder.DropColumn( + name: "UpdatorId", + table: "Tenants"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "TenantOrganisations"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "SiteVisits"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "SiteVisits"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Rules"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Rules"); + + migrationBuilder.DropColumn( + name: "UpdatorId", + table: "Rules"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Risks"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Risks"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Projects"); + + migrationBuilder.DropColumn( + name: "UpdatorId", + table: "Projects"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Programmes"); + + migrationBuilder.DropColumn( + name: "OwnerId", + table: "Programmes"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Portfolios"); + + migrationBuilder.DropColumn( + name: "OwnerId", + table: "Portfolios"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Outcomes"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Organisations"); + + migrationBuilder.DropColumn( + name: "RecipientUserId", + table: "Notifications"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Milestones"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Milestones"); + + migrationBuilder.DropColumn( + name: "UpdatorId", + table: "Milestones"); + + migrationBuilder.DropColumn( + name: "AssigneeId", + table: "Issues"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Issues"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Issues"); + + migrationBuilder.DropColumn( + name: "RecipientUserId", + table: "Invites"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Invites"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Instruments"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Instruments"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Indicators"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Indicators"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Evidences"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Evidences"); + + migrationBuilder.DropColumn( + name: "UpdatorId", + table: "Evidences"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Disbursements"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Disbursements"); + + migrationBuilder.DropColumn( + name: "UpdatorId", + table: "Disbursements"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Contracts"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Contracts"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "ComplianceItems"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "ComplianceItems"); + + migrationBuilder.DropColumn( + name: "VerifierId", + table: "ComplianceItems"); + + migrationBuilder.DropColumn( + name: "ApproverId", + table: "ChangeRequests"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "ChangeRequests"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "ChangeRequests"); + + migrationBuilder.DropColumn( + name: "ApproverId", + table: "Budgets"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Budgets"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Budgets"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Beneficiaries"); + + migrationBuilder.DropColumn( + name: "ApproverId", + table: "Awards"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Awards"); + + migrationBuilder.DropColumn( + name: "UpdatorId", + table: "Awards"); + + migrationBuilder.DropColumn( + name: "ApproverId", + table: "Activities"); + + migrationBuilder.DropColumn( + name: "CreatorId", + table: "Activities"); + + migrationBuilder.DropColumn( + name: "TenantId", + table: "Activities"); + + migrationBuilder.DropColumn( + name: "UpdatorId", + table: "Activities"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Users", + type: "integer", + nullable: false, + defaultValueSql: "2", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Email", + table: "Users", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "TenantUsers", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "TenantUsers", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Tenants", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Tenants", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Tenants", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "TenantOrganisations", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "TenantOrganisations", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "SiteVisits", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "InspectorName", + table: "SiteVisits", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Findings", + table: "SiteVisits", + type: "character varying(4096)", + maxLength: 4096, + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "SiteVisits", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Version", + table: "Rules", + type: "integer", + nullable: false, + defaultValue: 1, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Rules", + type: "integer", + nullable: false, + defaultValueSql: "2", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Rules", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Rules", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Risks", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Likelihood", + table: "Risks", + type: "integer", + nullable: false, + defaultValueSql: "3", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Impact", + table: "Risks", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Risks", + type: "character varying(1024)", + maxLength: 1024, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Risks", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Projects", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Sector", + table: "Projects", + type: "integer", + nullable: false, + defaultValueSql: "11", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "ProjectType", + table: "Projects", + type: "integer", + nullable: false, + defaultValueSql: "10", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Projects", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Projects", + type: "character varying(1024)", + maxLength: 1024, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Projects", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Programmes", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Programmes", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Programmes", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Portfolios", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Portfolios", + type: "character varying(1024)", + maxLength: 1024, + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Portfolios", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Outcomes", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Outcomes", + type: "character varying(1024)", + maxLength: 1024, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Outcomes", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Organisations", + type: "integer", + nullable: false, + defaultValueSql: "5", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Organisations", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "RegistrationNo", + table: "Organisations", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Organisations", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Email", + table: "Organisations", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Organisations", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Subject", + table: "Notifications", + type: "character varying(256)", + maxLength: 256, + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Notifications", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Platform", + table: "Notifications", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Message", + table: "Notifications", + type: "character varying(4096)", + maxLength: 4096, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Destination", + table: "Notifications", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Notifications", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Milestones", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Priority", + table: "Milestones", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Milestones", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Milestones", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Title", + table: "Issues", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Issues", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Resolution", + table: "Issues", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Priority", + table: "Issues", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Issues", + type: "character varying(1024)", + maxLength: 1024, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Issues", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Invites", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Instruments", + type: "integer", + nullable: false, + defaultValueSql: "2", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Instruments", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Instruments", + type: "character varying(1024)", + maxLength: 1024, + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Instruments", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Code", + table: "Instruments", + type: "character varying(100)", + maxLength: 100, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "UnitOfMeasure", + table: "Indicators", + type: "integer", + nullable: false, + defaultValueSql: "2", + oldClrType: typeof(int), + oldType: "integer", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "TargetAmount", + table: "Indicators", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Indicators", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Indicators", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "BaselineAmount", + table: "Indicators", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric"); + + migrationBuilder.AlterColumn( + name: "ActualAmount", + table: "Indicators", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric"); + + migrationBuilder.AlterColumn( + name: "Version", + table: "Evidences", + type: "integer", + nullable: false, + defaultValue: 1, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Evidences", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Type", + table: "Evidences", + type: "integer", + nullable: false, + defaultValueSql: "9", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Evidences", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "DocumentUrl", + table: "Evidences", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Evidences", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Disbursements", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Disbursements", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Amount", + table: "Disbursements", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric"); + + migrationBuilder.AlterColumn( + name: "TotalValue", + table: "Contracts", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric"); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Contracts", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Contracts", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Title", + table: "ComplianceItems", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "ComplianceItems", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Requirements", + table: "ComplianceItems", + type: "character varying(2048)", + maxLength: 2048, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "ComplianceItems", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Title", + table: "ChangeRequests", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "ChangeRequests", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "RevisedBudget", + table: "ChangeRequests", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: true, + oldClrType: typeof(decimal), + oldType: "numeric", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Justification", + table: "ChangeRequests", + type: "character varying(1024)", + maxLength: 1024, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "ChangeRequests", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Budgets", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Budgets", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Amount", + table: "Budgets", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Beneficiaries", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Location", + table: "Beneficiaries", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Beneficiaries", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Category", + table: "Beneficiaries", + type: "character varying(100)", + maxLength: 100, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Awards", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Awards", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Amount", + table: "Awards", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric"); + + migrationBuilder.AlterColumn( + name: "Timestamp", + table: "AuditLogs", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "EntityName", + table: "AuditLogs", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "EntityId", + table: "AuditLogs", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Action", + table: "AuditLogs", + type: "character varying(100)", + maxLength: 100, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "Changes", + table: "AuditLogs", + type: "jsonb", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Title", + table: "Activities", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Status", + table: "Activities", + type: "integer", + nullable: false, + defaultValueSql: "1", + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "ProjectId", + table: "Activities", + type: "bigint", + nullable: false, + defaultValue: 0L, + oldClrType: typeof(long), + oldType: "bigint", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "MilestoneId", + table: "Activities", + type: "bigint", + nullable: false, + defaultValue: 0L, + oldClrType: typeof(long), + oldType: "bigint", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Activities", + type: "character varying(1024)", + maxLength: 1024, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreatedAt", + table: "Activities", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "Category", + table: "Activities", + type: "character varying(256)", + maxLength: 256, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Amount", + table: "Activities", + type: "numeric(18,2)", + precision: 18, + scale: 2, + nullable: false, + oldClrType: typeof(decimal), + oldType: "numeric"); + + migrationBuilder.CreateIndex( + name: "IX_Tenants_CreatedBy", + table: "Tenants", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Tenants_UpdatedBy", + table: "Tenants", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_TenantOrganisations_CreatedBy", + table: "TenantOrganisations", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_SiteVisits_CreatedBy", + table: "SiteVisits", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Rules_CreatedBy", + table: "Rules", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Rules_UpdatedBy", + table: "Rules", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Risks_CreatedBy", + table: "Risks", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Projects_CreatedBy", + table: "Projects", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Projects_UpdatedBy", + table: "Projects", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Programmes_CreatedBy", + table: "Programmes", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Programmes_OwnedBy", + table: "Programmes", + column: "OwnedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Portfolios_CreatedBy", + table: "Portfolios", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Portfolios_OwnedBy", + table: "Portfolios", + column: "OwnedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Outcomes_CreatedBy", + table: "Outcomes", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Organisations_CreatedBy", + table: "Organisations", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Notifications_Recipient", + table: "Notifications", + column: "Recipient"); + + migrationBuilder.CreateIndex( + name: "IX_Milestones_CreatedBy", + table: "Milestones", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Milestones_UpdatedBy", + table: "Milestones", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Issues_AssignedTo", + table: "Issues", + column: "AssignedTo"); + + migrationBuilder.CreateIndex( + name: "IX_Issues_CreatedBy", + table: "Issues", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Invites_Recipient", + table: "Invites", + column: "Recipient"); + + migrationBuilder.CreateIndex( + name: "IX_Instruments_CreatedBy", + table: "Instruments", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Indicators_CreatedBy", + table: "Indicators", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Evidences_CreatedBy", + table: "Evidences", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Evidences_UpdatedBy", + table: "Evidences", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Disbursements_CreatedBy", + table: "Disbursements", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Disbursements_UpdatedBy", + table: "Disbursements", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Contracts_CreatedBy", + table: "Contracts", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_ComplianceItems_CreatedBy", + table: "ComplianceItems", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_ComplianceItems_VerifiedBy", + table: "ComplianceItems", + column: "VerifiedBy"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeRequests_ApprovedBy", + table: "ChangeRequests", + column: "ApprovedBy"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeRequests_CreatedBy", + table: "ChangeRequests", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Budgets_ApprovedBy", + table: "Budgets", + column: "ApprovedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Budgets_CreatedBy", + table: "Budgets", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Awards_ApprovedBy", + table: "Awards", + column: "ApprovedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Awards_CreatedBy", + table: "Awards", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Awards_UpdatedBy", + table: "Awards", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Activities_ApprovedBy", + table: "Activities", + column: "ApprovedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Activities_CreatedBy", + table: "Activities", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Activities_UpdatedBy", + table: "Activities", + column: "UpdatedBy"); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Milestones_MilestoneId", + table: "Activities", + column: "MilestoneId", + principalTable: "Milestones", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Projects_ProjectId", + table: "Activities", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Users_ApprovedBy", + table: "Activities", + column: "ApprovedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Users_CreatedBy", + table: "Activities", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Activities_Users_UpdatedBy", + table: "Activities", + column: "UpdatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Organisations_OrganisationId", + table: "Awards", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Programmes_ProgrammeId", + table: "Awards", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Projects_ProjectId", + table: "Awards", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Tenants_TenantId", + table: "Awards", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Users_ApprovedBy", + table: "Awards", + column: "ApprovedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Users_CreatedBy", + table: "Awards", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Awards_Users_UpdatedBy", + table: "Awards", + column: "UpdatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Beneficiaries_Projects_ProjectId", + table: "Beneficiaries", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Beneficiaries_Users_CreatedBy", + table: "Beneficiaries", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Beneficiaries_Users_UserId", + table: "Beneficiaries", + column: "UserId", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Budgets_Projects_ProjectId", + table: "Budgets", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Budgets_Users_ApprovedBy", + table: "Budgets", + column: "ApprovedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Budgets_Users_CreatedBy", + table: "Budgets", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ChangeRequests_Projects_ProjectId", + table: "ChangeRequests", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_ChangeRequests_Users_ApprovedBy", + table: "ChangeRequests", + column: "ApprovedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ChangeRequests_Users_CreatedBy", + table: "ChangeRequests", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ComplianceItems_Projects_ProjectId", + table: "ComplianceItems", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_ComplianceItems_Users_CreatedBy", + table: "ComplianceItems", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ComplianceItems_Users_VerifiedBy", + table: "ComplianceItems", + column: "VerifiedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Contracts_Awards_AwardId", + table: "Contracts", + column: "AwardId", + principalTable: "Awards", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Contracts_Users_CreatedBy", + table: "Contracts", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Milestones_MilestoneId", + table: "Disbursements", + column: "MilestoneId", + principalTable: "Milestones", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Projects_ProjectId", + table: "Disbursements", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Users_CreatedBy", + table: "Disbursements", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Disbursements_Users_UpdatedBy", + table: "Disbursements", + column: "UpdatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Activities_ActivityId", + table: "Evidences", + column: "ActivityId", + principalTable: "Activities", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Indicators_IndicatorId", + table: "Evidences", + column: "IndicatorId", + principalTable: "Indicators", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Milestones_MilestoneId", + table: "Evidences", + column: "MilestoneId", + principalTable: "Milestones", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Projects_ProjectId", + table: "Evidences", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Users_CreatedBy", + table: "Evidences", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Evidences_Users_UpdatedBy", + table: "Evidences", + column: "UpdatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Indicators_Projects_ProjectId", + table: "Indicators", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Indicators_Users_CreatedBy", + table: "Indicators", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Instruments_Programmes_ProgrammeId", + table: "Instruments", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Instruments_Users_CreatedBy", + table: "Instruments", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Awards_AwardId", + table: "Invites", + column: "AwardId", + principalTable: "Awards", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Contracts_ContractId", + table: "Invites", + column: "ContractId", + principalTable: "Contracts", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Organisations_InvitedOrganisationId", + table: "Invites", + column: "InvitedOrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Organisations_OrganisationId", + table: "Invites", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Invites_Users_Recipient", + table: "Invites", + column: "Recipient", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Issues_Projects_ProjectId", + table: "Issues", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Issues_Users_AssignedTo", + table: "Issues", + column: "AssignedTo", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + + migrationBuilder.AddForeignKey( + name: "FK_Issues_Users_CreatedBy", + table: "Issues", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Milestones_Projects_ProjectId", + table: "Milestones", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Milestones_Users_CreatedBy", + table: "Milestones", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Milestones_Users_UpdatedBy", + table: "Milestones", + column: "UpdatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Notifications_Organisations_OrganisationId", + table: "Notifications", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Notifications_Tenants_TenantId", + table: "Notifications", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Notifications_Users_Recipient", + table: "Notifications", + column: "Recipient", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Organisations_Users_CreatedBy", + table: "Organisations", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Outcomes_Beneficiaries_BeneficiaryId", + table: "Outcomes", + column: "BeneficiaryId", + principalTable: "Beneficiaries", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Outcomes_Users_CreatedBy", + table: "Outcomes", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Portfolios_Organisations_OrganisationId", + table: "Portfolios", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Portfolios_Tenants_TenantId", + table: "Portfolios", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Portfolios_Users_CreatedBy", + table: "Portfolios", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Portfolios_Users_OwnedBy", + table: "Portfolios", + column: "OwnedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_Portfolios_PortfolioId", + table: "Programmes", + column: "PortfolioId", + principalTable: "Portfolios", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_Tenants_TenantId", + table: "Programmes", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_Users_CreatedBy", + table: "Programmes", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_Users_OwnedBy", + table: "Programmes", + column: "OwnedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Programmes_ProgrammeId", + table: "Projects", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Tenants_TenantId", + table: "Projects", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Users_CreatedBy", + table: "Projects", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Projects_Users_UpdatedBy", + table: "Projects", + column: "UpdatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Risks_Projects_ProjectId", + table: "Risks", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Risks_Users_CreatedBy", + table: "Risks", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Rules_Programmes_ProgrammeId", + table: "Rules", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Rules_Users_CreatedBy", + table: "Rules", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Rules_Users_UpdatedBy", + table: "Rules", + column: "UpdatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_SiteVisits_Projects_ProjectId", + table: "SiteVisits", + column: "ProjectId", + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_SiteVisits_Users_CreatedBy", + table: "SiteVisits", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_TenantOrganisations_Organisations_OrganisationId", + table: "TenantOrganisations", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_TenantOrganisations_Tenants_TenantId", + table: "TenantOrganisations", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_TenantOrganisations_Users_CreatedBy", + table: "TenantOrganisations", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Tenants_Users_CreatedBy", + table: "Tenants", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Tenants_Users_UpdatedBy", + table: "Tenants", + column: "UpdatedBy", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_TenantUsers_Tenants_TenantId", + table: "TenantUsers", + column: "TenantId", + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_TenantUsers_Users_CreatedBy", + table: "TenantUsers", + column: "CreatedBy", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_TenantUsers_Users_UserId", + table: "TenantUsers", + column: "UserId", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/PostFundManagement.Infrastructure/Database/Migrations/ApplicationDbContextModelSnapshot.cs b/PostFundManagement.Infrastructure/Database/Migrations/ApplicationDbContextModelSnapshot.cs index 81a90d7..613c408 100644 --- a/PostFundManagement.Infrastructure/Database/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/PostFundManagement.Infrastructure/Database/Migrations/ApplicationDbContextModelSnapshot.cs @@ -31,48 +31,46 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Amount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); b.Property("ApprovedBy") .HasColumnType("uuid"); + b.Property("ApproverId") + .HasColumnType("uuid"); + b.Property("Category") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); - b.Property("Description") - .IsRequired() - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); + b.Property("CreatorId") + .HasColumnType("uuid"); - b.Property("MilestoneId") + b.Property("Description") + .HasColumnType("text"); + + b.Property("MilestoneId") .HasColumnType("bigint"); b.Property("PerformedAt") .HasColumnType("timestamp with time zone"); - b.Property("ProjectId") + b.Property("ProjectId") .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("Title") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); @@ -80,17 +78,22 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("UpdatedBy") .HasColumnType("uuid"); + b.Property("UpdatorId") + .HasColumnType("uuid"); + b.HasKey("Id"); - b.HasIndex("ApprovedBy"); + b.HasIndex("ApproverId"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("MilestoneId"); b.HasIndex("ProjectId"); - b.HasIndex("UpdatedBy"); + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); b.ToTable("Activities", (string)null); }); @@ -104,21 +107,13 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Action") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.PrimitiveCollection("Changes") - .HasColumnType("jsonb"); + .HasColumnType("text"); b.Property("EntityId") - .IsRequired() .HasColumnType("text"); b.Property("EntityName") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("PerformedBy") .HasColumnType("uuid"); @@ -127,9 +122,7 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("bigint"); b.Property("Timestamp") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.HasKey("Id"); @@ -145,20 +138,23 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Amount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); b.Property("ApprovedBy") .HasColumnType("uuid"); + b.Property("ApproverId") + .HasColumnType("uuid"); + b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("OrganisationId") .HasColumnType("bigint"); @@ -169,9 +165,7 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("TenantId") .HasColumnType("bigint"); @@ -182,11 +176,14 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("UpdatedBy") .HasColumnType("uuid"); + b.Property("UpdatorId") + .HasColumnType("uuid"); + b.HasKey("Id"); - b.HasIndex("ApprovedBy"); + b.HasIndex("ApproverId"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("OrganisationId"); @@ -196,7 +193,7 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasIndex("TenantId"); - b.HasIndex("UpdatedBy"); + b.HasIndex("UpdatorId"); b.ToTable("Awards", (string)null); }); @@ -210,26 +207,19 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Category") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); + .HasColumnType("text"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); b.Property("Location") - .IsRequired() .HasColumnType("text"); b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("ProjectId") .HasColumnType("bigint"); @@ -240,6 +230,9 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("TargetCount") .HasColumnType("integer"); + b.Property("TenantId") + .HasColumnType("bigint"); + b.Property("UserId") .HasColumnType("uuid"); @@ -249,6 +242,8 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasIndex("ProjectId"); + b.HasIndex("TenantId"); + b.HasIndex("UserId"); b.ToTable("Beneficiaries", (string)null); @@ -263,39 +258,45 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Amount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); b.Property("ApprovedBy") .HasColumnType("uuid"); + b.Property("ApproverId") + .HasColumnType("uuid"); + b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("ProjectId") .HasColumnType("bigint"); + b.Property("TenantId") + .HasColumnType("bigint"); + b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); b.HasKey("Id"); - b.HasIndex("ApprovedBy"); + b.HasIndex("ApproverId"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProjectId"); + b.HasIndex("TenantId"); + b.ToTable("Budgets", (string)null); }); @@ -310,50 +311,52 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("ApprovedBy") .HasColumnType("uuid"); + b.Property("ApproverId") + .HasColumnType("uuid"); + b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Justification") - .IsRequired() - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); + .HasColumnType("text"); b.Property("ProjectId") .HasColumnType("bigint"); b.Property("RevisedBudget") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); b.Property("RevisedEndedAt") .HasColumnType("timestamp with time zone"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("Title") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); b.HasKey("Id"); - b.HasIndex("ApprovedBy"); + b.HasIndex("ApproverId"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProjectId"); + b.HasIndex("TenantId"); + b.ToTable("ChangeRequests", (string)null); }); @@ -366,30 +369,28 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("ProjectId") .HasColumnType("bigint"); b.Property("Requirements") - .IsRequired() - .HasMaxLength(2048) - .HasColumnType("character varying(2048)"); + .HasColumnType("text"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("Title") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); @@ -397,13 +398,18 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("VerifiedBy") .HasColumnType("uuid"); + b.Property("VerifierId") + .HasColumnType("uuid"); + b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProjectId"); - b.HasIndex("VerifiedBy"); + b.HasIndex("TenantId"); + + b.HasIndex("VerifierId"); b.ToTable("ComplianceItems", (string)null); }); @@ -420,13 +426,14 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("bigint"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("EffectiveAt") .HasColumnType("timestamp with time zone"); @@ -440,20 +447,22 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("text"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("TotalValue") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); b.HasKey("Id"); b.HasIndex("AwardId") .IsUnique(); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); + + b.HasIndex("TenantId"); b.ToTable("Contracts", (string)null); }); @@ -467,17 +476,17 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Amount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("MilestoneId") .HasColumnType("bigint"); @@ -485,9 +494,10 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); @@ -495,15 +505,20 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("UpdatedBy") .HasColumnType("uuid"); + b.Property("UpdatorId") + .HasColumnType("uuid"); + b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("MilestoneId"); b.HasIndex("ProjectId"); - b.HasIndex("UpdatedBy"); + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); b.ToTable("Disbursements", (string)null); }); @@ -520,15 +535,15 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("bigint"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("DocumentUrl") - .IsRequired() .HasColumnType("text"); b.Property("IndicatorId") @@ -541,31 +556,31 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("Type") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("9"); + .HasColumnType("integer"); b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); - b.Property("UpdatedBy") + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("UpdatorId") .HasColumnType("uuid"); b.Property("Version") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValue(1); + .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("ActivityId"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("IndicatorId"); @@ -573,7 +588,9 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasIndex("ProjectId"); - b.HasIndex("UpdatedBy"); + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); b.ToTable("Evidences", (string)null); }); @@ -587,44 +604,43 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ActualAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); b.Property("BaselineAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("ProjectId") .HasColumnType("bigint"); b.Property("TargetAmount") - .HasPrecision(18, 2) - .HasColumnType("numeric(18,2)"); + .HasColumnType("numeric"); - b.Property("UnitOfMeasure") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("2"); + b.Property("TenantId") + .HasColumnType("bigint"); + + b.Property("UnitOfMeasure") + .HasColumnType("integer"); b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProjectId"); + b.HasIndex("TenantId"); + b.ToTable("Indicators", (string)null); }); @@ -637,41 +653,40 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Code") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); + .HasColumnType("text"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Description") - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); + .HasColumnType("text"); b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("ProgrammeId") .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("2"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProgrammeId"); + b.HasIndex("TenantId"); + b.ToTable("Instruments", (string)null); }); @@ -690,9 +705,7 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("bigint"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); @@ -706,6 +719,12 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("Recipient") .HasColumnType("uuid"); + b.Property("RecipientUserId") + .HasColumnType("uuid"); + + b.Property("TenantId") + .HasColumnType("bigint"); + b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); @@ -722,7 +741,9 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasIndex("OrganisationId"); - b.HasIndex("Recipient"); + b.HasIndex("RecipientUserId"); + + b.HasIndex("TenantId"); b.ToTable("Invites", (string)null); }); @@ -738,52 +759,52 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("AssignedTo") .HasColumnType("uuid"); + b.Property("AssigneeId") + .HasColumnType("uuid"); + b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Description") - .IsRequired() - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); + .HasColumnType("text"); b.Property("Priority") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("ProjectId") .HasColumnType("bigint"); b.Property("Resolution") - .IsRequired() .HasColumnType("text"); b.Property("ResolvedAt") .HasColumnType("timestamp with time zone"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("Title") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.HasKey("Id"); - b.HasIndex("AssignedTo"); + b.HasIndex("AssigneeId"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProjectId"); + b.HasIndex("TenantId"); + b.ToTable("Issues", (string)null); }); @@ -796,33 +817,31 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("DueAt") .HasColumnType("timestamp with time zone"); b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("Priority") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("ProjectId") .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); @@ -830,13 +849,18 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("UpdatedBy") .HasColumnType("uuid"); + b.Property("UpdatorId") + .HasColumnType("uuid"); + b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProjectId"); - b.HasIndex("UpdatedBy"); + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); b.ToTable("Milestones", (string)null); }); @@ -850,45 +874,37 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("Destination") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("Error") .HasColumnType("text"); b.Property("Message") - .IsRequired() - .HasMaxLength(4096) - .HasColumnType("character varying(4096)"); + .HasColumnType("text"); b.Property("OrganisationId") .HasColumnType("bigint"); b.Property("Platform") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("Recipient") .HasColumnType("uuid"); + b.Property("RecipientUserId") + .HasColumnType("uuid"); + b.Property("SentAt") .HasColumnType("timestamp with time zone"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("Subject") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("TenantId") .HasColumnType("bigint"); @@ -900,7 +916,7 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasIndex("OrganisationId"); - b.HasIndex("Recipient"); + b.HasIndex("RecipientUserId"); b.HasIndex("TenantId"); @@ -916,41 +932,32 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Email") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("RegistrationNo") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("Type") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("5"); + .HasColumnType("integer"); b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.ToTable("Organisations", (string)null); }); @@ -967,28 +974,25 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("bigint"); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Description") - .IsRequired() - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); + .HasColumnType("text"); b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.HasKey("Id"); b.HasIndex("BeneficiaryId"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.ToTable("Outcomes", (string)null); }); @@ -1002,21 +1006,19 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Description") - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); + .HasColumnType("text"); b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("OrganisationId") .HasColumnType("bigint"); @@ -1024,16 +1026,19 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("OwnedBy") .HasColumnType("uuid"); + b.Property("OwnerId") + .HasColumnType("uuid"); + b.Property("TenantId") .HasColumnType("bigint"); b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("OrganisationId"); - b.HasIndex("OwnedBy"); + b.HasIndex("OwnerId"); b.HasIndex("TenantId"); @@ -1049,28 +1054,28 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("OwnedBy") .HasColumnType("uuid"); + b.Property("OwnerId") + .HasColumnType("uuid"); + b.Property("PortfolioId") .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("TenantId") .HasColumnType("bigint"); @@ -1083,9 +1088,9 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); - b.HasIndex("OwnedBy"); + b.HasIndex("OwnerId"); b.HasIndex("PortfolioId"); @@ -1103,46 +1108,37 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Description") - .IsRequired() - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); + .HasColumnType("text"); b.Property("EndedAt") .HasColumnType("timestamp with time zone"); b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("ProgrammeId") .HasColumnType("bigint"); b.Property("ProjectType") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("10"); + .HasColumnType("integer"); b.Property("Sector") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("11"); + .HasColumnType("integer"); b.Property("StartedAt") .HasColumnType("timestamp with time zone"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("TenantId") .HasColumnType("bigint"); @@ -1153,15 +1149,18 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("UpdatedBy") .HasColumnType("uuid"); + b.Property("UpdatorId") + .HasColumnType("uuid"); + b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProgrammeId"); b.HasIndex("TenantId"); - b.HasIndex("UpdatedBy"); + b.HasIndex("UpdatorId"); b.ToTable("Projects", (string)null); }); @@ -1175,42 +1174,40 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Description") - .IsRequired() - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); + .HasColumnType("text"); b.Property("Impact") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("Likelihood") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("3"); + .HasColumnType("integer"); b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("ProjectId") .HasColumnType("bigint"); + b.Property("TenantId") + .HasColumnType("bigint"); + b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProjectId"); + b.HasIndex("TenantId"); + b.ToTable("Risks", (string)null); }); @@ -1223,25 +1220,25 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("ProgrammeId") .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("2"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); @@ -1249,18 +1246,21 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("UpdatedBy") .HasColumnType("uuid"); + b.Property("UpdatorId") + .HasColumnType("uuid"); + b.Property("Version") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValue(1); + .HasColumnType("integer"); b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProgrammeId"); - b.HasIndex("UpdatedBy"); + b.HasIndex("TenantId"); + + b.HasIndex("UpdatorId"); b.ToTable("Rules", (string)null); }); @@ -1274,38 +1274,40 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Findings") - .HasMaxLength(4096) - .HasColumnType("character varying(4096)"); + .HasColumnType("text"); b.Property("InspectorName") - .IsRequired() .HasColumnType("text"); b.Property("ProjectId") .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("bigint"); b.Property("VisitedAt") .HasColumnType("timestamp with time zone"); b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("ProjectId"); + b.HasIndex("TenantId"); + b.ToTable("SiteVisits", (string)null); }); @@ -1318,22 +1320,19 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("Name") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); @@ -1341,11 +1340,14 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Property("UpdatedBy") .HasColumnType("uuid"); + b.Property("UpdatorId") + .HasColumnType("uuid"); + b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); - b.HasIndex("UpdatedBy"); + b.HasIndex("UpdatorId"); b.ToTable("Tenants", (string)null); }); @@ -1359,27 +1361,26 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); + b.Property("CreatorId") + .HasColumnType("uuid"); + b.Property("OrganisationId") .HasColumnType("bigint"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("TenantId") .HasColumnType("bigint"); b.HasKey("Id"); - b.HasIndex("CreatedBy"); + b.HasIndex("CreatorId"); b.HasIndex("OrganisationId"); @@ -1397,17 +1398,13 @@ namespace PostFundManagement.Infrastructure.Database.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("CreatedAt") - .ValueGeneratedOnAdd() - .HasColumnType("timestamp with time zone") - .HasDefaultValueSql("now()"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .HasColumnType("uuid"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("1"); + .HasColumnType("integer"); b.Property("TenantId") .HasColumnType("bigint"); @@ -1433,17 +1430,13 @@ namespace PostFundManagement.Infrastructure.Database.Migrations .HasColumnType("uuid"); b.Property("Email") - .IsRequired() - .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("text"); b.Property("LastLoginAt") .HasColumnType("timestamp with time zone"); b.Property("Status") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasDefaultValueSql("2"); + .HasColumnType("integer"); b.HasKey("Id"); @@ -1454,31 +1447,29 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Approver") .WithMany() - .HasForeignKey("ApprovedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("ApproverId"); b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Milestone", "Milestone") .WithMany() - .HasForeignKey("MilestoneId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); + .HasForeignKey("MilestoneId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() - .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .HasForeignKey("ProjectId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") .WithMany() - .HasForeignKey("UpdatedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("UpdatorId"); b.Navigation("Approver"); @@ -1488,6 +1479,8 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Navigation("Project"); + b.Navigation("Tenant"); + b.Navigation("Updator"); }); @@ -1495,42 +1488,37 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Approver") .WithMany() - .HasForeignKey("ApprovedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("ApproverId"); b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") .WithMany() .HasForeignKey("OrganisationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Programme", "Programme") .WithMany("Awards") .HasForeignKey("ProgrammeId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany("Awards") - .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.SetNull); + .HasForeignKey("ProjectId"); b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") .WithMany() .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") .WithMany() - .HasForeignKey("UpdatedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("UpdatorId"); b.Navigation("Approver"); @@ -1552,25 +1540,33 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "User") .WithMany() .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.NoAction) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); b.Navigation("Project"); + b.Navigation("Tenant"); + b.Navigation("User"); }); @@ -1578,19 +1574,22 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Approver") .WithMany() - .HasForeignKey("ApprovedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("ApproverId"); b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Approver"); @@ -1598,25 +1597,30 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Navigation("Creator"); b.Navigation("Project"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.ChangeRequest", b => { b.HasOne("PostFundManagement.Domain.Entities.User", "Approver") .WithMany() - .HasForeignKey("ApprovedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("ApproverId"); b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Approver"); @@ -1624,31 +1628,38 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Navigation("Creator"); b.Navigation("Project"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.ComplianceItem", b => { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Verifier") .WithMany() - .HasForeignKey("VerifiedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("VerifierId"); b.Navigation("Creator"); b.Navigation("Project"); + b.Navigation("Tenant"); + b.Navigation("Verifier"); }); @@ -1657,43 +1668,51 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasOne("PostFundManagement.Domain.Entities.Award", "Award") .WithOne("Contract") .HasForeignKey("PostFundManagement.Domain.Entities.Contract", "AwardId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) + .HasForeignKey("CreatorId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Award"); b.Navigation("Creator"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.Disbursement", b => { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Milestone", "Milestone") .WithMany() - .HasForeignKey("MilestoneId") - .OnDelete(DeleteBehavior.Restrict); + .HasForeignKey("MilestoneId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") .WithMany() - .HasForeignKey("UpdatedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("UpdatorId"); b.Navigation("Creator"); @@ -1701,6 +1720,8 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Navigation("Project"); + b.Navigation("Tenant"); + b.Navigation("Updator"); }); @@ -1709,37 +1730,40 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasOne("PostFundManagement.Domain.Entities.Activity", "Activity") .WithMany("Evidences") .HasForeignKey("ActivityId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Indicator", "Indicator") .WithMany() .HasForeignKey("IndicatorId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Milestone", "Milestone") .WithMany() .HasForeignKey("MilestoneId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") .WithMany() - .HasForeignKey("UpdatedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("UpdatorId"); b.Navigation("Activity"); @@ -1751,6 +1775,8 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Navigation("Project"); + b.Navigation("Tenant"); + b.Navigation("Updator"); }); @@ -1758,38 +1784,50 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); b.Navigation("Project"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.Instrument", b => { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Programme", "Programme") .WithMany("Instruments") .HasForeignKey("ProgrammeId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); b.Navigation("Programme"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.Invite", b => @@ -1797,31 +1835,35 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasOne("PostFundManagement.Domain.Entities.Award", "Award") .WithMany() .HasForeignKey("AwardId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Contract", "Contract") .WithMany() .HasForeignKey("ContractId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Organisation", "InvitedOrganisation") .WithMany() .HasForeignKey("InvitedOrganisationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") .WithMany() .HasForeignKey("OrganisationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "RecipientUser") .WithMany() - .HasForeignKey("Recipient") - .OnDelete(DeleteBehavior.Restrict) + .HasForeignKey("RecipientUserId"); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Award"); @@ -1833,26 +1875,30 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Navigation("Organisation"); b.Navigation("RecipientUser"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.Issue", b => { b.HasOne("PostFundManagement.Domain.Entities.User", "Assignee") .WithMany() - .HasForeignKey("AssignedTo") - .OnDelete(DeleteBehavior.SetNull) - .IsRequired(); + .HasForeignKey("AssigneeId"); b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Assignee"); @@ -1860,31 +1906,38 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.Navigation("Creator"); b.Navigation("Project"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.Milestone", b => { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") .WithMany() - .HasForeignKey("UpdatedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("UpdatorId"); b.Navigation("Creator"); b.Navigation("Project"); + b.Navigation("Tenant"); + b.Navigation("Updator"); }); @@ -1893,19 +1946,17 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") .WithMany() .HasForeignKey("OrganisationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "RecipientUser") .WithMany() - .HasForeignKey("Recipient") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); + .HasForeignKey("RecipientUserId"); b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") .WithMany() .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Organisation"); @@ -1919,9 +1970,7 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.Navigation("Creator"); }); @@ -1931,14 +1980,12 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasOne("PostFundManagement.Domain.Entities.Beneficiary", "Beneficiary") .WithMany() .HasForeignKey("BeneficiaryId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.Navigation("Beneficiary"); @@ -1949,26 +1996,22 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") .WithMany() .HasForeignKey("OrganisationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Owner") .WithMany() - .HasForeignKey("OwnedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("OwnerId"); b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") .WithMany() .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); @@ -1984,26 +2027,22 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.User", "Owner") .WithMany() - .HasForeignKey("OwnedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("OwnerId"); b.HasOne("PostFundManagement.Domain.Entities.Portfolio", "Portfolio") .WithMany("Programmes") .HasForeignKey("PortfolioId") - .OnDelete(DeleteBehavior.NoAction) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") .WithMany() .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.NoAction) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); @@ -2019,26 +2058,23 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Programme", "Programme") .WithMany("Projects") .HasForeignKey("ProgrammeId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") .WithMany() .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") .WithMany() - .HasForeignKey("UpdatedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("UpdatorId"); b.Navigation("Creator"); @@ -2053,44 +2089,55 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); b.Navigation("Project"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.Rule", b => { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Programme", "Programme") .WithMany("Rules") .HasForeignKey("ProgrammeId") - .OnDelete(DeleteBehavior.NoAction) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") .WithMany() - .HasForeignKey("UpdatedBy") - .OnDelete(DeleteBehavior.NoAction); + .HasForeignKey("UpdatorId"); b.Navigation("Creator"); b.Navigation("Programme"); + b.Navigation("Tenant"); + b.Navigation("Updator"); }); @@ -2098,33 +2145,36 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.NoAction) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Project", "Project") .WithMany() .HasForeignKey("ProjectId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); b.Navigation("Project"); + + b.Navigation("Tenant"); }); modelBuilder.Entity("PostFundManagement.Domain.Entities.Tenant", b => { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.User", "Updator") .WithMany() - .HasForeignKey("UpdatedBy") - .OnDelete(DeleteBehavior.Restrict); + .HasForeignKey("UpdatorId"); b.Navigation("Creator"); @@ -2135,20 +2185,18 @@ namespace PostFundManagement.Infrastructure.Database.Migrations { b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() - .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); + .HasForeignKey("CreatorId"); b.HasOne("PostFundManagement.Domain.Entities.Organisation", "Organisation") .WithMany() .HasForeignKey("OrganisationId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") .WithMany() .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); @@ -2163,19 +2211,19 @@ namespace PostFundManagement.Infrastructure.Database.Migrations b.HasOne("PostFundManagement.Domain.Entities.User", "Creator") .WithMany() .HasForeignKey("CreatedBy") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.Tenant", "Tenant") .WithMany() .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PostFundManagement.Domain.Entities.User", "User") .WithMany() .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) + .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Creator"); diff --git a/PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj b/PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj index de366dd..ebbf430 100644 --- a/PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj +++ b/PostFundManagement.Infrastructure/PostFundManagement.Infrastructure.csproj @@ -26,6 +26,7 @@ +