mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-11 06:30:28 +00:00
Fix dbmigration (#1277)
ENH: Support adding a '-- Generated by' comment to DDL including version and timestamp
This commit is contained in:
1 parent
0e219a9bc6
commit
91cb5a23fd
55 files changed
+184
-13
No files matched your search
@@ -66,8 +66,13 @@ public class BaseDdlHandler implements DdlHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateExtra(DdlWrite write) throws IOException {
|
||||
tableDdl.generateExtra(write);
|
||||
public void generateProlog(DdlWrite write) throws IOException {
|
||||
tableDdl.generateProlog(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateEpilog(DdlWrite write) throws IOException {
|
||||
tableDdl.generateEpilog(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,5 +41,7 @@ public interface DdlHandler {
|
||||
|
||||
void generate(DdlWrite writer, DropIndex dropIndex) throws IOException;
|
||||
|
||||
void generateExtra(DdlWrite write) throws IOException;
|
||||
void generateProlog(DdlWrite write) throws IOException;
|
||||
|
||||
void generateEpilog(DdlWrite write) throws IOException;
|
||||
}
|
||||
@@ -68,8 +68,14 @@ public interface TableDdl {
|
||||
*/
|
||||
void generate(DdlWrite writer, DropIndex dropIndex) throws IOException;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Generate any extra DDL such as stored procedures or TableValueParameters.
|
||||
*/
|
||||
void generateProlog(DdlWrite write) throws IOException;
|
||||
|
||||
/**
|
||||
* Generate any extra DDL such as regeneration of history triggers.
|
||||
*/
|
||||
void generateExtra(DdlWrite write) throws IOException;
|
||||
void generateEpilog(DdlWrite write) throws IOException;
|
||||
}
|
||||
@@ -656,14 +656,20 @@ public class BaseTableDdl implements TableDdl {
|
||||
platformDdl.dropHistoryTable(writer, dropHistoryTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateProlog(DdlWrite write) throws IOException {
|
||||
platformDdl.generateProlog(write);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the end to generate additional ddl such as regenerate history triggers.
|
||||
*/
|
||||
@Override
|
||||
public void generateExtra(DdlWrite write) throws IOException {
|
||||
public void generateEpilog(DdlWrite write) throws IOException {
|
||||
for (HistoryTableUpdate update : this.regenerateHistoryTriggers.values()) {
|
||||
platformDdl.regenerateHistoryTriggers(write, update);
|
||||
}
|
||||
platformDdl.generateEpilog(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -617,4 +617,19 @@ public class PlatformDdl {
|
||||
}
|
||||
apply.append(String.format("comment on column %s.%s is '%s'", table, column, comment)).endOfStatement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to generate a prolog for each script (stored procedures)
|
||||
*/
|
||||
public void generateProlog(DdlWrite write) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to generate an epilog. Will be added at the end of script
|
||||
*/
|
||||
public void generateEpilog(DdlWrite write) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,6 +107,10 @@ public class CurrentModel {
|
||||
createDdl();
|
||||
|
||||
StringBuilder ddl = new StringBuilder(2000);
|
||||
String header = server.getServerConfig().getMigrationConfig().getDdlHeader();
|
||||
if (header != null && !header.isEmpty()) {
|
||||
ddl.append(header).append('\n');
|
||||
}
|
||||
ddl.append(write.apply().getBuffer());
|
||||
ddl.append(write.applyForeignKeys().getBuffer());
|
||||
ddl.append(write.applyHistory().getBuffer());
|
||||
@@ -122,6 +126,10 @@ public class CurrentModel {
|
||||
createDdl();
|
||||
|
||||
StringBuilder ddl = new StringBuilder(2000);
|
||||
String header = server.getServerConfig().getMigrationConfig().getDdlHeader();
|
||||
if (header != null && !header.isEmpty()) {
|
||||
ddl.append(header).append('\n');
|
||||
}
|
||||
ddl.append(write.dropAllForeignKeys().getBuffer());
|
||||
ddl.append(write.dropAll().getBuffer());
|
||||
|
||||
@@ -139,7 +147,9 @@ public class CurrentModel {
|
||||
write = new DdlWrite(new MConfiguration(), model);
|
||||
|
||||
DdlHandler handler = handler();
|
||||
handler.generateProlog(write);
|
||||
handler.generate(write, createChangeSet);
|
||||
handler.generateEpilog(write);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,14 +45,14 @@ public class PlatformDdlWriter {
|
||||
public void processMigration(Migration dbMigration, DdlWrite write, File writePath, String fullVersion) throws IOException {
|
||||
|
||||
DdlHandler handler = handler();
|
||||
|
||||
handler.generateProlog(write);
|
||||
List<ChangeSet> changeSets = dbMigration.getChangeSet();
|
||||
for (ChangeSet changeSet : changeSets) {
|
||||
if (isApply(changeSet)) {
|
||||
handler.generate(write, changeSet);
|
||||
}
|
||||
}
|
||||
handler.generateExtra(write);
|
||||
handler.generateEpilog(write);
|
||||
|
||||
writePlatformDdl(write, writePath, fullVersion);
|
||||
}
|
||||
@@ -88,6 +88,10 @@ public class PlatformDdlWriter {
|
||||
*/
|
||||
protected void writeApplyDdl(Writer writer, DdlWrite write) throws IOException {
|
||||
|
||||
String header = config.getDdlHeader();
|
||||
if (header != null) {
|
||||
writer.append(header).append('\n');
|
||||
}
|
||||
// merge the apply buffers in the appropriate order
|
||||
prependDropDependencies(writer, write.applyDropDependencies());
|
||||
writer.append("-- apply changes\n");
|
||||
|
||||
@@ -90,7 +90,9 @@ public class ModelBuildBeanVisitor implements BeanVisitor {
|
||||
if (!descriptor.isIdTypePlatformDefault() || initialValue > 0 || allocationSize > 0) {
|
||||
// explicitly set to use sequence or identity (generally not recommended practice)
|
||||
if (IdType.IDENTITY == descriptor.getIdType()) {
|
||||
table.setIdentityType(IdentityType.IDENTITY);
|
||||
if (!descriptor.isIdTypePlatformDefault()) {
|
||||
table.setIdentityType(IdentityType.IDENTITY);
|
||||
}
|
||||
} else {
|
||||
// explicit sequence defined
|
||||
table.setIdentityType(IdentityType.SEQUENCE);
|
||||
|
||||
Reference in new issue
Block a user