Search in sources :

Example 1 with DfSchemaDiff

use of org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff in project dbflute-core by dbflute.

the class DfAlterCheckProcess method checkAlter.

// ===================================================================================
// AlterCheck Process
// ==================
public DfAlterCheckFinalInfo checkAlter() {
    deleteAllNGMark();
    deleteSchemaXml();
    deleteCraftMeta();
    final DfAlterCheckFinalInfo finalInfo = new DfAlterCheckFinalInfo();
    // after AlterCheck, the database has altered schema
    // so you can check your application on the environment
    // to be next DB
    becomeNextSchema(finalInfo);
    if (finalInfo.isFailure()) {
        return finalInfo;
    }
    serializeNextSchema();
    // to be previous DB
    becomePreviousSchema();
    alterSchema(finalInfo);
    if (finalInfo.isFailure()) {
        return finalInfo;
    }
    serializePreviousSchema();
    // to replace the result file
    deleteAlterCheckResultDiff();
    final DfSchemaDiff schemaDiff = schemaDiff();
    if (schemaDiff.hasDiff()) {
        processDifference(finalInfo, schemaDiff);
    } else {
        processSuccess(finalInfo);
        deleteAlterCheckMark();
        deleteCraftMeta();
    }
    // not finally because of trace when abort
    deleteSchemaXml();
    return finalInfo;
}
Also used : DfSchemaDiff(org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff) DfAlterCheckFinalInfo(org.dbflute.logic.replaceschema.finalinfo.DfAlterCheckFinalInfo)

Example 2 with DfSchemaDiff

use of org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff in project dbflute-core by dbflute.

the class DfAlterCheckProcess method schemaDiff.

// ===================================================================================
// SchemaDiff
// ==========
protected DfSchemaDiff schemaDiff() {
    _log.info("");
    _log.info("+-----------------+");
    _log.info("|                 |");
    _log.info("|   Schema Diff   |");
    _log.info("|                 |");
    _log.info("+-----------------|");
    final String previousXml = getMigrationAlterCheckPreviousSchemaXml();
    final String nextXml = getMigrationAlterCheckNextSchemaXml();
    final DfSchemaDiff schemaDiff = DfSchemaDiff.createAsAlterCheck(previousXml, nextXml);
    schemaDiff.enableCraftDiff(getMigrationAlterCheckCraftMetaDir());
    schemaDiff.loadPreviousSchema();
    // always can read here so no check
    schemaDiff.loadNextSchema();
    schemaDiff.analyzeDiff();
    return schemaDiff;
}
Also used : DfSchemaDiff(org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff)

Example 3 with DfSchemaDiff

use of org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff in project dbflute-core by dbflute.

the class DfFirstDateAgent method getColumnFirstDateMap.

protected Map<String, Date> getColumnFirstDateMap() {
    // case insensitive (not flexible because of historical changes)
    if (_columnFirstDateMap != null) {
        return _columnFirstDateMap;
    }
    final Map<String, Date> columnFirstDateMap = StringKeyMap.createAsCaseInsensitiveOrdered();
    final List<DfSchemaDiff> schemaDiffList = prepareSchemaDiffList();
    for (DfSchemaDiff schemaDiff : schemaDiffList) {
        final List<DfTableDiff> tableDiffList = schemaDiff.getChangedTableDiffList();
        for (DfTableDiff tableDiff : tableDiffList) {
            final String tableName = tableDiff.getTableName();
            final List<DfColumnDiff> columnDiffList = tableDiff.getAddedColumnDiffList();
            for (DfColumnDiff columnDiff : columnDiffList) {
                final String columnName = columnDiff.getColumnName();
                final String keyName = generateColumnKey(tableName, columnName);
                columnFirstDateMap.put(keyName, schemaDiff.getNativeDiffDate());
            }
        }
    }
    _columnFirstDateMap = columnFirstDateMap;
    return _columnFirstDateMap;
}
Also used : DfSchemaDiff(org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff) DfTableDiff(org.dbflute.logic.jdbc.schemadiff.DfTableDiff) DfColumnDiff(org.dbflute.logic.jdbc.schemadiff.DfColumnDiff) Date(java.util.Date) HandyDate(org.dbflute.helper.HandyDate)

Example 4 with DfSchemaDiff

use of org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff in project dbflute-core by dbflute.

the class DfSchemaSyncChecker method checkSync.

// ===================================================================================
// Check Sync
// ==========
public void checkSync() {
    clearOutputResource();
    final DfSchemaXmlSerializer serializer = diffSchema();
    _log.info("");
    _log.info("* * * * * * * * * * * * * * * * *");
    _log.info("*                               *");
    _log.info("*   Check Schema Synchronized   *");
    _log.info("*                               *");
    _log.info("* * * * * * * * * * * * * * * * *");
    final DfSchemaDiff schemaDiff = serializer.getSchemaDiff();
    if (schemaDiff.hasDiff()) {
        _log.info(" -> the schema has differences");
        throwSchemaSyncCheckTragedyResultException();
    } else {
        // synchronized
        _log.info(" -> the schema is synchronized");
        clearOutputResource();
    }
}
Also used : DfSchemaDiff(org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff) DfSchemaXmlSerializer(org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlSerializer)

Example 5 with DfSchemaDiff

use of org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff in project dbflute-core by dbflute.

the class DfSchemaHistory method acceptDiffMap.

protected void acceptDiffMap(Map<String, Object> diffMap) {
    final Set<Entry<String, Object>> entrySet = diffMap.entrySet();
    int index = 0;
    for (Entry<String, Object> entry : entrySet) {
        // diffDate
        final String key = entry.getKey();
        final Object value = entry.getValue();
        assertDiffElementMap(key, value);
        @SuppressWarnings("unchecked") final Map<String, Object> schemaDiffMap = (Map<String, Object>) value;
        final DfSchemaDiff schemaDiff = DfSchemaDiff.createAsHistory();
        schemaDiff.acceptSchemaDiffMap(schemaDiffMap);
        if (index == 0) {
            schemaDiff.setLatest(true);
        }
        _schemaDiffList.add(schemaDiff);
        ++index;
    }
}
Also used : Entry(java.util.Map.Entry) DfSchemaDiff(org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff) Map(java.util.Map)

Aggregations

DfSchemaDiff (org.dbflute.logic.jdbc.schemadiff.DfSchemaDiff)8 Date (java.util.Date)2 HandyDate (org.dbflute.helper.HandyDate)2 DfTableDiff (org.dbflute.logic.jdbc.schemadiff.DfTableDiff)2 DfAlterCheckFinalInfo (org.dbflute.logic.replaceschema.finalinfo.DfAlterCheckFinalInfo)2 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 DfColumnDiff (org.dbflute.logic.jdbc.schemadiff.DfColumnDiff)1 DfSchemaXmlSerializer (org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlSerializer)1