Skip to content

Commit

Permalink
#374 - Update migration generation
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Aug 14, 2015
1 parent bd9acab commit 85fdf86
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 102 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/avaje/ebean/config/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ public class ServerConfig {
*/
private String asOfSysPeriod = "sys_period";

/**
* Suffix appended to the base table to derive the view that contains the union
* of the base table and the history table in order to support asOf queries.
*/
private String historyTableSuffix = "_history";

/**
* Use for transaction scoped batch mode.
*/
Expand Down Expand Up @@ -676,6 +682,20 @@ public void setAsOfSysPeriod(String asOfSysPeriod) {
this.asOfSysPeriod = asOfSysPeriod;
}

/**
* Return the history table suffix (defaults to _history).
*/
public String getHistoryTableSuffix() {
return historyTableSuffix;
}

/**
* Set the history table suffix.
*/
public void setHistoryTableSuffix(String historyTableSuffix) {
this.historyTableSuffix = historyTableSuffix;
}

/**
* Return true if we are running in a JTA Transaction manager.
*/
Expand Down Expand Up @@ -1960,6 +1980,7 @@ protected void loadSettings(PropertiesWrapper p) {
diffFlatMode = p.getBoolean("diffFlatMode", diffFlatMode);
asOfViewSuffix = p.get("asOfViewSuffix", asOfViewSuffix);
asOfSysPeriod = p.get("asOfSysPeriod", asOfSysPeriod);
historyTableSuffix = p.get("historyTableSuffix", historyTableSuffix);
dataSourceJndiName = p.get("dataSourceJndiName", dataSourceJndiName);
databaseSequenceBatchSize = p.getInt("databaseSequenceBatchSize", databaseSequenceBatchSize);
databaseBooleanTrue = p.get("databaseBooleanTrue", databaseBooleanTrue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.avaje.ebean.dbmigration.ddlgeneration;

import com.avaje.ebean.config.DbConstraintNaming;
import com.avaje.ebean.config.NamingConvention;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.dbmigration.ddlgeneration.platform.BaseTableDdl;
import com.avaje.ebean.dbmigration.ddlgeneration.platform.PlatformDdl;
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.CreateTable;
import com.avaje.ebean.dbmigration.migration.DropColumn;
import com.avaje.ebean.dbmigration.migration.DropHistoryTable;

import java.io.IOException;
import java.util.List;
Expand All @@ -20,27 +21,36 @@ public class BaseDdlHandler implements DdlHandler {

protected final TableDdl tableDdl;

public BaseDdlHandler(NamingConvention namingConvention, DbConstraintNaming naming, PlatformDdl platformDdl) {
this.tableDdl = new BaseTableDdl(namingConvention, naming, platformDdl);
public BaseDdlHandler(ServerConfig serverConfig, PlatformDdl platformDdl) {
this.tableDdl = new BaseTableDdl(serverConfig, platformDdl);
}

@Override
public void generate(DdlWrite writer, ChangeSet changeSet) throws IOException {

List<Object> changeSetChildren = changeSet.getChangeSetChildren();
for (Object change : changeSetChildren) {
if (change instanceof CreateTable) {
if (change instanceof CreateTable) {
generate(writer, (CreateTable) change);
} else if (change instanceof AddColumn) {
generate(writer, (AddColumn) change);
} else if (change instanceof DropColumn) {
generate(writer, (DropColumn) change);
} else if (change instanceof AlterColumn) {
generate(writer, (AlterColumn) change);
} else if (change instanceof AddHistoryTable) {
generate(writer, (AddHistoryTable) change);
} else if (change instanceof DropHistoryTable) {
generate(writer, (DropHistoryTable) change);
}
}
}

@Override
public void generateExtra(DdlWrite write) throws IOException {
tableDdl.generateExtra(write);
}

@Override
public void generate(DdlWrite writer, CreateTable createTable) throws IOException {
tableDdl.generate(writer, createTable);
Expand All @@ -60,4 +70,14 @@ public void generate(DdlWrite writer, DropColumn dropColumn) throws IOException
public void generate(DdlWrite writer, AlterColumn alterColumn) throws IOException {
tableDdl.generate(writer, alterColumn);
}

@Override
public void generate(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException {
tableDdl.generate(writer, addHistoryTable);
}

@Override
public void generate(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException {
tableDdl.generate(writer, dropHistoryTable);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.avaje.ebean.dbmigration.ddlgeneration;

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.CreateTable;
import com.avaje.ebean.dbmigration.migration.DropColumn;
import com.avaje.ebean.dbmigration.migration.DropHistoryTable;

import java.io.IOException;

Expand All @@ -22,4 +24,9 @@ public interface DdlHandler {

void generate(DdlWrite writer, AlterColumn alterColumn) throws IOException;

void generate(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException;

void generate(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException;

void generateExtra(DdlWrite write) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.avaje.ebean.dbmigration.ddlgeneration;

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.CreateTable;
import com.avaje.ebean.dbmigration.migration.DropColumn;
import com.avaje.ebean.dbmigration.migration.DropHistoryTable;
import com.avaje.ebean.dbmigration.migration.DropTable;

import java.io.IOException;
Expand Down Expand Up @@ -37,4 +39,19 @@ public interface TableDdl {
* Write the drop column change.
*/
void generate(DdlWrite writer, DropColumn dropColumn) throws IOException;

/**
* Write the AddHistoryTable change.
*/
void generate(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException;

/**
* Write the DropHistoryTable change.
*/
void generate(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException;

/**
* Generate any extra DDL such as regeneration of history triggers.
*/
void generateExtra(DdlWrite write) throws IOException;
}
Loading

0 comments on commit 85fdf86

Please sign in to comment.