using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace ManagerService.Migrations { /// public partial class AddDateUpdateAudit : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "DateUpdate", table: "Users", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateUpdate", table: "Sections", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateUpdate", table: "Resources", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateUpdate", table: "Instances", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateCreation", table: "GuidedPaths", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateUpdate", table: "GuidedPaths", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateUpdate", table: "Configurations", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateCreation", table: "ApplicationInstances", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateUpdate", table: "ApplicationInstances", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateCreation", table: "AppConfigurationLinks", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateUpdate", table: "AppConfigurationLinks", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); migrationBuilder.AddColumn( name: "DateUpdate", table: "ApiKeys", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); // Backfill : pour les lignes existantes, DateUpdate reprend la DateCreation connue. migrationBuilder.Sql("UPDATE \"Users\" SET \"DateUpdate\" = \"DateCreation\";"); migrationBuilder.Sql("UPDATE \"Sections\" SET \"DateUpdate\" = \"DateCreation\";"); migrationBuilder.Sql("UPDATE \"Resources\" SET \"DateUpdate\" = \"DateCreation\";"); migrationBuilder.Sql("UPDATE \"Instances\" SET \"DateUpdate\" = \"DateCreation\";"); migrationBuilder.Sql("UPDATE \"Configurations\" SET \"DateUpdate\" = \"DateCreation\";"); migrationBuilder.Sql("UPDATE \"ApiKeys\" SET \"DateUpdate\" = \"DateCreation\";"); // GuidedPaths/ApplicationInstances/AppConfigurationLinks n'avaient aucune date avant cette migration : // on ne peut pas reconstituer la vraie date de création, donc on initialise les deux au moment du backfill. migrationBuilder.Sql("UPDATE \"GuidedPaths\" SET \"DateCreation\" = now(), \"DateUpdate\" = now();"); migrationBuilder.Sql("UPDATE \"ApplicationInstances\" SET \"DateCreation\" = now(), \"DateUpdate\" = now();"); migrationBuilder.Sql("UPDATE \"AppConfigurationLinks\" SET \"DateCreation\" = now(), \"DateUpdate\" = now();"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropColumn( name: "DateUpdate", table: "Users"); migrationBuilder.DropColumn( name: "DateUpdate", table: "Sections"); migrationBuilder.DropColumn( name: "DateUpdate", table: "Resources"); migrationBuilder.DropColumn( name: "DateUpdate", table: "Instances"); migrationBuilder.DropColumn( name: "DateCreation", table: "GuidedPaths"); migrationBuilder.DropColumn( name: "DateUpdate", table: "GuidedPaths"); migrationBuilder.DropColumn( name: "DateUpdate", table: "Configurations"); migrationBuilder.DropColumn( name: "DateCreation", table: "ApplicationInstances"); migrationBuilder.DropColumn( name: "DateUpdate", table: "ApplicationInstances"); migrationBuilder.DropColumn( name: "DateCreation", table: "AppConfigurationLinks"); migrationBuilder.DropColumn( name: "DateUpdate", table: "AppConfigurationLinks"); migrationBuilder.DropColumn( name: "DateUpdate", table: "ApiKeys"); } } }