File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 107107await using ( var scope = app . Services . CreateAsyncScope ( ) )
108108{
109109 var dbContext = scope . ServiceProvider . GetRequiredService < BikeTrackingDbContext > ( ) ;
110+
111+ // SQLite cannot execute DropCheckConstraint migrations. Apply the
112+ // supported migrations, mark those legacy migrations as applied,
113+ // then continue migration so endpoint queries run on migrated schema.
114+ var sqliteUnsupportedConstraintMigrations = new [ ]
115+ {
116+ "20260327165005_AddRideMilesUpperBound" ,
117+ "20260327171355_FixRideMilesUpperBoundNumericComparison" ,
118+ } ;
119+
120+ var provider = dbContext . Database . ProviderName ;
121+ if ( provider == "Microsoft.EntityFrameworkCore.Sqlite" )
122+ {
123+ await dbContext . Database . MigrateAsync ( "20260327000000_AddRideVersion" ) ;
124+
125+ var applied = ( await dbContext . Database . GetAppliedMigrationsAsync ( ) ) . ToHashSet ( ) ;
126+ foreach ( var migration in sqliteUnsupportedConstraintMigrations )
127+ {
128+ if ( applied . Contains ( migration ) )
129+ {
130+ continue ;
131+ }
132+
133+ await dbContext . Database . ExecuteSqlRawAsync (
134+ "INSERT INTO \" __EFMigrationsHistory\" (\" MigrationId\" , \" ProductVersion\" ) VALUES ({0}, {1})" ,
135+ migration ,
136+ "10.0.5"
137+ ) ;
138+ }
139+ }
140+
110141 await dbContext . Database . MigrateAsync ( ) ;
111142}
112143
You can’t perform that action at this time.
0 commit comments