using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace HyperBooru.Migrations { /// public partial class UploadedFilesToObjects : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "Guid", table: "UploadedFiles", type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"); migrationBuilder.Sql( "INSERT INTO \"Objects\" (\"Guid\") SELECT \"Guid\" FROM \"UploadedFiles\";"); migrationBuilder.Sql( "UPDATE \"UploadedFiles\" AS uf SET \"UploadedFileId\" = o.\"ObjectId\" FROM \"Objects\" AS o WHERE o.\"Guid\" = uf.\"Guid\";"); migrationBuilder.DropColumn( name: "Guid", table: "UploadedFiles"); migrationBuilder.RenameColumn( name: "UploadedFileId", table: "UploadedFiles", newName: "ObjectId"); migrationBuilder.AlterColumn( name: "ObjectId", table: "UploadedFiles", type: "integer", nullable: false, oldClrType: typeof(int), oldType: "integer") .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); migrationBuilder.AddForeignKey( name: "FK_UploadedFiles_Objects_ObjectId", table: "UploadedFiles", column: "ObjectId", principalTable: "Objects", principalColumn: "ObjectId", onDelete: ReferentialAction.Cascade); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_UploadedFiles_Objects_ObjectId", table: "UploadedFiles"); migrationBuilder.RenameColumn( name: "ObjectId", table: "UploadedFiles", newName: "UploadedFileId"); migrationBuilder.AlterColumn( name: "UploadedFileId", table: "UploadedFiles", type: "integer", nullable: false, oldClrType: typeof(int), oldType: "integer") .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); } } }