Search in sources :

Example 21 with DatabaseFunction

use of liquibase.statement.DatabaseFunction in project liquibase by liquibase.

the class MySQLIntegrationTest method dateDefaultValue.

@Test
public void dateDefaultValue() throws Exception {
    if (getDatabase() == null) {
        return;
    }
    ExecutorService.getInstance().getExecutor(getDatabase()).execute(new RawSqlStatement("CREATE TABLE ad (\n" + "ad_id int(10) unsigned NOT NULL AUTO_INCREMENT,\n" + "advertiser_id int(10) unsigned NOT NULL,\n" + "ad_type_id int(10) unsigned NOT NULL,\n" + "name varchar(155) NOT NULL DEFAULT '',\n" + "label varchar(155)NOT NULL DEFAULT '',\n" + "description text NOT NULL,\n" + "active tinyint(1) NOT NULL DEFAULT '0',\n" + "created datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n" + "updated datetime DEFAULT '0000-00-00 00:00:00',\n" + "PRIMARY KEY (ad_id),\n" + "KEY active (active)\n" + ")"));
    DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(CatalogAndSchema.DEFAULT, getDatabase(), new SnapshotControl(getDatabase()));
    Column createdColumn = snapshot.get(new Column().setRelation(new Table().setName("ad").setSchema(new Schema())).setName("created"));
    Object defaultValue = createdColumn.getDefaultValue();
    assertNotNull(defaultValue);
    assertTrue(defaultValue instanceof DatabaseFunction);
    assertEquals("0000-00-00 00:00:00", ((DatabaseFunction) defaultValue).getValue());
}
Also used : RawSqlStatement(liquibase.statement.core.RawSqlStatement) Table(liquibase.structure.core.Table) DatabaseFunction(liquibase.statement.DatabaseFunction) Column(liquibase.structure.core.Column) Schema(liquibase.structure.core.Schema) CatalogAndSchema(liquibase.CatalogAndSchema) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Aggregations

DatabaseFunction (liquibase.statement.DatabaseFunction)21 Date (java.util.Date)7 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)6 SequenceNextValueFunction (liquibase.statement.SequenceNextValueFunction)5 DatabaseObject (liquibase.structure.DatabaseObject)5 BigInteger (java.math.BigInteger)4 LiquibaseDataType (liquibase.datatype.LiquibaseDataType)4 DateFormat (java.text.DateFormat)3 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Method (java.lang.reflect.Method)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Change (liquibase.change.Change)2 ChangeSet (liquibase.changelog.ChangeSet)2 InformixDatabase (liquibase.database.core.InformixDatabase)2 SequenceCurrentValueFunction (liquibase.statement.SequenceCurrentValueFunction)2 SqlStatement (liquibase.statement.SqlStatement)2 RawSqlStatement (liquibase.statement.core.RawSqlStatement)2 Column (liquibase.structure.core.Column)2