liquibase / liquibase-cosmosdb

Liquibase Cosmos DB Core (SQL) API Extension
Apache License 2.0
6 stars 9 forks source link
core extension oss

Liquibase Cosmos DB Core (SQL) API Extension

[![Build Status]()]()

Table of contents

  1. Introduction
  2. Implemented Changes
  3. Getting Started
  4. Running tests
  5. Integration
  6. Contributing
  7. License

Introduction

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.

Implemented Changes:

The available changes implemented are:

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Install Azure Cosmos DB Emulator

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)

Import keys to Trust Store

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="\cacerts.jks" -Djavax.net.ssl.trustStorePassword=changeit ``` ### Installing * Clone the project * [Run tests](#running-tests) ## Running tests ### Adjust connection string Connection url can be adjusted here: [`db.connection.uri`](./src/test/resources/application-test.properties) Connection String Format has to be prefixed with ```cosmosdb://``` Can understand two formats: #### Json Format after the prefix ```json { "accountEndpoint" : "https://[host]:[port]", "accountKey" : "[Account Key]", "databaseName" : "[Database Name]" } ``` so a json url looks like: ```url cosmosdb://{"accountEndpoint" : "https://localhost:8080", "accountKey" : "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", "databaseName" : "testdb1"} ``` #### CosmosDB URL like after the prefix ```url cosmosdb://[host]:[accountKey]@[host]:[port]/[databaseName]?[Query Parameters] ``` so a CosmosDB like url looks like: ```url cosmosdb://localhost:C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==@localhost:8080/testdb1 ```

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```)

### Run integration tests Integration tests can be run by enabling `run-its` profile ```shell script mvn clean install -Prun-its ``` ## Integration ### Add dependency: ```xml com.mastercard.mcob liquibase-cosmosdb 4.0.1-SNAPSHOT ``` ### Java call: You can initialise Liquibase and run from java in your application: See examples in [Integration Tests](/src/test/java/liquibase/ext/cosmosdb/CosmosLiquibaseIT.java) ### Run using maven plugin ```xml org.liquibase liquibase-maven-plugin 4.0.0 [path_to_scripts]\scripts\changelog.main.xml cosmosdb://{"AccountEndpoint" : "https://ech-0a9d975b:8081, "AccountKey" : "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", "DatabaseName" : "testdb1"} false com.mastercard.mcob liquibase-cosmosdb 4.0.1-SNAPSHOT org.liquibase liquibase-core 4.0.0 ``` See [Demo Application](/src/test/liquibase-cosmosdb-example) Working/tested plugin features: * liquibase:update - evolve * liquibase:dropAll - cleanup database the created db will not be dropped * liquibase:history - shows applied changesets * liquibase:status - shows the pending changesets and invalid checksums * liquibase:listLocks - lists the list of acquired locks * liquibase:releaseLocks - releases the existing acquired locks ## Contributing Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. ## License This project is licensed under the Apache License Version 2.0 - see the [LICENSE.md](LICENSE.md) file for details