166 lines
6.6 KiB
C#
166 lines
6.6 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace ManagerService.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddDateUpdateAudit : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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<DateTime>(
|
|
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();");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
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");
|
|
}
|
|
}
|
|
}
|