aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Migrations/20200221064341_AddJwtToken.cs
blob: 628970c639e4b34d71421a0ab6aa0ff6d6e401c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Security.Cryptography;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Timeline.Migrations
{
    public static class JwtTokenGenerateHelper
    {
        public static byte[] GenerateKey()
        {
            using var random = RandomNumberGenerator.Create();
            var key = new byte[16];
            random.GetBytes(key);
            return key;
        }
    }

    public partial class AddJwtToken : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "jwt_token",
                columns: table => new
                {
                    id = table.Column<long>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    key = table.Column<byte[]>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_jwt_token", x => x.id);
                });


            migrationBuilder.InsertData("jwt_token", "key", JwtTokenGenerateHelper.GenerateKey());
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "jwt_token");
        }
    }
}