From c2f5530adcfe3be7cbce76e5637b13bd25961510 Mon Sep 17 00:00:00 2001
From: Kamil Krynicki <kkrynick@cs-ccr-dev2.cern.ch>
Date: Mon, 23 Jul 2018 10:44:02 +0200
Subject: [PATCH] NXCALS-1880 added constraint on users

---
 ...LS-1880-add-unique-constraint-on-users.xml | 19 +++++++++++++++++++
 .../sql/versions/all-versions-changelog.xml   |  1 +
 2 files changed, 20 insertions(+)
 create mode 100644 service-db/src/main/resources/sql/versions/NXCALS-1880/NXCALS-1880-add-unique-constraint-on-users.xml

diff --git a/service-db/src/main/resources/sql/versions/NXCALS-1880/NXCALS-1880-add-unique-constraint-on-users.xml b/service-db/src/main/resources/sql/versions/NXCALS-1880/NXCALS-1880-add-unique-constraint-on-users.xml
new file mode 100644
index 0000000000..e93347dc8b
--- /dev/null
+++ b/service-db/src/main/resources/sql/versions/NXCALS-1880/NXCALS-1880-add-unique-constraint-on-users.xml
@@ -0,0 +1,19 @@
+<databaseChangeLog
+    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
+         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"
+>
+
+  <changeSet author="kkrynick" id="NXCALS-1880-constraint-on-users">
+    <sql>
+      ALTER TABLE USERS ADD CONSTRAINT USERS_UK UNIQUE (REALM_ID, USER_NAME);
+    </sql>
+    <rollback>
+      ALTER TABLE USERS DROP CONSTRAINT USERS_UK;
+    </rollback>
+  </changeSet>
+
+</databaseChangeLog>
+
+
diff --git a/service-db/src/main/resources/sql/versions/all-versions-changelog.xml b/service-db/src/main/resources/sql/versions/all-versions-changelog.xml
index 4fcb9f0ed5..25fa06b901 100644
--- a/service-db/src/main/resources/sql/versions/all-versions-changelog.xml
+++ b/service-db/src/main/resources/sql/versions/all-versions-changelog.xml
@@ -10,5 +10,6 @@
     <include file="NXCALS-1329/NXCALS-1329-increase-sequence-values.xml" relativeToChangelogFile="true"/>
     <include file="NXCALS-1224/NXCALS-1224-add-lock-until-stamp-column-to-entities.xml" relativeToChangelogFile="true"/>
     <include file="NXCALS-1850/NXCALS-1850-add-unit-to-variable.xml" relativeToChangelogFile="true"/>
+    <include file="NXCALS-1880/NXCALS-1880-add-unique-constraint-on-users.xml" relativeToChangelogFile="true"/>
 
 </databaseChangeLog>
-- 
GitLab