Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
342 stars 44 forks source link

Customise collection names #42

Closed cocowalla closed 5 years ago

cocowalla commented 5 years ago

A pattern I've used with Azure's SQL Server and Postgres PaaS offerings is to use a single instance to hold data for all our test environments (e.g. dev, test, qa), by using database schemas. For example, if I had a Widgets table, it would exist in all of the schemas:

dev.Widgets
test.Widgets
qa.Widgets

This reduces costs, as there is only 1 database instance instead of 3, and also means there are less Azure resources to manage.

I'd like to do the same with Cosmos DB, but AFAIK it doesn't have a schema/namespace concept, so the idea would be to prefix the name of each collection with the environment, e.g.:

dev__Widgets
test__Widgets
qa__Widgets

What I'm looking for is perhaps a CollectionPrefix property on CosmosStoreSettings.

Is there any way to achieve this at present? If not, are you open to discussing a mechanism for this?

Elfocrash commented 5 years ago

Hello @cocowalla,

These are different environments or configurations under which your project runs right?

You can do that manually by using the overrideCollectionName at the CosmosStore instantiation method or the DI registration ones and providing your own prefix logic using your configuration. However this is a really valid point and I would like to implement this feature as it would be easy to just do it at the CosmosStoreSettings level as you said.

Thanks for submitting this, I will leave it open until I implement the feature.

Elfocrash commented 5 years ago

Hello @cocowalla,

Feature added in develop. Will be added in the next minor release.

Thanks for making Cosmonaut better.

cocowalla commented 5 years ago

Looks good, thanks! 👏