using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Musify.Infrastructure.Persistence.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "InboxState", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), MessageId = table.Column(type: "uuid", nullable: false), ConsumerId = table.Column(type: "uuid", nullable: false), LockId = table.Column(type: "uuid", nullable: false), RowVersion = table.Column(type: "bytea", rowVersion: true, nullable: true), Received = table.Column(type: "timestamp with time zone", nullable: false), ReceiveCount = table.Column(type: "integer", nullable: false), ExpirationTime = table.Column(type: "timestamp with time zone", nullable: true), Consumed = table.Column(type: "timestamp with time zone", nullable: true), Delivered = table.Column(type: "timestamp with time zone", nullable: true), LastSequenceNumber = table.Column(type: "bigint", nullable: true) }, constraints: table => { table.PrimaryKey("PK_InboxState", x => x.Id); table.UniqueConstraint("AK_InboxState_MessageId_ConsumerId", x => new { x.MessageId, x.ConsumerId }); }); migrationBuilder.CreateTable( name: "OutboxState", columns: table => new { OutboxId = table.Column(type: "uuid", nullable: false), LockId = table.Column(type: "uuid", nullable: false), RowVersion = table.Column(type: "bytea", rowVersion: true, nullable: true), Created = table.Column(type: "timestamp with time zone", nullable: false), Delivered = table.Column(type: "timestamp with time zone", nullable: true), LastSequenceNumber = table.Column(type: "bigint", nullable: true) }, constraints: table => { table.PrimaryKey("PK_OutboxState", x => x.OutboxId); }); migrationBuilder.CreateTable( name: "Tracks", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Title = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), NormalizedTitle = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), OriginalPictureName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), SmallPictureName = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), MediumPictureName = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), LargePictureName = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), OriginalAudioName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), AudioFolderName = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), PicturesProcessingStatus = table.Column(type: "integer", nullable: false), AudioTranscodeProcessingStatus = table.Column(type: "integer", nullable: false), LifeCycleStatus = table.Column(type: "integer", nullable: false), RetryCount = table.Column(type: "integer", nullable: false), LastRetryAt = table.Column(type: "timestamp with time zone", nullable: true), CreatedDate = table.Column(type: "timestamp with time zone", nullable: false), UpdatedDate = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tracks", x => x.Id); }); migrationBuilder.CreateTable( name: "Upload", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Bucket = table.Column(type: "text", nullable: false), Key = table.Column(type: "text", nullable: false), ContentType = table.Column(type: "text", nullable: false), CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), State = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Upload", x => x.Id); }); migrationBuilder.CreateTable( name: "User", columns: table => new { Id = table.Column(type: "bigint", nullable: false), Name = table.Column(type: "character varying(48)", maxLength: 48, nullable: false), NormalizedName = table.Column(type: "character varying(48)", maxLength: 48, nullable: false), FirstName = table.Column(type: "character varying(48)", maxLength: 48, nullable: true), SecondName = table.Column(type: "character varying(48)", maxLength: 48, nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_User", x => x.Id); }); migrationBuilder.CreateTable( name: "OutboxMessage", columns: table => new { SequenceNumber = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), EnqueueTime = table.Column(type: "timestamp with time zone", nullable: true), SentTime = table.Column(type: "timestamp with time zone", nullable: false), Headers = table.Column(type: "text", nullable: true), Properties = table.Column(type: "text", nullable: true), InboxMessageId = table.Column(type: "uuid", nullable: true), InboxConsumerId = table.Column(type: "uuid", nullable: true), OutboxId = table.Column(type: "uuid", nullable: true), MessageId = table.Column(type: "uuid", nullable: false), ContentType = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), MessageType = table.Column(type: "text", nullable: false), Body = table.Column(type: "text", nullable: false), ConversationId = table.Column(type: "uuid", nullable: true), CorrelationId = table.Column(type: "uuid", nullable: true), InitiatorId = table.Column(type: "uuid", nullable: true), RequestId = table.Column(type: "uuid", nullable: true), SourceAddress = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), DestinationAddress = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), ResponseAddress = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), FaultAddress = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), ExpirationTime = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_OutboxMessage", x => x.SequenceNumber); table.ForeignKey( name: "FK_OutboxMessage_InboxState_InboxMessageId_InboxConsumerId", columns: x => new { x.InboxMessageId, x.InboxConsumerId }, principalTable: "InboxState", principalColumns: new[] { "MessageId", "ConsumerId" }); table.ForeignKey( name: "FK_OutboxMessage_OutboxState_OutboxId", column: x => x.OutboxId, principalTable: "OutboxState", principalColumn: "OutboxId"); }); migrationBuilder.CreateTable( name: "PlayLists", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "bigint", nullable: false), Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), NormalizedName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), Description = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), OriginalPictureName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), SmallPictureName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), MediumPictureName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), LargePictureName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), LifeCycleStatus = table.Column(type: "integer", nullable: false), CreatedDate = table.Column(type: "timestamp with time zone", nullable: false), UpdatedDate = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PlayLists", x => x.Id); table.ForeignKey( name: "FK_PlayLists_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UploadIntents", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "bigint", nullable: false), Bucket = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), Key = table.Column(type: "character varying(512)", maxLength: 512, nullable: false), ObjectName = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), ContentType = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), ExpectedSizeBytes = table.Column(type: "bigint", nullable: true), Purpose = table.Column(type: "integer", nullable: false), Status = table.Column(type: "integer", nullable: false), ExpiresAt = table.Column(type: "timestamp with time zone", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UploadIntents", x => x.Id); table.ForeignKey( name: "FK_UploadIntents_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserHasTrack", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "bigint", nullable: false), TrackId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserHasTrack", x => x.Id); table.ForeignKey( name: "FK_UserHasTrack_Tracks_TrackId", column: x => x.TrackId, principalTable: "Tracks", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserHasTrack_User_UserId", column: x => x.UserId, principalTable: "User", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "PlayListHasTrack", columns: table => new { Id = table.Column(type: "uuid", nullable: false), PlayListId = table.Column(type: "uuid", nullable: false), TrackId = table.Column(type: "uuid", nullable: false), Position = table.Column(type: "integer", nullable: false), AddedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PlayListHasTrack", x => x.Id); table.ForeignKey( name: "FK_PlayListHasTrack_PlayLists_PlayListId", column: x => x.PlayListId, principalTable: "PlayLists", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PlayListHasTrack_Tracks_TrackId", column: x => x.TrackId, principalTable: "Tracks", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_InboxState_Delivered", table: "InboxState", column: "Delivered"); migrationBuilder.CreateIndex( name: "IX_OutboxMessage_EnqueueTime", table: "OutboxMessage", column: "EnqueueTime"); migrationBuilder.CreateIndex( name: "IX_OutboxMessage_ExpirationTime", table: "OutboxMessage", column: "ExpirationTime"); migrationBuilder.CreateIndex( name: "IX_OutboxMessage_InboxMessageId_InboxConsumerId_SequenceNumber", table: "OutboxMessage", columns: new[] { "InboxMessageId", "InboxConsumerId", "SequenceNumber" }, unique: true); migrationBuilder.CreateIndex( name: "IX_OutboxMessage_OutboxId_SequenceNumber", table: "OutboxMessage", columns: new[] { "OutboxId", "SequenceNumber" }, unique: true); migrationBuilder.CreateIndex( name: "IX_OutboxState_Created", table: "OutboxState", column: "Created"); migrationBuilder.CreateIndex( name: "IX_PlayListHasTrack_PlayListId", table: "PlayListHasTrack", column: "PlayListId"); migrationBuilder.CreateIndex( name: "IX_PlayListHasTrack_TrackId", table: "PlayListHasTrack", column: "TrackId"); migrationBuilder.CreateIndex( name: "IX_PlayLists_UserId", table: "PlayLists", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_UploadIntents_UserId", table: "UploadIntents", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_UserHasTrack_TrackId", table: "UserHasTrack", column: "TrackId"); migrationBuilder.CreateIndex( name: "IX_UserHasTrack_UserId", table: "UserHasTrack", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "OutboxMessage"); migrationBuilder.DropTable( name: "PlayListHasTrack"); migrationBuilder.DropTable( name: "Upload"); migrationBuilder.DropTable( name: "UploadIntents"); migrationBuilder.DropTable( name: "UserHasTrack"); migrationBuilder.DropTable( name: "InboxState"); migrationBuilder.DropTable( name: "OutboxState"); migrationBuilder.DropTable( name: "PlayLists"); migrationBuilder.DropTable( name: "Tracks"); migrationBuilder.DropTable( name: "User"); } } }