using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace PostFundManagement.Infrastructure.Database.Migrations { /// public partial class AddedActivityNotification : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Evidences_Indicators_IndicatorId", table: "Evidences"); migrationBuilder.DropForeignKey( name: "FK_Programmes_Instruments_InstrumentId", table: "Programmes"); migrationBuilder.DropForeignKey( name: "FK_Projects_Programmes_ProgrammeId", table: "Projects"); migrationBuilder.DropIndex( name: "IX_Programmes_InstrumentId", table: "Programmes"); migrationBuilder.DropColumn( name: "InstrumentId", table: "Programmes"); migrationBuilder.AddColumn( name: "ProjectType", table: "Projects", type: "integer", nullable: false, defaultValueSql: "10"); migrationBuilder.AddColumn( name: "Sector", table: "Projects", type: "integer", nullable: false, defaultValueSql: "11"); migrationBuilder.AddColumn( name: "Priority", table: "Milestones", type: "integer", nullable: false, defaultValueSql: "1"); migrationBuilder.AddColumn( name: "AssignedTo", table: "Issues", type: "uuid", nullable: true); migrationBuilder.AddColumn( name: "Resolution", table: "Issues", type: "text", nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "ProgrammeId", table: "Instruments", type: "bigint", nullable: false, defaultValue: 0L); migrationBuilder.AddColumn( name: "ActivityId", table: "Evidences", type: "bigint", nullable: false, defaultValue: 0L); migrationBuilder.AddColumn( name: "Type", table: "Evidences", type: "integer", nullable: false, defaultValueSql: "9"); migrationBuilder.CreateTable( name: "Activities", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ProjectId = table.Column(type: "bigint", nullable: false), MilestoneId = table.Column(type: "bigint", nullable: false), CreatedBy = table.Column(type: "uuid", nullable: false), UpdatedBy = table.Column(type: "uuid", nullable: true), ApprovedBy = table.Column(type: "uuid", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), Category = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Status = table.Column(type: "integer", nullable: false, defaultValueSql: "1"), Amount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), Title = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Description = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false), PerformedAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Activities", x => x.Id); table.ForeignKey( name: "FK_Activities_Milestones_MilestoneId", column: x => x.MilestoneId, principalTable: "Milestones", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Activities_Projects_ProjectId", column: x => x.ProjectId, principalTable: "Projects", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Activities_Users_ApprovedBy", column: x => x.ApprovedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_Activities_Users_CreatedBy", column: x => x.CreatedBy, principalTable: "Users", principalColumn: "Id"); table.ForeignKey( name: "FK_Activities_Users_UpdatedBy", column: x => x.UpdatedBy, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Invites", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), OrganisationId = table.Column(type: "bigint", nullable: false), InvitedOrganisationId = table.Column(type: "bigint", nullable: false), AwardId = table.Column(type: "bigint", nullable: false), ContractId = table.Column(type: "bigint", nullable: false), Recipient = table.Column(type: "uuid", nullable: false), CreatedBy = table.Column(type: "uuid", nullable: false), UpdatedBy = table.Column(type: "uuid", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Invites", x => x.Id); table.ForeignKey( name: "FK_Invites_Awards_AwardId", column: x => x.AwardId, principalTable: "Awards", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Invites_Contracts_ContractId", column: x => x.ContractId, principalTable: "Contracts", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Invites_Organisations_InvitedOrganisationId", column: x => x.InvitedOrganisationId, principalTable: "Organisations", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Invites_Organisations_OrganisationId", column: x => x.OrganisationId, principalTable: "Organisations", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Invites_Users_Recipient", column: x => x.Recipient, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Notifications", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), OrganisationId = table.Column(type: "bigint", nullable: false), Recipient = table.Column(type: "uuid", nullable: false), Platform = table.Column(type: "integer", nullable: false, defaultValueSql: "1"), Status = table.Column(type: "integer", nullable: false, defaultValueSql: "1"), Subject = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), Message = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: false), Destination = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), SentAt = table.Column(type: "timestamp with time zone", nullable: true), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), Error = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Notifications", x => x.Id); table.ForeignKey( name: "FK_Notifications_Organisations_OrganisationId", column: x => x.OrganisationId, principalTable: "Organisations", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Notifications_Users_Recipient", column: x => x.Recipient, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_Issues_AssignedTo", table: "Issues", column: "AssignedTo"); migrationBuilder.CreateIndex( name: "IX_Instruments_ProgrammeId", table: "Instruments", column: "ProgrammeId"); migrationBuilder.CreateIndex( name: "IX_Evidences_ActivityId", table: "Evidences", column: "ActivityId"); 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_MilestoneId", table: "Activities", column: "MilestoneId"); migrationBuilder.CreateIndex( name: "IX_Activities_ProjectId", table: "Activities", column: "ProjectId"); migrationBuilder.CreateIndex( name: "IX_Activities_UpdatedBy", table: "Activities", column: "UpdatedBy"); migrationBuilder.CreateIndex( name: "IX_Invites_AwardId", table: "Invites", column: "AwardId"); migrationBuilder.CreateIndex( name: "IX_Invites_ContractId", table: "Invites", column: "ContractId"); migrationBuilder.CreateIndex( name: "IX_Invites_InvitedOrganisationId", table: "Invites", column: "InvitedOrganisationId"); migrationBuilder.CreateIndex( name: "IX_Invites_OrganisationId", table: "Invites", column: "OrganisationId"); migrationBuilder.CreateIndex( name: "IX_Invites_Recipient", table: "Invites", column: "Recipient"); migrationBuilder.CreateIndex( name: "IX_Notifications_OrganisationId", table: "Notifications", column: "OrganisationId"); migrationBuilder.CreateIndex( name: "IX_Notifications_Recipient", table: "Notifications", column: "Recipient"); 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_Instruments_Programmes_ProgrammeId", table: "Instruments", column: "ProgrammeId", principalTable: "Programmes", 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_Projects_Programmes_ProgrammeId", table: "Projects", column: "ProgrammeId", principalTable: "Programmes", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Evidences_Activities_ActivityId", table: "Evidences"); migrationBuilder.DropForeignKey( name: "FK_Evidences_Indicators_IndicatorId", table: "Evidences"); migrationBuilder.DropForeignKey( name: "FK_Instruments_Programmes_ProgrammeId", table: "Instruments"); migrationBuilder.DropForeignKey( name: "FK_Issues_Users_AssignedTo", table: "Issues"); migrationBuilder.DropForeignKey( name: "FK_Projects_Programmes_ProgrammeId", table: "Projects"); migrationBuilder.DropTable( name: "Activities"); migrationBuilder.DropTable( name: "Invites"); migrationBuilder.DropTable( name: "Notifications"); migrationBuilder.DropIndex( name: "IX_Issues_AssignedTo", table: "Issues"); migrationBuilder.DropIndex( name: "IX_Instruments_ProgrammeId", table: "Instruments"); migrationBuilder.DropIndex( name: "IX_Evidences_ActivityId", table: "Evidences"); migrationBuilder.DropColumn( name: "ProjectType", table: "Projects"); migrationBuilder.DropColumn( name: "Sector", table: "Projects"); migrationBuilder.DropColumn( name: "Priority", table: "Milestones"); migrationBuilder.DropColumn( name: "AssignedTo", table: "Issues"); migrationBuilder.DropColumn( name: "Resolution", table: "Issues"); migrationBuilder.DropColumn( name: "ProgrammeId", table: "Instruments"); migrationBuilder.DropColumn( name: "ActivityId", table: "Evidences"); migrationBuilder.DropColumn( name: "Type", table: "Evidences"); migrationBuilder.AddColumn( name: "InstrumentId", table: "Programmes", type: "bigint", nullable: false, defaultValue: 0L); migrationBuilder.CreateIndex( name: "IX_Programmes_InstrumentId", table: "Programmes", column: "InstrumentId"); migrationBuilder.AddForeignKey( name: "FK_Evidences_Indicators_IndicatorId", table: "Evidences", column: "IndicatorId", principalTable: "Indicators", principalColumn: "Id", onDelete: ReferentialAction.Cascade); migrationBuilder.AddForeignKey( name: "FK_Programmes_Instruments_InstrumentId", table: "Programmes", column: "InstrumentId", principalTable: "Instruments", principalColumn: "Id"); migrationBuilder.AddForeignKey( name: "FK_Projects_Programmes_ProgrammeId", table: "Projects", column: "ProgrammeId", principalTable: "Programmes", principalColumn: "Id"); } } }