1 |
|
package liquibase.statementexecute; |
2 |
|
|
3 |
|
import liquibase.database.Database; |
4 |
|
import liquibase.database.core.*; |
5 |
|
import liquibase.database.typeconversion.TypeConverterFactory; |
6 |
|
import liquibase.statement.NotNullConstraint; |
7 |
|
import liquibase.statement.SqlStatement; |
8 |
|
import liquibase.statement.core.CreateTableStatement; |
9 |
|
import liquibase.statement.core.RenameColumnStatement; |
10 |
|
import liquibase.test.DatabaseTestContext; |
11 |
|
import org.junit.Test; |
12 |
|
|
13 |
|
import java.util.ArrayList; |
14 |
|
import java.util.List; |
15 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 4 |
Complexity Density: 0.2 |
|
16 |
|
public class RenameColumnExecuteTest extends AbstractExecuteTest { |
17 |
|
|
18 |
|
protected static final String TABLE_NAME = "table_name"; |
19 |
|
protected static final String COLUMN_NAME = "column_name"; |
20 |
|
|
21 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
22 |
0
|
@Override... |
23 |
|
protected List<? extends SqlStatement> setupStatements(Database database) { |
24 |
0
|
ArrayList<CreateTableStatement> statements = new ArrayList<CreateTableStatement>(); |
25 |
0
|
CreateTableStatement table = new CreateTableStatement(null, TABLE_NAME); |
26 |
0
|
if (database instanceof MySQLDatabase) { |
27 |
0
|
table.addPrimaryKeyColumn("id", TypeConverterFactory.getInstance().findTypeConverter(database).getDataType("int", false), null, "pk_", null); |
28 |
|
} else { |
29 |
0
|
table.addColumn("id", TypeConverterFactory.getInstance().findTypeConverter(database).getDataType("int", false), null, new NotNullConstraint()); |
30 |
|
} |
31 |
0
|
table.addColumn(COLUMN_NAME, TypeConverterFactory.getInstance().findTypeConverter(database).getDataType("int", false)); |
32 |
0
|
statements.add(table); |
33 |
|
|
34 |
0
|
if (database.supportsSchemas()) { |
35 |
0
|
table = new CreateTableStatement(DatabaseTestContext.ALT_SCHEMA, TABLE_NAME); |
36 |
0
|
table |
37 |
|
.addColumn("id", TypeConverterFactory.getInstance().findTypeConverter(database).getDataType("int", false), null, new NotNullConstraint()); |
38 |
0
|
statements.add(table); |
39 |
|
} |
40 |
0
|
return statements; |
41 |
|
} |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
4
-
|
|
43 |
0
|
@SuppressWarnings("unchecked")... |
44 |
|
@Test |
45 |
|
public void noSchema() throws Exception { |
46 |
0
|
this.statementUnderTest = new RenameColumnStatement(null, TABLE_NAME, COLUMN_NAME, "new_name", "int"); |
47 |
|
|
48 |
0
|
assertCorrect("rename column table_name.column_name to new_name", DerbyDatabase.class, InformixDatabase.class, MaxDBDatabase.class); |
49 |
0
|
assertCorrect("alter table table_name alter column column_name rename to new_name", H2Database.class, HsqlDatabase.class); |
50 |
0
|
assertCorrect("alter table table_name alter column column_name to new_name", FirebirdDatabase.class); |
51 |
0
|
assertCorrect("alter table `table_name` change `column_name` `new_name` int", MySQLDatabase.class); |
52 |
0
|
assertCorrect("exec sp_rename '[dbo].[table_name].[column_name]', 'new_name'", MSSQLDatabase.class); |
53 |
0
|
assertCorrect("alter table [table_name] rename \"column_name\" to \"new_name\"",SybaseASADatabase.class); |
54 |
0
|
assertCorrectOnRest("alter table [table_name] rename column [column_name] to [new_name]"); |
55 |
|
} |
56 |
|
} |