Skip to content

Commit

Permalink
Merge pull request #3583 from Coduz/fix-userExternalUsernameIndex
Browse files Browse the repository at this point in the history
Fixed User.externalUsername column and creation on db
  • Loading branch information
Coduz authored Aug 1, 2022
2 parents 670050c + 2c93de4 commit 423aaa8
Show file tree
Hide file tree
Showing 3 changed files with 317 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ public User create(UserCreator userCreator) throws KapuaException {
ArgumentValidator.notNull(userCreator.getScopeId().getId(), "userCreator.scopeId");
ArgumentValidator.notEmptyOrNull(userCreator.getName(), "userCreator.name");
ArgumentValidator.match(userCreator.getName(), CommonsValidationRegex.NAME_REGEXP, "userCreator.name");
ArgumentValidator.lengthRange(userCreator.getName(), 3, 255, "userCreator.name");
ArgumentValidator.match(userCreator.getEmail(), CommonsValidationRegex.EMAIL_REGEXP, "userCreator.email");
ArgumentValidator.notNull(userCreator.getStatus(), "userCreator.status");

ArgumentValidator.notNull(userCreator.getUserType(), "userCreator.userType");
if (userCreator.getUserType() == UserType.EXTERNAL) {
if (userCreator.getExternalId() != null) {
ArgumentValidator.notEmptyOrNull(userCreator.getExternalId(), "userCreator.externalId");
ArgumentValidator.lengthRange(userCreator.getExternalId(), 3, 255, "userCreator.externalId");
} else {
ArgumentValidator.notEmptyOrNull(userCreator.getExternalUsername(), "userCreator.externalUsername");
ArgumentValidator.lengthRange(userCreator.getExternalUsername(), 3, 255, "userCreator.externalUsername");
}
} else if (userCreator.getUserType() == UserType.INTERNAL) {
ArgumentValidator.isEmptyOrNull(userCreator.getExternalId(), "userCreator.externalId");
Expand Down Expand Up @@ -150,15 +153,18 @@ public User update(User user) throws KapuaException {
ArgumentValidator.notNull(user.getScopeId(), "user.scopeId");
ArgumentValidator.notEmptyOrNull(user.getName(), "user.name");
ArgumentValidator.match(user.getName(), CommonsValidationRegex.NAME_REGEXP, "user.name");
ArgumentValidator.lengthRange(user.getName(), 3, 255, "user.name");
ArgumentValidator.match(user.getEmail(), CommonsValidationRegex.EMAIL_REGEXP, "user.email");
ArgumentValidator.notNull(user.getStatus(), "user.status");
ArgumentValidator.notNull(user.getUserType(), "user.userType");

if (user.getUserType() == UserType.EXTERNAL) {
if (user.getExternalId() != null) {
ArgumentValidator.notEmptyOrNull(user.getExternalId(), "user.externalId");
ArgumentValidator.lengthRange(user.getExternalId(), 3, 255, "user.externalId");
} else {
ArgumentValidator.notEmptyOrNull(user.getExternalUsername(), "user.externalUsername");
ArgumentValidator.lengthRange(user.getExternalUsername(), 3, 255, "user.externalUsername");
}
} else if (user.getUserType() == UserType.INTERNAL) {
ArgumentValidator.isEmptyOrNull(user.getExternalId(), "user.externalId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,46 @@
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd"
logicalFilePath="KapuaDB/changelog-user-2.0.0.xml">

<changeSet id="changelog-user_2.0.0_external-username" author="eurotech">
<!-- This has been commented since UNIQUE creates an index on the field, which makes this column creation incompatible -->
<!-- with MySQL/MariaDB databases that have a length limit of 767 bytes per index. -->
<!-- Index will be redefined as NOT UNIQUE with an index on the column to improve query performances -->
<!-- -->
<!-- <changeSet id="changelog-user_2.0.0_external-username" author="eurotech">-->
<!-- <addColumn tableName="usr_user">-->
<!-- <column name="external_username" type="varchar(1024)">-->
<!-- <constraints unique="true"/>-->
<!-- </column>-->
<!-- </addColumn>-->
<!-- </changeSet>-->

<changeSet id="changelog-user_2.0.0_external-username-fix-create" author="eurotech">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="usr_user" columnName="external_username"/>
</not>
</preConditions>

<addColumn tableName="usr_user">
<column name="external_username" type="varchar(1024)">
<constraints unique="true"/>
</column>
<column name="external_username" type="varchar(255)"/>
</addColumn>
</changeSet>
<changeSet id="changelog-user_2.0.0_external-username-fix-modify" author="eurotech">
<preConditions onFail="MARK_RAN">
<columnExists tableName="usr_user" columnName="external_username"/>
</preConditions>

<modifyDataType tableName="usr_user" columnName="external_username" newDataType="varchar(255)"/>
</changeSet>

<changeSet id="changelog-user_2.0.0_external-username-fix-index" author="eurotech">
<preConditions onFail="MARK_RAN">
<not>
<indexExists tableName="usr_user" indexName="idx_externalUsername"/>
</not>
</preConditions>

<createIndex tableName="usr_user" indexName="idx_externalUsername">
<column name="external_username"/>
</createIndex>
</changeSet>
</databaseChangeLog>
Loading

0 comments on commit 423aaa8

Please sign in to comment.