Search in sources :

Example 21 with Schema

use of liquibase.structure.core.Schema in project liquibase by liquibase.

the class ForeignKeyExistsPrecondition method check.

@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
    try {
        ForeignKey example = new ForeignKey();
        example.setName(getForeignKeyName());
        example.setForeignKeyTable(new Table());
        if (StringUtils.trimToNull(getForeignKeyTableName()) != null) {
            example.getForeignKeyTable().setName(getForeignKeyTableName());
        }
        example.getForeignKeyTable().setSchema(new Schema(getCatalogName(), getSchemaName()));
        if (!SnapshotGeneratorFactory.getInstance().has(example, database)) {
            throw new PreconditionFailedException("Foreign Key " + database.escapeIndexName(catalogName, schemaName, foreignKeyName) + " does not exist", changeLog, this);
        }
    } catch (PreconditionFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new PreconditionErrorException(e, changeLog, this);
    }
}
Also used : Table(liquibase.structure.core.Table) Schema(liquibase.structure.core.Schema) ForeignKey(liquibase.structure.core.ForeignKey)

Example 22 with Schema

use of liquibase.structure.core.Schema in project liquibase by liquibase.

the class AbstractDatabaseObject method getSerializableFieldValue.

@Override
public Object getSerializableFieldValue(String field) {
    if (field.equals("snapshotId")) {
        return snapshotId;
    }
    if (!attributes.containsKey(field)) {
        throw new UnexpectedLiquibaseException("Unknown field " + field);
    }
    Object value = attributes.get(field);
    try {
        if (value instanceof Schema) {
            Schema clone = new Schema(((Schema) value).getCatalogName(), ((Schema) value).getName());
            clone.setSnapshotId(((DatabaseObject) value).getSnapshotId());
            return clone;
        } else if (value instanceof DatabaseObject) {
            DatabaseObject clone = (DatabaseObject) value.getClass().newInstance();
            clone.setName(((DatabaseObject) value).getName());
            clone.setSnapshotId(((DatabaseObject) value).getSnapshotId());
            return clone;
        }
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException(e);
    }
    return value;
}
Also used : Schema(liquibase.structure.core.Schema) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParseException(java.text.ParseException)

Example 23 with Schema

use of liquibase.structure.core.Schema 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

Schema (liquibase.structure.core.Schema)23 CatalogAndSchema (liquibase.CatalogAndSchema)9 Table (liquibase.structure.core.Table)6 Database (liquibase.database.Database)5 OracleDatabase (liquibase.database.core.OracleDatabase)4 SQLException (java.sql.SQLException)3 AbstractJdbcDatabase (liquibase.database.AbstractJdbcDatabase)3 DatabaseException (liquibase.exception.DatabaseException)3 RawSqlStatement (liquibase.statement.core.RawSqlStatement)3 Column (liquibase.structure.core.Column)3 View (liquibase.structure.core.View)3 InformixDatabase (liquibase.database.core.InformixDatabase)2 CachedRow (liquibase.snapshot.CachedRow)2 JdbcDatabaseSnapshot (liquibase.snapshot.JdbcDatabaseSnapshot)2 UnparsedSql (liquibase.sql.UnparsedSql)2 Catalog (liquibase.structure.core.Catalog)2 Index (liquibase.structure.core.Index)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1