mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#374 - Update ModelDiff and migration generation
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package com.avaje.ebean.dbmigration.model;
|
||||
|
||||
import com.avaje.ebean.dbmigration.migration.AddColumn;
|
||||
import com.avaje.ebean.dbmigration.migration.AddHistoryTable;
|
||||
import com.avaje.ebean.dbmigration.migration.AlterColumn;
|
||||
import com.avaje.ebean.dbmigration.migration.ChangeSet;
|
||||
import com.avaje.ebean.dbmigration.migration.ChangeSetType;
|
||||
import com.avaje.ebean.dbmigration.migration.DropColumn;
|
||||
import com.avaje.ebean.dbmigration.migration.DropHistoryTable;
|
||||
import com.avaje.ebean.dbmigration.migration.Migration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -31,6 +33,11 @@ public class ModelDiff {
|
||||
*/
|
||||
private final List<Object> dropChanges = new ArrayList<Object>();
|
||||
|
||||
/**
|
||||
* List of 'drop' type changes. Expected to be placed into a separate DDL script.
|
||||
*/
|
||||
private final List<Object> dropHistoryChanges = new ArrayList<Object>();
|
||||
|
||||
/**
|
||||
* Construct with a base model.
|
||||
*/
|
||||
@@ -45,6 +52,27 @@ public class ModelDiff {
|
||||
this.baseModel = new ModelContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the diff as a migration potentially containing
|
||||
* an apply changeSet and a drop changeSet.
|
||||
*/
|
||||
public Migration getMigration() {
|
||||
|
||||
Migration migration = new Migration();
|
||||
ChangeSet applyChangeSet = getApplyChangeSet();
|
||||
if (!applyChangeSet.getChangeSetChildren().isEmpty()) {
|
||||
// add a non empty apply changeSet
|
||||
migration.getChangeSet().add(applyChangeSet);
|
||||
}
|
||||
|
||||
ChangeSet dropChangeSet = getDropChangeSet();
|
||||
if (!dropChangeSet.getChangeSetChildren().isEmpty()) {
|
||||
// add a non empty drop changeSet
|
||||
migration.getChangeSet().add(dropChangeSet);
|
||||
}
|
||||
return migration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of 'create' changes.
|
||||
*/
|
||||
@@ -52,6 +80,16 @@ public class ModelDiff {
|
||||
return createChanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of 'drop' changes.
|
||||
*/
|
||||
public List<Object> getDropChanges() {
|
||||
return dropChanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the 'apply' changeSet.
|
||||
*/
|
||||
public ChangeSet getApplyChangeSet() {
|
||||
// put the changes into a ChangeSet
|
||||
ChangeSet createChangeSet = new ChangeSet();
|
||||
@@ -60,6 +98,9 @@ public class ModelDiff {
|
||||
return createChangeSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the 'drop' changeSet.
|
||||
*/
|
||||
public ChangeSet getDropChangeSet() {
|
||||
// put the changes into a ChangeSet
|
||||
ChangeSet createChangeSet = new ChangeSet();
|
||||
@@ -68,21 +109,6 @@ public class ModelDiff {
|
||||
return createChangeSet;
|
||||
}
|
||||
|
||||
public Migration getMigration() {
|
||||
|
||||
Migration migration = new Migration();
|
||||
migration.getChangeSet().add(getApplyChangeSet());
|
||||
migration.getChangeSet().add(getDropChangeSet());
|
||||
return migration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of 'drop' changes.
|
||||
*/
|
||||
public List<Object> getDropChanges() {
|
||||
return dropChanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare to a 'newer' model and collect the differences.
|
||||
*/
|
||||
@@ -116,18 +142,41 @@ public class ModelDiff {
|
||||
protected void compareTables(MTable currentTable, MTable newTable) {
|
||||
|
||||
currentTable.compare(this, newTable);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the AlterColumn to the 'apply' changes.
|
||||
*/
|
||||
public void addAlterColumn(AlterColumn alterColumn) {
|
||||
createChanges.add(alterColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the AlterColumn to the 'apply' changes.
|
||||
*/
|
||||
public void addAddColumn(AddColumn addColumn) {
|
||||
createChanges.add(addColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the DropColumn to the 'drop' changes.
|
||||
*/
|
||||
public void addDropColumn(DropColumn dropColumn) {
|
||||
dropChanges.add(dropColumn);
|
||||
}
|
||||
|
||||
public void addAddColumn(AddColumn addColumn) {
|
||||
createChanges.add(addColumn);
|
||||
/**
|
||||
* Add the AddHistoryTable to apply changes.
|
||||
*/
|
||||
public void addAddHistoryTable(AddHistoryTable addHistoryTable) {
|
||||
createChanges.add(addHistoryTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the DropHistoryTable to the 'drop history' changes.
|
||||
*/
|
||||
public void addDropHistoryTable(DropHistoryTable dropHistoryTable) {
|
||||
dropHistoryChanges.add(dropHistoryTable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user