use of liquibase.change.ColumnConfig in project liquibase by liquibase.
the class UpdateExecutablePreparedStatementTest method testExecuteWithParamPlaceholders.
@Test
public void testExecuteWithParamPlaceholders() throws Exception {
// given
UpdateExecutablePreparedStatement statement = new UpdateExecutablePreparedStatement(database, null, null, "DATABASECHANGELOG", new ArrayList<ColumnConfig>(asList(new ColumnConfig().setName("MD5SUM").setValue("7:e27bf9c0c2313160ef960a15d44ced47"))), changeSet, resourceAccessor).setWhereClause(database.escapeObjectName("ID", Column.class) + " = ? " + "AND " + database.escapeObjectName("AUTHOR", Column.class) + " = ? " + "AND " + database.escapeObjectName("FILENAME", Column.class) + " = ?").addWhereParameters("SYPA: AUTO_START tüüp INT -> TEXT, vaartus 0 00 17 * * ?", "martin", "db/changelog.xml");
// when
statement.execute(preparedStatementFactory);
// then
verify(connection).prepareStatement("UPDATE [DATABASECHANGELOG] " + "SET [MD5SUM] = ? " + "WHERE [ID] = N'SYPA: AUTO_START tüüp INT -> TEXT, vaartus 0 00 17 * * ?' " + "AND [AUTHOR] = 'martin' " + "AND [FILENAME] = 'db/changelog.xml'");
verify(ps).setString(1, "7:e27bf9c0c2313160ef960a15d44ced47");
}
use of liquibase.change.ColumnConfig in project liquibase by liquibase.
the class XMLChangeLogSerializerTest method createNode_CreateTableChange.
@Test
public void createNode_CreateTableChange() throws Exception {
CreateTableChange change = new CreateTableChange();
change.setTableName("TABLE_NAME");
ColumnConfig column1 = new ColumnConfig();
column1.setName("id");
column1.setType("int");
ConstraintsConfig column1constraints = new ConstraintsConfig();
column1constraints.setPrimaryKey(true);
column1constraints.setNullable(false);
column1.setConstraints(column1constraints);
change.addColumn(column1);
ColumnConfig column2 = new ColumnConfig();
column2.setName("name");
column2.setType("varchar(255)");
change.addColumn(column2);
ColumnConfig column3 = new ColumnConfig();
column3.setName("state_id");
ConstraintsConfig column3constraints = new ConstraintsConfig();
column3constraints.setNullable(false);
column3constraints.setInitiallyDeferred(true);
column3constraints.setDeferrable(true);
column3constraints.setForeignKeyName("fk_tab_ref");
column3constraints.setReferences("state(id)");
column3.setConstraints(column3constraints);
change.addColumn(column3);
ColumnConfig column4 = new ColumnConfig();
column4.setName("phone");
column4.setType("varchar(255)");
column4.setDefaultValue("NOPHONE");
change.addColumn(column4);
ColumnConfig column5 = new ColumnConfig();
column5.setName("phone2");
column5.setType("varchar(255)");
ConstraintsConfig column5constraints = new ConstraintsConfig();
column5constraints.setUnique(true);
column5.setConstraints(column5constraints);
change.addColumn(column5);
Element element = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change);
assertEquals("createTable", element.getTagName());
assertEquals(5, element.getChildNodes().getLength());
Element columnElement = ((Element) element.getChildNodes().item(0));
assertEquals("column", columnElement.getTagName());
assertEquals("id", columnElement.getAttribute("name"));
assertEquals("int", columnElement.getAttribute("type"));
Element constraintsElement = (Element) columnElement.getChildNodes().item(0);
assertEquals("constraints", constraintsElement.getTagName());
assertEquals(2, constraintsElement.getAttributes().getLength());
assertEquals("true", constraintsElement.getAttribute("primaryKey"));
assertEquals("false", constraintsElement.getAttribute("nullable"));
columnElement = ((Element) element.getChildNodes().item(1));
assertEquals("column", columnElement.getTagName());
assertEquals("name", columnElement.getAttribute("name"));
assertEquals("varchar(255)", columnElement.getAttribute("type"));
columnElement = ((Element) element.getChildNodes().item(2));
assertEquals("column", columnElement.getTagName());
assertEquals("state_id", columnElement.getAttribute("name"));
constraintsElement = (Element) columnElement.getChildNodes().item(0);
assertEquals("constraints", constraintsElement.getTagName());
assertEquals(5, constraintsElement.getAttributes().getLength());
assertEquals("false", constraintsElement.getAttribute("nullable"));
assertEquals("true", constraintsElement.getAttribute("deferrable"));
assertEquals("true", constraintsElement.getAttribute("initiallyDeferred"));
assertEquals("fk_tab_ref", constraintsElement.getAttribute("foreignKeyName"));
assertEquals("state(id)", constraintsElement.getAttribute("references"));
columnElement = ((Element) element.getChildNodes().item(3));
assertEquals("column", columnElement.getTagName());
assertEquals("phone", columnElement.getAttribute("name"));
assertEquals("varchar(255)", columnElement.getAttribute("type"));
columnElement = ((Element) element.getChildNodes().item(4));
assertEquals("column", columnElement.getTagName());
assertEquals("phone2", columnElement.getAttribute("name"));
assertEquals("varchar(255)", columnElement.getAttribute("type"));
constraintsElement = (Element) columnElement.getChildNodes().item(0);
assertEquals("constraints", constraintsElement.getTagName());
assertEquals(1, constraintsElement.getAttributes().getLength());
assertEquals("true", constraintsElement.getAttribute("unique"));
}
use of liquibase.change.ColumnConfig in project liquibase by liquibase.
the class AddUniqueConstraintExecutorTest method execute_withSchema.
@SuppressWarnings("unchecked")
@Test
public void execute_withSchema() throws Exception {
statementUnderTest = new AddUniqueConstraintStatement(DatabaseTestContext.ALT_CATALOG, DatabaseTestContext.ALT_SCHEMA, TABLE_NAME, new ColumnConfig[] { new ColumnConfig().setName(COLUMN_NAME) }, CONSTRAINT_NAME);
// FIXME Syntax for mysql is correct, but exception "Table 'liquibaseb.adduqtest' doesn't exist" is thrown
// assertCorrect("alter table `liquibaseb`.`adduqtest` add constraint `uq_test` unique (`coltomakeuq`)", MySQLDatabase.class);
assertCorrect("alter table liquibaseb.adduqtest add constraint unique (coltomakeuq) constraint uq_test", InformixDatabase.class);
assertCorrect("alter table liquibasec.adduqtest add constraint uq_test unique (coltomakeuq)", OracleDatabase.class);
assertCorrect("alter table liquibaseb.\"adduqtest\" add constraint uq_test unique (\"coltomakeuq\")", PostgresDatabase.class);
assertCorrect("alter table liquibasec.adduqtest add constraint uq_test unique (coltomakeuq)", DerbyDatabase.class);
assertCorrect("alter table [liquibaseb].[adduqtest] add constraint [uq_test] unique ([coltomakeuq])", SybaseASADatabase.class, SybaseDatabase.class, MSSQLDatabase.class);
assertCorrect("alter table [adduqtest] add constraint [uq_test] unique ([coltomakeuq])", FirebirdDatabase.class);
assertCorrect("alter table [liquibaseb].[adduqtest] add constraint [uq_test] unique ([coltomakeuq])", HsqlDatabase.class);
assertCorrectOnRest("alter table [liquibasec].[adduqtest] add constraint [uq_test] unique ([coltomakeuq])");
}
use of liquibase.change.ColumnConfig in project liquibase by liquibase.
the class AddUniqueConstraintExecutorTest method execute_noConstraintName.
@SuppressWarnings("unchecked")
@Test
public void execute_noConstraintName() throws Exception {
this.statementUnderTest = new AddUniqueConstraintStatement(null, null, TABLE_NAME, new ColumnConfig[] { new ColumnConfig().setName(COLUMN_NAME) }, null);
assertCorrect("alter table adduqtest add unique (coltomakeuq)", MySQLDatabase.class);
assertCorrect("alter table adduqtest add constraint unique (coltomakeuq)", InformixDatabase.class);
assertCorrect("alter table adduqtest add unique (coltomakeuq)", OracleDatabase.class);
assertCorrect("alter table \"adduqtest\" add unique (\"coltomakeuq\")", PostgresDatabase.class);
assertCorrect("alter table adduqtest add unique (coltomakeuq)", DerbyDatabase.class);
assertCorrect("alter table [adduqtest] add unique ([coltomakeuq])", SybaseASADatabase.class, SybaseDatabase.class);
assertCorrect("alter table [adduqtest] add unique ([coltomakeuq])", MSSQLDatabase.class);
assertCorrect("alter table [adduqtest] add unique ([coltomakeuq])");
}
use of liquibase.change.ColumnConfig in project liquibase by liquibase.
the class AddUniqueConstraintExecutorTest method execute_noSchema.
// @Test
// public void execute_noSchema() throws Exception {
// new DatabaseTestTemplate().testOnAvailableDatabases(
// new SqlStatementDatabaseTest(null, new AddUniqueConstraintStatement(null, TABLE_NAME, COLUMN_NAME, "uq_adduqtest")) {
//
// protected void preExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// assertFalse(snapshot.getTable(TABLE_NAME).getColumn(COLUMN_NAME).isUnique());
// }
//
// protected void postExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// //todo: enable snapshot and assertion when snapshot can check for unique constraints
// //snapshot = new DatabaseSnapshotGenerator(snapshot);
// assertTrue(snapshot.getTable(TABLE_NAME).getColumn(COLUMN_NAME).isUnique());
// }
// });
// }
//
// @Test
// public void execute_withSchema() throws Exception {
// new DatabaseTestTemplate().testOnAvailableDatabases(
// new SqlStatementDatabaseTest(TestContext.ALT_SCHEMA, new AddUniqueConstraintStatement(TestContext.ALT_SCHEMA, TABLE_NAME, COLUMN_NAME, "uq_adduqtest")) {
// protected void preExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// assertFalse(snapshot.getTable(TABLE_NAME).getColumn(COLUMN_NAME).isUnique());
// }
//
// protected void postExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// //todo: enable snapshot and assertion when snapshot can check for unique constraints
// snapshot = new DatabaseSnapshotGenerator(database, TestContext.ALT_SCHEMA);
// assertTrue(snapshot.getTable(TABLE_NAME).getColumn(COLUMN_NAME).isUnique());
// }
//
// });
// }
//
// @Test
// public void execute_withTablespace() throws Exception {
// new DatabaseTestTemplate().testOnAvailableDatabases(
// new SqlStatementDatabaseTest(null, new AddUniqueConstraintStatement(null, TABLE_NAME, COLUMN_NAME, "uq_adduqtest").setTablespace(TestContext.ALT_TABLESPACE)) {
// protected void preExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// assertFalse(snapshot.getTable(TABLE_NAME).getColumn(COLUMN_NAME).isUnique());
// }
//
// protected void postExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// //todo: enable snapshot and assertion when snapshot can check for unique constraints
// // snapshot = new DatabaseSnapshotGenerator(database);
//// assertTrue(snapshot.getTable(TABLE_NAME).getColumn(COLUMN_NAME).isUnique());
// }
// });
// }
@SuppressWarnings("unchecked")
@Test
public void execute_noSchema() throws Exception {
this.statementUnderTest = new AddUniqueConstraintStatement(null, null, TABLE_NAME, new ColumnConfig[] { new ColumnConfig().setName(COLUMN_NAME) }, CONSTRAINT_NAME);
assertCorrect("alter table [adduqtest] add constraint [uq_test] unique ([coltomakeuq])", SybaseDatabase.class);
assertCorrect("alter table [adduqtest] add constraint [uq_test] unique ([coltomakeuq])", MSSQLDatabase.class);
assertCorrect("alter table [adduqtest] add constraint [uq_test] unique ([coltomakeuq])", SybaseASADatabase.class);
assertCorrect("alter table adduqtest add constraint uq_test unique (coltomakeuq)", MySQLDatabase.class);
assertCorrect("alter table adduqtest add constraint unique (coltomakeuq) constraint uq_test", InformixDatabase.class);
assertCorrect("alter table adduqtest add constraint uq_test unique (coltomakeuq)", OracleDatabase.class);
assertCorrect("alter table \"adduqtest\" add constraint uq_test unique (\"coltomakeuq\")", PostgresDatabase.class);
assertCorrect("alter table adduqtest add constraint uq_test unique (coltomakeuq)", DerbyDatabase.class);
assertCorrect("alter table [adduqtest] add constraint [uq_test] unique ([coltomakeuq])");
}
Aggregations