Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08e026d
commit 93ab9c6
Showing
7 changed files
with
159 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../java/com/dotmarketing/startup/runonce/Task230426AlterVarcharLengthOfLockedByColTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.dotmarketing.startup.runonce; | ||
|
||
import com.dotmarketing.common.db.DotConnect; | ||
import com.dotmarketing.common.db.DotDatabaseMetaData; | ||
import com.dotmarketing.db.DbConnectionFactory; | ||
import com.dotmarketing.exception.DotDataException; | ||
import org.junit.Test; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
public class Task230426AlterVarcharLengthOfLockedByColTest { | ||
// Change the length to recreate the scenario | ||
private void setMinLengthBeforeTask (String tblName) throws SQLException { | ||
String query = ""; | ||
if (DbConnectionFactory.isPostgres()){ | ||
query = "alter table "+tblName+" alter column locked_by type varchar (36);"; | ||
} | ||
|
||
final DotConnect dotConnect = new DotConnect(); | ||
dotConnect.executeStatement(query); | ||
} | ||
|
||
/** | ||
* Method to test: {@link Task230426AlterVarcharLengthOfLockedByCol#executeUpgrade()} | ||
* Given Scenario: The varchar length of the column locked_by in the specified table should be increased | ||
* Specified Tables: contentlet_version_info, container_version_info, template_version_info, link_version_info | ||
* ExpectedResult: The length of the column locked_by should be more than 36. We set it in 100 | ||
* | ||
*/ | ||
@Test | ||
public void test_executeUpgrade_GivenIncreaseLockedByLength_LengthShouldBeMoreThan36() throws SQLException, DotDataException { | ||
final String[] tableNames = { "contentlet_version_info", "container_version_info", "template_version_info", "link_version_info" }; | ||
final String colName = "locked_by"; | ||
Map<String, String> result; | ||
final DotDatabaseMetaData dotDatabaseMetaData = new DotDatabaseMetaData(); | ||
|
||
//The method is created and tested only for postgres | ||
if (DbConnectionFactory.isPostgres()){ | ||
|
||
//iterate and test all the tables | ||
for (String tableName : tableNames) { | ||
setMinLengthBeforeTask(tableName); | ||
//set the length 36 to recreate the given scenario | ||
result = dotDatabaseMetaData.getModifiedColumnLength(tableName, colName); | ||
assertEquals("36", result.get("field_length")); | ||
} | ||
|
||
//Execute the task | ||
final Task230426AlterVarcharLengthOfLockedByCol taskToBeTested = new Task230426AlterVarcharLengthOfLockedByCol(); | ||
taskToBeTested.executeUpgrade(); | ||
|
||
//Check if the length was increased to 100 | ||
for (String tableName : tableNames) { | ||
result = dotDatabaseMetaData.getModifiedColumnLength(tableName, colName);; | ||
assertEquals("100", result.get("field_length")); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...main/java/com/dotmarketing/startup/runonce/Task230426AlterVarcharLengthOfLockedByCol.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.dotmarketing.startup.runonce; | ||
import com.dotmarketing.common.db.DotConnect; | ||
import com.dotmarketing.exception.DotDataException; | ||
import com.dotmarketing.exception.DotRuntimeException; | ||
import com.dotmarketing.startup.StartupTask; | ||
|
||
import java.sql.SQLException; | ||
|
||
/** | ||
* This class alter the locked_by column in four different tables. | ||
* The locked_by column in some coses has a length of 36. With this class | ||
* we are increasing that length to 100. | ||
*/ | ||
public class Task230426AlterVarcharLengthOfLockedByCol implements StartupTask { | ||
private void alterTables() throws SQLException { | ||
final DotConnect dc = new DotConnect(); | ||
dc.executeStatement("alter table contentlet_version_info alter column locked_by type varchar (100)"); | ||
dc.executeStatement("alter table container_version_info alter column locked_by type varchar (100)"); | ||
dc.executeStatement("alter table template_version_info alter column locked_by type varchar (100)"); | ||
dc.executeStatement("alter table link_version_info alter column locked_by type varchar (100)"); | ||
} | ||
@Override | ||
public boolean forceRun() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void executeUpgrade() throws DotDataException, DotRuntimeException { | ||
try { | ||
alterTables(); | ||
} catch (SQLException e) { | ||
throw new DotDataException(e.getMessage(),e); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters