using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace PlaylistShared.Api.Data.Migrations { /// public partial class AddUserSessionsAndLogging : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterColumn( name: "AddedByUserId", table: "TrackAdditionLogs", type: "uniqueidentifier", nullable: true, oldClrType: typeof(Guid), oldType: "uniqueidentifier"); migrationBuilder.AddColumn( name: "SessionId", table: "TrackAdditionLogs", type: "nvarchar(449)", nullable: false, defaultValue: ""); migrationBuilder.CreateTable( name: "UserSessions", columns: table => new { SessionId = table.Column(type: "nvarchar(449)", maxLength: 449, nullable: false), ClientIpAddress = table.Column(type: "nvarchar(max)", nullable: true), UserAgent = table.Column(type: "nvarchar(max)", nullable: true), FirstSeenUtc = table.Column(type: "datetime2", nullable: false), LastSeenUtc = table.Column(type: "datetime2", nullable: false), AssociatedUserId = table.Column(type: "uniqueidentifier", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserSessions", x => x.SessionId); table.ForeignKey( name: "FK_UserSessions_AspNetUsers_AssociatedUserId", column: x => x.AssociatedUserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "TrackRemovalLogs", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), SharedPlaylistId = table.Column(type: "uniqueidentifier", nullable: false), TrackId = table.Column(type: "nvarchar(450)", nullable: false), RemovedByUserId = table.Column(type: "uniqueidentifier", nullable: true), RemovedAtUtc = table.Column(type: "datetime2", nullable: false), SessionId = table.Column(type: "nvarchar(449)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_TrackRemovalLogs", x => x.Id); table.ForeignKey( name: "FK_TrackRemovalLogs_AspNetUsers_RemovedByUserId", column: x => x.RemovedByUserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_TrackRemovalLogs_SharedPlaylists_SharedPlaylistId", column: x => x.SharedPlaylistId, principalTable: "SharedPlaylists", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_TrackRemovalLogs_UserSessions_SessionId", column: x => x.SessionId, principalTable: "UserSessions", principalColumn: "SessionId", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_TrackAdditionLogs_SessionId", table: "TrackAdditionLogs", column: "SessionId"); migrationBuilder.CreateIndex( name: "IX_TrackRemovalLogs_RemovedByUserId", table: "TrackRemovalLogs", column: "RemovedByUserId"); migrationBuilder.CreateIndex( name: "IX_TrackRemovalLogs_SessionId", table: "TrackRemovalLogs", column: "SessionId"); migrationBuilder.CreateIndex( name: "IX_TrackRemovalLogs_SharedPlaylistId_TrackId", table: "TrackRemovalLogs", columns: new[] { "SharedPlaylistId", "TrackId" }); migrationBuilder.CreateIndex( name: "IX_UserSessions_AssociatedUserId", table: "UserSessions", column: "AssociatedUserId"); migrationBuilder.AddForeignKey( name: "FK_TrackAdditionLogs_UserSessions_SessionId", table: "TrackAdditionLogs", column: "SessionId", principalTable: "UserSessions", principalColumn: "SessionId", onDelete: ReferentialAction.Restrict); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_TrackAdditionLogs_UserSessions_SessionId", table: "TrackAdditionLogs"); migrationBuilder.DropTable( name: "TrackRemovalLogs"); migrationBuilder.DropTable( name: "UserSessions"); migrationBuilder.DropIndex( name: "IX_TrackAdditionLogs_SessionId", table: "TrackAdditionLogs"); migrationBuilder.DropColumn( name: "SessionId", table: "TrackAdditionLogs"); migrationBuilder.AlterColumn( name: "AddedByUserId", table: "TrackAdditionLogs", type: "uniqueidentifier", nullable: false, defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), oldClrType: typeof(Guid), oldType: "uniqueidentifier", oldNullable: true); } } }