Migration202005151300ExtendUser.cs 3.25 KB
Newer Older
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using FluentMigrator;
namespace Coscine.Database.Migration.Migrations
{
    //yyyymmddhhmm
    [Migration(202005151300)]
    public class Migration202005151300ExtendUser : FluentMigrator.Migration
    {
        public override void Down()
        {
            #region Foreign Keys
            Delete.ForeignKey()
                .FromTable("Users").ForeignColumn("TitleId")
                .ToTable("Titles").PrimaryColumn("Id");

            Delete.ForeignKey()
                .FromTable("Users").ForeignColumn("LanguageId")
                .ToTable("Languages").PrimaryColumn("Id");

            Delete.ForeignKey()
                .FromTable("UserDisciplines").ForeignColumn("DisciplineId")
                .ToTable("Disciplines").PrimaryColumn("Id");
            Delete.ForeignKey()
                .FromTable("UserDisciplines").ForeignColumn("UserId")
                .ToTable("Users").PrimaryColumn("Id");
            #endregion

            Delete.Column("TitleId").FromTable("Users");
            Delete.Column("LanguageId").FromTable("Users");
            Delete.Column("Institute").FromTable("Users");

            Delete.Table("Titles");
            Delete.Table("Languages");
            Delete.Table("UserDisciplines");
        }

        public override void Up()
        {
            Create.Table("Titles")
                .WithColumn("Id").AsGuid().PrimaryKey().WithDefault(SystemMethods.NewGuid)
                .WithColumn("DisplayName").AsString(50).NotNullable();

            Insert.IntoTable("Titles").Row(new { DisplayName = "Prof." });
            Insert.IntoTable("Titles").Row(new { DisplayName = "Dr." });

            Create.Table("Languages")
                .WithColumn("Id").AsGuid().PrimaryKey().WithDefault(SystemMethods.NewGuid)
                .WithColumn("DisplayName").AsString(50).NotNullable()
                .WithColumn("Abbreviation").AsString(50).NotNullable();

            Insert.IntoTable("Languages").Row(new { DisplayName = "English", Abbreviation = "en" });
            Insert.IntoTable("Languages").Row(new { DisplayName = "Deutsch", Abbreviation = "de" });

            Create.Table("UserDisciplines")
                .WithColumn("RelationId").AsGuid().PrimaryKey().WithDefault(SystemMethods.NewGuid)
                .WithColumn("DisciplineId").AsGuid().NotNullable()
                .WithColumn("UserId").AsGuid().NotNullable();

            Alter.Table("Users").AddColumn("TitleId").AsGuid().Nullable();
            Alter.Table("Users").AddColumn("LanguageId").AsGuid().Nullable();
            Alter.Table("Users").AddColumn("Institute").AsString(200).Nullable();

            #region Foreign Keys
            Create.ForeignKey()
                .FromTable("Users").ForeignColumn("TitleId")
                .ToTable("Titles").PrimaryColumn("Id");

            Create.ForeignKey()
                .FromTable("Users").ForeignColumn("LanguageId")
                .ToTable("Languages").PrimaryColumn("Id");

            Create.ForeignKey()
                .FromTable("UserDisciplines").ForeignColumn("DisciplineId")
                .ToTable("Disciplines").PrimaryColumn("Id");
            Create.ForeignKey()
                .FromTable("UserDisciplines").ForeignColumn("UserId")
                .ToTable("Users").PrimaryColumn("Id");
            #endregion
        }
    }
}