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

Fix migrations service in playground #2351

Merged
merged 4 commits into from
Feb 26, 2024
Merged

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Feb 22, 2024

Fixes #2308

Creating a transaction failed if starting from a blank slate because there isn't a database to create a transaction on. Removing the transaction fixes this problem.

However, it would be ideal to keep the transaction to make this safe to transient errors. To follow best practice, we need to:

  1. Create the database
  2. Start transaction
  3. Apply migratio
  4. Commit transaction.

@AndriySvyryd How do you instruct EF to just create the database? I looked at DbContext.Database.EnsureCreatedAsync, but it also creates tables.

Microsoft Reviewers: Open in CodeFlow

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Feb 22, 2024

You can call dbContext.GetService<IRelationalDatabaseCreator>().ExistsAsync() and CreateAsync()

If you remove the transaction you'll need to remove the execution strategy as well, since retrying in case of a failure will only make it worse. This is tracked in dotnet/efcore#22616

@mitchdenny mitchdenny added this to the preview 4 (Mar) milestone Feb 23, 2024
@JamesNK
Copy link
Member Author

JamesNK commented Feb 23, 2024

The retry is there to keep retrying until the database server container is running.

Database creator worked and I've re-added the transaction. Please take another look.

Comment on lines +40 to +53
if (!await dbCreator.ExistsAsync(cancellationToken))
{
await dbCreator.CreateAsync(cancellationToken);
}
Copy link
Member

@AndriySvyryd AndriySvyryd Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move these to a separate .ExecuteAsync call, since they could use up all retries while waiting for the container to start and if there's any delay creating the database BeginTransactionAsync will just fail without retrying.

@JamesNK JamesNK force-pushed the jamesnk/fix-migrations-service branch from dc1ad0a to 0e3afab Compare February 26, 2024 05:15
@JamesNK JamesNK enabled auto-merge (squash) February 26, 2024 05:16
@JamesNK JamesNK merged commit 2f664ba into main Feb 26, 2024
8 checks passed
@JamesNK JamesNK deleted the jamesnk/fix-migrations-service branch February 26, 2024 05:49
@github-actions github-actions bot locked and limited conversation to collaborators Apr 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error execute migration in playground DatabaseMigration service
3 participants