blob: 1210592da78cc79eca85d53a0ad6e94dd5201423 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Working with database · Eclipse Kapua™ Developer Guide</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.2">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-hints/plugin-hints.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="client.html" />
<link rel="prev" href="sso.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="building.html">
<a href="building.html">
Building
</a>
<ul class="articles">
<li class="chapter " data-level="1.2.1" data-path="building.html">
<a href="building.html#kapua">
Kapua
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="building.html">
<a href="building.html#documentation">
Documentation
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.3" data-path="running.html">
<a href="running.html">
Running
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="running.html">
<a href="running.html#docker-containers">
Docker
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="running.html">
<a href="running.html#openshift">
OpenShift
</a>
</li>
<li class="chapter " data-level="1.3.3" data-path="running.html">
<a href="running.html#vagrant">
Vagrant
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.4" data-path="ide.html">
<a href="ide.html">
Setting up an IDE
</a>
<ul class="articles">
<li class="chapter " data-level="1.4.1" data-path="ide.html">
<a href="ide.html#eclipse">
Eclipse IDE
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.5" >
<span>
Configuration
</span>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="sso.html">
<a href="sso.html">
Single sign-on
</a>
</li>
</ul>
</li>
<li class="chapter active" data-level="1.6" data-path="database.html">
<a href="database.html">
Working with database
</a>
</li>
<li class="chapter " data-level="1.7" data-path="client.html">
<a href="client.html">
Client generation
</a>
</li>
<li class="chapter " data-level="1.8" data-path="qa.html">
<a href="qa.html">
QA process
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >Working with database</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="working-with-kapua-database">Working with Kapua database</h1>
<p>In current implementation of Kapua we hold device data in SQL database (H2 SQL Server).
Kapua is also compatible with other DBMS that can be setup by providing the correct JDBC Driver and correct JDBC URL String.</p>
<p>In order to keep SQL schema updated, we decided to use <a href="https://www.liquibase.org/" target="_blank">Liquibase</a>.</p>
<h2 id="liquibase-in-kapua">Liquibase in Kapua</h2>
<p>Kapua REST APIs, Admin Console and Broker can use, upon their startup, the embedded Liquibase client which ensures that all database update scripts have been collected and
applied to your database. The coordinates of database URL connection are obtained from regular Kapua settings i.e. the following
system properties:</p>
<ul>
<li><code>commons.db.username</code></li>
<li><code>commons.db.password</code></li>
<li><code>commons.db.schema</code></li>
</ul>
<p>Please note that the scripts execution is disabled by default. To enable it, set the system property <code>commons.db.schema.update</code> to true when running any of the applications.</p>
<p>Liquibase clients looks up for xml scripts located in the classpath matching <code>liquibase/(*-master.pre.xml|*-master.xml|*-master.post.xml)</code> pattern. </p>
<p>Such files will be collected all together from the plugin, then sorted in three distinct sets: all the <code>*-master.pre.xml</code> files first, then the <code>*-master.xml</code> files and finally <code>*-master.post.xml</code> files.
Every set will be sorted by path name, then the three sets will then be executed in the same same order (the <code>master.pre</code> first, then the <code>master</code> set and finally the <code>master.post</code> set.)</p>
<p>Every master file must contain at least one reference (via the <code>&lt;include&gt;</code> Liquibase XML tag) to a version-specific changelog file, usually contained in a folder named after the service version.
Such changelog will, in turn, contain references to the actual Liquibase XML files that gets executed by the Liquibase client.</p>
<h3 id="adding-new-xml-script-to-the-project">Adding new XML script to the project</h3>
<p>If you would like a new Liquibase script to your service, just add new <code>*.xml</code> file to <code>src/main/resources/liquibase/_service-version_</code> directory of your Maven project.
Just keep in mind that the name of your file should be unique, so the best way is to at least reference the name of your service module (for example <code>device-new-creation-script.xml</code> for device management).
Also, after you create the XML, be sure to add a reference to it in the main changelog XML for the version.
If such file doesn&apos;t exist yet, because it&apos;s releated to a new version of the service, create it and add a reference to it in an appropriate master XML file.</p>
<p>More details regarding Liquibase XML file syntax, can be found on <a href="http://www.liquibase.org/documentation/xml_format.html" target="_blank">Liquibase web page</a>.</p>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="sso.html" class="navigation navigation-prev " aria-label="Previous page: Single sign-on">
<i class="fa fa-angle-left"></i>
</a>
<a href="client.html" class="navigation navigation-next " aria-label="Next page: Client generation">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Working with database","level":"1.6","depth":1,"next":{"title":"Client generation","level":"1.7","depth":1,"path":"client.md","ref":"client.md","articles":[]},"previous":{"title":"Single sign-on","level":"1.5.1","depth":2,"path":"sso.md","ref":"sso.md","articles":[]},"dir":"ltr"},"config":{"plugins":["hints"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"hints":{"danger":"fa fa-exclamation-circle","info":"fa fa-info-circle","tip":"fa fa-mortar-board","working":"fa fa-wrench"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"github":"eclipse/kapua","theme":"default","githubHost":"https://github.com/","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Eclipse Kapua™ Developer Guide","links":{"home":"http://eclipse.org/kapua"},"gitbook":"3.x.x","description":"Eclipse Kapua™ Developer Guide"},"file":{"path":"database.md","mtime":"2020-11-26T08:22:34.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2020-11-26T08:23:27.237Z"},"basePath":".","book":{"language":""}});
});
</script>
</div>
<script src="gitbook/gitbook.js"></script>
<script src="gitbook/theme.js"></script>
<script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="gitbook/gitbook-plugin-search/search.js"></script>
<script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
</body>
</html>