Comments (5)
Thanks @Thwaitesy for your interest in the project!
The scenario you describe is indeed something that I don't support with the current implementation. So you're not missing anything.
It would be a nice addition though, because backward compatible DB migrations are indeed one of the nastiest issues to tackle with zero-downtime deployments. I'll think about adding this to the project.
Thanks for the heads-up!
from pitstop.
Ok cool, yeah I was just looking through things and was like.. mmm maybe ive missed some magic migration feature haha.
In no way am I saying you should add this particular feature to your project, but for anyone reading along and want to know how I solve the issue then here it is:
I have a seperate project/console app which has all the migrations in it which is basically the below program.cs
file.
I can then call that app as part of my deployment like so: Api.Database.Migrations.dll <insert-db-connection-string
right before I deploy to x machines/pods. Obviously all db changes need to be backwards compatible, so no renaming or removing tables & columns etc until they are not being used. Its not hard, it just needs planning.
program.cs
namespace Api.Database.Migrations
{
public class EFCoreContextFactory : IDesignTimeDbContextFactory<EFCoreContext>
{
public EFCoreContext CreateDbContext(string[] args)
{
var connectionString = args != null && args.Length == 1 && !string.IsNullOrEmpty(args[0]) ? args[0] : "Data Source=(local);Initial Catalog=DatabaseName;Integrated Security=True";
var optionsBuilder = new DbContextOptionsBuilder<EFCoreContext>();
optionsBuilder.UseLoggerFactory(Program.CustomLoggerFactory);
optionsBuilder.UseSqlServer(connectionString, opt => opt.CommandTimeout(120)
.MigrationsAssembly("Api.Database.Migrations"));
return new EFCoreContext(optionsBuilder.Options);
}
}
class Program
{
public static readonly LoggerFactory CustomLoggerFactory = new LoggerFactory();
static void Main(string[] args)
{
//Setup Logging
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console()
.CreateLogger();
CustomLoggerFactory.AddSerilog(dispose: false);
try
{
Log.Information("Preparing to migrate database.");
using (var db = new EFCoreContextFactory().CreateDbContext(args))
{
db.Database.Migrate();
}
Log.Information("Finished migrating database.");
}
catch (Exception ex)
{
Log.Error(ex, "Error migrating database.");
Environment.Exit(1);
}
finally
{
Log.CloseAndFlush();
}
}
}
}
Anyway I hope that provides some use to someone 👍
from pitstop.
@Thwaitesy @EdwinVW would it also make sense for all of the db writes go to one database or is this standard for containerized systems?
I've never used multiple databases for one app. Wouldn't you have a lot of cross-database joins for reporting purposes? Does this not affect db performance?
from pitstop.
@Thwaitesy I always have a separate database (or databases) for every Microservice. This is mainly because you want your services to be as autonomous as possible. That is why these databases are even made completely inaccessible from outside the service (also not for reporting!).
For reporting I would introduce a separate database that has read-models specifically for reporting purposes and fill these models by ingesting all the events that are emitted by the services.
from pitstop.
OK, thanks. I'm trying to learn how to build using microservices, but am having a tough time learning Ocelot, Messaging, etc all at the same time. Your repo is very helpful, and I hope to grasp it all someday soon.
from pitstop.
Related Issues (20)
- Where WorkshopManagement database is created HOT 1
- WebApp not working on ARM / M1 pro CPU HOT 2
- Maildev UI not opening in Browser HOT 11
- Error while sending data through POST method HOT 3
- Replace Angular front-end with a Blazor front-end
- There is a typo under functionality in Domain description on MaintenanceJob....there is a forgotten "be" HOT 2
- Invoice HOT 5
- Future plan HOT 1
- Context map workshop management precision HOT 5
- Do we really need multiple retries policy setup? HOT 2
- Parameter-less constructor HOT 2
- How do I HOT 4
- Get an error in RabbitMQMessagePublisher class
- Wiki mentions running Kubernetes dashboard, but it seems to have moved HOT 1
- Consistency between Db Entity and Event HOT 2
- Issue with microsoft/mssql-server-linux:latest HOT 3
- Questions regarding - Upgrade to .NET Core 3.0 HOT 4
- RabbitMQ Connection approach HOT 2
- Azure SQL is not supported HOT 6
- PSA: Create pitstop databases manually when deploying with azure sql
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pitstop.