-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Migrations.cs
98 lines (84 loc) · 3.6 KB
/
Migrations.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
using OrchardCore.Alias.Indexes;
using OrchardCore.Alias.Models;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Data.Migration;
using YesSql.Sql;
namespace OrchardCore.Alias
{
public class Migrations : DataMigration
{
private readonly IContentDefinitionManager _contentDefinitionManager;
public Migrations(IContentDefinitionManager contentDefinitionManager)
{
_contentDefinitionManager = contentDefinitionManager;
}
public int Create()
{
_contentDefinitionManager.AlterPartDefinition(nameof(AliasPart), builder => builder
.Attachable()
.WithDescription("Provides a way to define custom aliases for content items."));
// NOTE: The Alias Length has been upgraded from 64 characters to 767.
// For existing SQL databases update the AliasPartIndex tables Alias column length manually.
// INFO: The Alias Length is now of 735 chars, but this is only used on a new installation.
SchemaBuilder.CreateMapIndexTable<AliasPartIndex>(table => table
.Column<string>("Alias", col => col.WithLength(AliasPart.MaxAliasLength))
.Column<string>("ContentItemId", c => c.WithLength(26))
.Column<bool>("Latest", c => c.WithDefault(false))
.Column<bool>("Published", c => c.WithDefault(true))
);
SchemaBuilder.AlterIndexTable<AliasPartIndex>(table => table
.CreateIndex("IDX_AliasPartIndex_DocumentId",
"DocumentId",
"Alias",
"ContentItemId",
"Published",
"Latest")
);
// Shortcut other migration steps on new content definition schemas.
return 4;
}
// This code can be removed in a later version as Latest and Published are alterations.
public int UpdateFrom1()
{
SchemaBuilder.AlterIndexTable<AliasPartIndex>(table => table
.AddColumn<bool>("Latest", c => c.WithDefault(false))
);
SchemaBuilder.AlterIndexTable<AliasPartIndex>(table => table
.AddColumn<bool>("Published", c => c.WithDefault(true))
);
return 2;
}
// This code can be removed in a later version.
public int UpdateFrom2()
{
// Can't be fully created on existing databases where the 'Alias' may be of 767 chars.
SchemaBuilder.AlterIndexTable<AliasPartIndex>(table => table
//.CreateIndex("IDX_AliasPartIndex_DocumentId",
// "DocumentId",
// "Alias",
// "ContentItemId",
// "Latest",
// "Published")
.CreateIndex("IDX_AliasPartIndex_DocumentId",
"DocumentId",
"Alias")
);
return 3;
}
// This code can be removed in a later version.
public int UpdateFrom3()
{
// In the previous migration step, an index was not fully created,
// but here, we can create a separate one for the missing columns.
SchemaBuilder.AlterIndexTable<AliasPartIndex>(table => table
.CreateIndex("IDX_AliasPartIndex_DocumentId_ContentItemId",
"DocumentId",
"ContentItemId",
"Published",
"Latest")
);
return 4;
}
}
}