-
Notifications
You must be signed in to change notification settings - Fork 3
/
MigrationsWithIncorrectColumnTypes.cs
171 lines (154 loc) · 8.89 KB
/
MigrationsWithIncorrectColumnTypes.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Data;
using Aranasoft.Cobweb.FluentMigrator.Extensions;
using FluentMigrator;
using FluentMigrator.SqlServer;
namespace Aranasoft.Cobweb.EntityFrameworkCore.Validation.Tests.Support.Migrations
{
[Migration(12345, "Add Identity Tables")]
public class MigrationsWithIncorrectColumnTypes : Migration
{
public override void Up()
{
Create.Table("AspNetRoles")
.WithColumn("Id", col => col.AsInt32().NotNullable().PrimaryKey("PK_AspNetRoles"))
.WithColumn("ConcurrencyStamp", col => col.AsInt32().Nullable())
.WithColumn("Name", col => col.AsInt32().Nullable())
.WithColumn("NormalizedName", col => col.AsInt32().Nullable())
;
Create.Index("RoleNameIndex").OnTable("AspNetRoles")
.OnColumn("NormalizedName", col => col.Unique().NullsNotDistinct())
;
IfDatabase(dbType => string.Equals(dbType, "SQLite-Test", StringComparison.InvariantCultureIgnoreCase)).Delegate(() =>
Create.Table("AspNetUsers")
.WithColumn("Id", col => col.AsInt32().NotNullable().PrimaryKey("PK_AspNetUsers"))
.WithColumn("AccessFailedCount", col => col.AsInt32().NotNullable())
.WithColumn("ConcurrencyStamp", col => col.AsInt32().Nullable())
.WithColumn("Email", col => col.AsInt32().Nullable())
.WithColumn("EmailConfirmed", col => col.AsString().NotNullable())
.WithColumn("LockoutEnabled", col => col.AsString().NotNullable())
.WithColumn("LockoutEnd", col => col.AsString().Nullable())
.WithColumn("NormalizedEmail", col => col.AsString(256).Nullable().Indexed("EmailIndex"))
.WithColumn("NormalizedUserName", col => col.AsString(256).Nullable())
.WithColumn("PasswordHash", col => col.AsInt32().Nullable())
.WithColumn("PhoneNumber", col => col.AsInt32().Nullable())
.WithColumn("PhoneNumberConfirmed", col => col.AsInt32().NotNullable())
.WithColumn("SecurityStamp", col => col.AsStringMax().Nullable())
.WithColumn("TwoFactorEnabled", col => col.AsBoolean().NotNullable())
.WithColumn("UserName", col => col.AsString(256).Nullable())
);
IfDatabase(dbType => !string.Equals(dbType, "SQLite-Test", StringComparison.InvariantCultureIgnoreCase)).Delegate(() =>
Create.Table("AspNetUsers")
.WithColumn("Id", col => col.AsInt32().NotNullable().PrimaryKey("PK_AspNetUsers"))
.WithColumn("AccessFailedCount", col => col.AsInt32().NotNullable())
.WithColumn("ConcurrencyStamp", col => col.AsStringMax().Nullable())
.WithColumn("Email", col => col.AsString(256).Nullable())
.WithColumn("EmailConfirmed", col => col.AsBoolean().NotNullable())
.WithColumn("LockoutEnabled", col => col.AsBoolean().NotNullable())
.WithColumn("LockoutEnd", col => col.AsDateTimeOffset().Nullable())
.WithColumn("NormalizedEmail", col => col.AsString(256).Nullable().Indexed("EmailIndex"))
.WithColumn("NormalizedUserName", col => col.AsString(256).Nullable())
.WithColumn("PasswordHash", col => col.AsStringMax().Nullable())
.WithColumn("PhoneNumber", col => col.AsStringMax().Nullable())
.WithColumn("PhoneNumberConfirmed", col => col.AsBoolean().NotNullable())
.WithColumn("SecurityStamp", col => col.AsStringMax().Nullable())
.WithColumn("TwoFactorEnabled", col => col.AsBoolean().NotNullable())
.WithColumn("UserName", col => col.AsString(256).Nullable())
);
Create.Index("UserNameIndex").OnTable("AspNetUsers")
.OnColumn("NormalizedUserName", col => col.Unique().NullsNotDistinct())
;
Create.Table("AspNetRoleClaims")
.WithColumn("Id", col => col.AsInt32().NotNullable().Identity().PrimaryKey("PK_AspNetRoleClaims"))
.WithColumn("ClaimType", col => col.AsStringMax().Nullable())
.WithColumn("ClaimValue", col => col.AsStringMax().Nullable())
.WithColumn("RoleId",
col => col.AsInt32().NotNullable()
.Indexed("IX_AspNetRoleClaims_RoleId")
.ForeignKey("FK_AspNetRoleClaims_AspNetRoles_RoleId", "AspNetRoles", "Id")
.OnDelete(Rule.Cascade))
;
Create.Table("AspNetUserClaims")
.WithColumn("Id", col => col.AsInt32().NotNullable().Identity().PrimaryKey("PK_AspNetUserClaims"))
.WithColumn("ClaimType", col => col.AsStringMax().Nullable())
.WithColumn("ClaimValue", col => col.AsStringMax().Nullable())
.WithColumn("UserId",
col => col.AsInt32().NotNullable()
.Indexed("IX_AspNetUserClaims_UserId")
.ForeignKey("FK_AspNetUserClaims_AspNetUsers_UserId", "AspNetUsers", "Id")
.OnDelete(Rule.Cascade))
;
Create.Table("AspNetUserLogins")
.WithColumn("LoginProvider", col => col.AsString(450).NotNullable().PrimaryKey("PK_AspNetUserLogins"))
.WithColumn("ProviderKey", col => col.AsString(450).NotNullable().PrimaryKey("PK_AspNetUserLogins"))
.WithColumn("ProviderDisplayName", col => col.AsStringMax().Nullable())
.WithColumn("UserId",
col => col.AsInt32().NotNullable()
.Indexed("IX_AspNetUserLogins_UserId")
.ForeignKey("FK_AspNetUserLogins_AspNetUsers_UserId", "AspNetUsers", "Id")
.OnDelete(Rule.Cascade))
;
Create.Table("AspNetUserRoles")
.WithColumn("UserId",
col => col.AsInt32().NotNullable().PrimaryKey("PK_AspNetUserRoles")
.ForeignKey("FK_AspNetUserRoles_AspNetUsers_UserId", "AspNetUsers", "Id")
.OnDelete(Rule.Cascade))
.WithColumn("RoleId",
col => col.AsInt32().NotNullable().PrimaryKey("PK_AspNetUserRoles")
.Indexed("IX_AspNetUserRoles_RoleId")
.ForeignKey("FK_AspNetUserRoles_AspNetRoles_RoleId", "AspNetRoles", "Id")
.OnDelete(Rule.Cascade))
;
Create.Table("AspNetUserTokens")
.WithColumn("UserId",
col => col.AsInt32().NotNullable().PrimaryKey("PK_AspNetUserTokens")
.ForeignKey("FK_AspNetUserTokens_AspNetUsers_UserId", "AspNetUsers", "Id")
.OnDelete(Rule.Cascade))
.WithColumn("LoginProvider", col => col.AsString(450).NotNullable().PrimaryKey("PK_AspNetUserTokens"))
.WithColumn("Name", col => col.AsString(450).NotNullable().PrimaryKey("PK_AspNetUserTokens"))
.WithColumn("Value", col => col.AsStringMax().Nullable())
;
Create.Table("TableBasedEntity")
.WithColumn("Id", col => col.AsInt32().NotNullable().PrimaryKey("PK_TableBasedEntity"))
.WithColumn("Field", col => col.AsString(256).Nullable())
.WithColumn("RoleId", col => col.AsInt32().NotNullable()
.Indexed("IX_TableBasedEntity_RoleId")
.ForeignKey("FK_TableBasedEntity_AspNetRoles_RoleId", "AspNetRoles", "Id")
.OnDelete(Rule.Cascade))
;
Execute.Sql(@"CREATE VIEW ViewBasedEntities AS SELECT Id, Field, RoleId FROM TableBasedEntity");
}
public override void Down()
{
Execute.Sql(@"DROP VIEW ViewBasedEntities");
if (Schema.Table("AspNetRoleClaims").Exists())
{
Delete.Table("AspNetRoleClaims");
}
if (Schema.Table("AspNetUserClaims").Exists())
{
Delete.Table("AspNetUserClaims");
}
if (Schema.Table("AspNetUserLogins").Exists())
{
Delete.Table("AspNetUserLogins");
}
if (Schema.Table("AspNetUserRoles").Exists())
{
Delete.Table("AspNetUserRoles");
}
if (Schema.Table("AspNetUserTokens").Exists())
{
Delete.Table("AspNetUserTokens");
}
if (Schema.Table("AspNetRoles").Exists())
{
Delete.Table("AspNetRoles");
}
if (Schema.Table("AspNetUsers").Exists())
{
Delete.Table("AspNetUsers");
}
}
}
}