Migration202010271100ApiTokens.cs 881 Bytes
Newer Older
L. Ellenbeck's avatar
L. Ellenbeck committed
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
using FluentMigrator;

namespace Coscine.Migrations.Migrations
{
    //yyyymmddhhmm
    [Migration(202010271100)]
    public class Migration202010271100ApiTokens : Migration
    {
        public override void Down()
        {
            Delete.Table("ApiTokens");
        }

        public override void Up()
        {
            Create.Table("ApiTokens")
                .WithColumn("Id").AsGuid().PrimaryKey().WithDefault(SystemMethods.NewGuid)
                .WithColumn("Name").AsString().NotNullable()
                .WithColumn("UserId").AsGuid().NotNullable()
                .WithColumn("IssuedAt").AsDateTime().NotNullable()
                .WithColumn("Expiration").AsDateTime().NotNullable();

            Create.ForeignKey()
                .FromTable("ApiTokens").ForeignColumn("UserId")
                .ToTable("Users").PrimaryColumn("Id");
        }
    }
}