xwrs
xwrs

Reputation: 1297

Cosmos DB and DevOps automations

Recently I have faced a scenario where I needed to execute some sort of DDL and DML migration (I know these acronyms are not applicable for NoSQL, but anyway) on my CosmosDB database. These migration is planned to be automated and executed within CI/CD pipelines.

Apparently its is really hard to find any information online about the functionality I am trying to achieve. Here are some criteria:

I am really frustrated about last point and trying to avoid creation of app that will apply DML changes using SDK. In .net world AFAIK EntityFramework does not support automated migrations in CosmosDB.

So question to a good community is: is there anything considered a good practice for automating Cosmos DB data modifications?

Does what I have stated above makes any sense or it is another attempt to deal with NoSQL DBMS as with RDBMS?

Upvotes: 5

Views: 1482

Answers (2)

Noah Stahl
Noah Stahl

Reputation: 7563

While Cosmos doesn't enforce a schema and will accept any new fields or formats you start providing, for example, I have sometimes encountered a scenario where a one-time "migration" of sorts made sense, for example renaming a field. One approach I've used is to create a single-use, on-demand Azure Function with the sole job of reading the existing data, validating, and making needed changes.

This bit of code can be very deliberate about changes and configured with safeguards to make sure it only runs manually/intentionally and is idempotent to be safe to run multiple times with same result. It can be logically separate from your app's codebase but could still used share data access code like repository classes. Unless you schedule downtime, it would need to account for changes that happen during the migration window, which idempotency solves by allowing to run several passes as needed.

Another option to consider is to leverage Azure Data Factory with its integration to read and transform Cosmos data.

Upvotes: 1

Mark Brown
Mark Brown

Reputation: 8763

Yes, stop trying to treat Cosmos DB like SQL Server. There is no DDL for database schema or default values. This is a NoSQL store that doesn't care what you write to the database.

In Cosmos DB, you define your schema in your application's data layer. If you have data model classes defined, add the new properties there with whatever attributes they need and you are done.

Upvotes: 1

Related Questions