[![Build Status]()]()
Azure Cosmos DB is a globally distributed multi-model database. One of the supported APIs is the SQL API, which provides a JSON document model with SQL querying and JavaScript procedural logic.
This is a Liquibase extension for [Azure Cosmos DB Core (SQL) API](https://docs.microsoft.com/en-us/rest/api/cosmos-db/) support. It uses internally [Azure Cosmos DB Java SDK v4 for Core (SQL)](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-java-v4). It is an alternative to existing evolution tools.
In order to call specific Java SDK specific methods, Liquibase turned to be the most feasible tool to extend as it allows defining change sets to fit driver methods arguments. Parameters are usually sent as Attributes ans JSON Payloads. While implementing we tried to stay as close as possible to respective Rest Endpoint API Payload structure and Java SDK method naming.
The available changes implemented are:
createDatabase REST [SDK]()
This is implicit change not available for use and it is called when Connection is initialised. A database (with provided DatabaseName in JSON connection string) is crested if not exists. All subsequent changes are applied to the created DB.
Creates a Cosmos container while passing additional request properties. There is a possibility to pass throughput properties either manual as a number or auto as a json. There is a flag to skip if exists and do not fail. If no properties are specified then a ``/null`` partition key path is the default one.
Replaces the container properties by container id. There is a possibility to pass throughput properties either manual as a number or auto as a json. If only properties specified no throughput properties will be amended and viceversa.
Deletes the Cosmos container by id. There is a flag to skip if missing and do not fail.
createStoredProcedure REST SDK
The Create Stored Procedure operation creates a new stored procedure in a collection. There is a flag to replace if exists and do not fail.
deleteStoredProcedure REST SDK
The Delete Stored Procedure operation deletes a stored procedure in a collection. There is a flag to skip if missing and do not fail.
Creates a new item(Document) synchronously in the container specified name.
Upserts an Cosmos item in the current container. If item is not found by id it will be created otherwise will be updated.
This is a custom operation not provided by API that updates each item in the query. Was implemented by exposing Query Option document and the fields to be merged(updated). Firstly the items are selected by query parameters, then for each item the fields are added from the update document, lastly the obtained item is upserted back.
This is a custom operation not provided by API that deletes each item in the query. Was implemented by exposing Query Option document. Recommended to make projections in the query as deletion is done by id field, thus is not require to fetch all fields. Firstly the items are selected by query parameters, then for each item a delete by id is performed.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
If is required to test locally or install in On-Prem server, one can use the Emulator which is quite limited however enough for some initial testing.
Otherwise can be fallowed the [Java Application Quickstart Prerequisites](https://docs.microsoft.com/en-us/azure/cosmos-db/create-sql-api-java?tabs=sync)
You need to export the emulator certificate to successfully use the emulator endpoint from languages and runtime environments that do not integrate with the Windows Certificate Store. [Export the Azure Cosmos DB TLS/SSL certificate](https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator-export-ssl-certificates) ```shell script sudo $JAVA_HOME/bin/keytool -delete -alias cosmos_emulator # import the cert sudo $JAVA_HOME/bin/keytool -importcert -keystore cacerts.jks -alias cosmos_emulator -file cosmos_emulator.cer ```
After certificate is imported should be passed as system parameters:
```shell script
mvn -Djavax.net.ssl.trustStore="
Connection string for now doesn't conform to any standard was just too convenient to parse from a JSON.
Field names are case-sensitive and kept as upper camel case as in Cosmos documentation.
Both formats accept other properties either as Json fields and respectively query parameters for future flexibility
(the only meaningful for nou is ```ssl=true/false```)