11using OrchardCore . Data . Migration ;
2+ using OrchardCore . Environment . Shell ;
23using OrchardCoreContrib . Contents . Indexes ;
34using YesSql . Sql ;
45
56namespace OrchardCoreContrib . Contents ;
67
7- public class Migrations : DataMigration
8+ public class Migrations ( IShellFeaturesManager shellFeaturesManager ) : DataMigration
89{
910 public async Task < int > CreateAsync ( )
1011 {
@@ -17,8 +18,24 @@ await SchemaBuilder.CreateMapIndexTableAsync<SharedDraftLinkIndex>(table => tabl
1718 . Column < DateTime > ( "CreatedUtc" )
1819 ) ;
1920
21+ return 1 ;
22+ }
23+
24+ public async Task < int > UpdateFrom1Async ( )
25+ {
26+ var features = await shellFeaturesManager . GetEnabledFeaturesAsync ( ) ;
27+
28+ if ( ! features . Any ( f => f . Id == "OrchardCore.Notifications" ) )
29+ {
30+ await SchemaBuilder . AlterIndexTableAsync < SharedDraftLinkIndex > ( table =>
31+ {
32+ table . DropIndex ( "IDX_NotificationIndex_DocumentId" ) ;
33+ table . DropIndex ( "IDX_NotificationIndex_CreatedBy" ) ;
34+ } ) ;
35+ }
36+
2037 await SchemaBuilder . AlterIndexTableAsync < SharedDraftLinkIndex > ( table => table
21- . CreateIndex ( "IDX_NotificationIndex_DocumentId " ,
38+ . CreateIndex ( "IDX_SharedDraftLinkIndex_DocumentId " ,
2239 "DocumentId" ,
2340 "LinkId" ,
2441 "ContentItemId" ,
@@ -29,13 +46,13 @@ await SchemaBuilder.AlterIndexTableAsync<SharedDraftLinkIndex>(table => table
2946 ) ;
3047
3148 await SchemaBuilder . AlterIndexTableAsync < SharedDraftLinkIndex > ( table => table
32- . CreateIndex ( "IDX_NotificationIndex_CreatedBy " ,
49+ . CreateIndex ( "IDX_SharedDraftLinkIndex_CreatedBy " ,
3350 "DocumentId" ,
3451 "ContentItemId" ,
3552 "CreatedBy" ,
3653 "CreatedUtc" )
3754 ) ;
3855
39- return 1 ;
56+ return 2 ;
4057 }
4158}
0 commit comments