using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace ROLAC.API.Migrations { /// public partial class AddNotifications : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "LineBindingCodes", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Code = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), MemberId = table.Column(type: "integer", nullable: false), ExpiresAt = table.Column(type: "timestamp with time zone", nullable: false), ConsumedAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_LineBindingCodes", x => x.Id); table.ForeignKey( name: "FK_LineBindingCodes_Members_MemberId", column: x => x.MemberId, principalTable: "Members", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MemberChannelBindings", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), MemberId = table.Column(type: "integer", nullable: false), Channel = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), ExternalId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), BoundAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_MemberChannelBindings", x => x.Id); table.ForeignKey( name: "FK_MemberChannelBindings_Members_MemberId", column: x => x.MemberId, principalTable: "Members", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MessagingGroups", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Channel = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), ExternalId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), IsActive = table.Column(type: "boolean", nullable: false), RegisteredAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_MessagingGroups", x => x.Id); }); migrationBuilder.CreateTable( name: "NotificationLogs", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Channel = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), TargetType = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), TargetExternalId = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Subject = table.Column(type: "character varying(300)", maxLength: 300, nullable: true), MemberId = table.Column(type: "integer", nullable: true), MessagingGroupId = table.Column(type: "integer", nullable: true), Body = table.Column(type: "text", nullable: false), Status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), Error = table.Column(type: "text", nullable: true), SentByUserId = table.Column(type: "character varying(450)", maxLength: 450, nullable: false), SentAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_NotificationLogs", x => x.Id); table.ForeignKey( name: "FK_NotificationLogs_Members_MemberId", column: x => x.MemberId, principalTable: "Members", principalColumn: "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "FK_NotificationLogs_MessagingGroups_MessagingGroupId", column: x => x.MessagingGroupId, principalTable: "MessagingGroups", principalColumn: "Id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateIndex( name: "IX_LineBindingCodes_Code", table: "LineBindingCodes", column: "Code"); migrationBuilder.CreateIndex( name: "IX_LineBindingCodes_MemberId", table: "LineBindingCodes", column: "MemberId"); migrationBuilder.CreateIndex( name: "IX_MemberChannelBindings_Channel_ExternalId", table: "MemberChannelBindings", columns: new[] { "Channel", "ExternalId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_MemberChannelBindings_MemberId_Channel", table: "MemberChannelBindings", columns: new[] { "MemberId", "Channel" }, unique: true); migrationBuilder.CreateIndex( name: "IX_MessagingGroups_Channel_ExternalId", table: "MessagingGroups", columns: new[] { "Channel", "ExternalId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_NotificationLogs_Channel", table: "NotificationLogs", column: "Channel"); migrationBuilder.CreateIndex( name: "IX_NotificationLogs_MemberId", table: "NotificationLogs", column: "MemberId"); migrationBuilder.CreateIndex( name: "IX_NotificationLogs_MessagingGroupId", table: "NotificationLogs", column: "MessagingGroupId"); migrationBuilder.CreateIndex( name: "IX_NotificationLogs_SentAt", table: "NotificationLogs", column: "SentAt"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "LineBindingCodes"); migrationBuilder.DropTable( name: "MemberChannelBindings"); migrationBuilder.DropTable( name: "NotificationLogs"); migrationBuilder.DropTable( name: "MessagingGroups"); } } }