Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckMigrated #24866

Open
Tracked by #19587
ajcvickers opened this issue May 9, 2021 · 5 comments
Open
Tracked by #19587

CheckMigrated #24866

ajcvickers opened this issue May 9, 2021 · 5 comments
Labels
area-migrations area-tools punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Milestone

Comments

@ajcvickers
Copy link
Contributor

One of the dilemmas of "getting started" applications and examples is that creating the database in code when the application starts is by far the easiest way to get up and running with a database, but this is considered an anti-pattern for most production applications. So, even though its a bit harder, we want people to start with something like Migrations which allows us to show best practice from the start. However, using Migrations requires running some commands at the command line.

The idea behind EnsureMigrated is to have a single, simple line of code that can safely be run when starting an application and which will check if Migrations have been created and applied to the database. If no migrations are found in the project, then EnsureMigrated will stop and indicate that the user should run dotnet ef migrations add. For example:

A database must be created for this application. Enter the following commands to create a database using EF Core Migrations:
dotnet ef migrations add InitialMigration
dotnet ef database update
See https://aka.ms/databasemigrations for more information.

We can potentially also detect other conditions such as a migration exists, but update database has not been called. We may also want to check if the dotnet-ef tool is installed and give instructions for that.

To make this easier, we could create a new command that will add a migration and update the database in one go. For example:

A database must be created for this application. Enter the following commands to create a database using EF Core Migrations:
dotnet ef database initialize
See https://aka.ms/databasemigrations for more information.

The end-result is guidance towards best practice with minimal input from the user. It's also not magic--that is, the user knows that they are creating a database.

Thoughts @davidfowl @bricelam @JeremyLikness @halter73 @LadyNaggaga @glennc

@DamianEdwards
Copy link
Member

This looks good @ajcvickers. What do you think we should do with regards to actually calling EnsureCreated then? Should it be our templates that use EF? Would we update the database exception filter for the developer error page to show the content you propose, along with details on how and where to call EnsureCreated? Of course getting the database exception filter registered is itself a manual task today which presents its own challenges WRT discovery (separate package, separate call to add the filter to services, etc.).

@bricelam
Copy link
Contributor

bricelam commented Jun 2, 2021

This could leverage the API proposed in #22105 (comment) to check for unscaffolded migrations.

@bricelam
Copy link
Contributor

bricelam commented Jun 2, 2021

📝 Design meeting notes

@ErikEJ
Copy link
Contributor

ErikEJ commented Jun 3, 2021

"VerifyMigrated" ?

@ajcvickers ajcvickers added this to the Backlog milestone Jun 8, 2021
@ajcvickers ajcvickers modified the milestones: Backlog, 7.0.0 Oct 20, 2021
@ajcvickers ajcvickers modified the milestones: 7.0.0, Backlog Apr 23, 2022
@ajcvickers ajcvickers added punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. and removed propose-punt labels Apr 23, 2022
@vigouredelaruse

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations area-tools punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Projects
None yet
Development

No branches or pull requests

5 participants