Edouard Berthe
Edouard Berthe

Reputation: 1463

Best practices for Database Migrations in Production in Azure

I am developping an ASP.Net Core application, backed with a PostgreSQL database.

So far, my application is hosted on my personal VPS, but I would like to migrate on Azure, and I don't know how to handle the DB migrations over there.

My database scheme is handled by Entity Framework Core and mapped with POCOs. As explained in the docs, when I want to change my SQL scheme, I update the POCOs, create a migration C# file through the dotnet ef migration create command, and apply them through the Database.Migrate() command at runtime. This is defined by Applying migrations at runtime, however as stated:

While productive for local development and testing of migrations, this approach is inappropriate for managing production databases.

There is a paragraph about using SQL Scripts, but nothing really about "How to apply migrations scripts in CI/CD pipeline".

Of course, I had a look to the official tutorial on Microsoft docs about how to deploy and ASP.Net Core app + SQL DB on Azure, but there is nothing about DB migrations (the migrations of the production DB are applied through CLI from local computer ...).

Isn't there a specific service on Azure allowing us to apply the DB migrations?

I know this question is specific neither to Azure, nor to .NET apps, but I was afraid my question would be too "broad".

Also, when looking for "DB migrations" on Google, most results are concerning the migration from a given DB to another (or from a vendor to another), which is not the same.

Many thanks

Upvotes: 6

Views: 1933

Answers (2)

Matthieu Girard
Matthieu Girard

Reputation: 1

I guess you are looking for Azure Database Migration Service. It has two main mode, online and offline mode depending on your migration strategy. It is compatible with PostgresSQL et should allow migration to managed Postgres (Single or Flexible Server).

https://azure.microsoft.com/en-us/services/database-migration/#overview

Once your migration is done, you can then point your connection string to your newly migrated DB.

Upvotes: -1

faso
faso

Reputation: 697

There isn't a specific service in Azure that manages your DB migrations.

From experience, it's usually managed by generating the migration SQL (dotnet ef migrations script), reviewing it and then running it manually or saving to a file that is then executed as a part of the CI/CD pipeline.

Upvotes: 3

Related Questions