// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AliasServerDb.Migrations
{
    /// <inheritdoc />
    public partial class AddMetadataColumns : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "FileSize",
                table: "Vaults",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<DateTime>(
                name: "CreatedAt",
                table: "AliasVaultUsers",
                type: "TEXT",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<DateTime>(
                name: "UpdatedAt",
                table: "AliasVaultUsers",
                type: "TEXT",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            // Update all existing users to have the CreatedAt and UpdatedAt set to "now".
            if (migrationBuilder.IsSqlite())
            {
                migrationBuilder.Sql("UPDATE AliasVaultUsers SET CreatedAt = datetime('now'), UpdatedAt = datetime('now')");
            }
            else
            {
                migrationBuilder.Sql("UPDATE AliasVaultUsers SET CreatedAt = GETUTCDATE(), UpdatedAt = GETUTCDATE()");
            }
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "FileSize",
                table: "Vaults");

            migrationBuilder.DropColumn(
                name: "CreatedAt",
                table: "AliasVaultUsers");

            migrationBuilder.DropColumn(
                name: "UpdatedAt",
                table: "AliasVaultUsers");
        }
    }
}
