-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
6,928 additions
and
428 deletions.
There are no files selected for viewing
1,311 changes: 1,311 additions & 0 deletions
1,311
dbmigration-test/resources/dbmigration/myapp/migration-current.xml
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
src/main/java/com/avaje/ebean/config/DbMigrationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.avaje.ebean.config; | ||
|
||
/** | ||
* Configuration for the DB migration processing. | ||
*/ | ||
public class DbMigrationConfig { | ||
|
||
/** | ||
* The application name which is used as the unique code when applying migrations. | ||
*/ | ||
private String appName; | ||
|
||
/** | ||
* Path where migration | ||
*/ | ||
private String resourcePath; | ||
|
||
public String getAppName() { | ||
return appName; | ||
} | ||
|
||
public void setAppName(String appName) { | ||
this.appName = appName; | ||
} | ||
|
||
public String getResourcePath() { | ||
return resourcePath; | ||
} | ||
|
||
public void setResourcePath(String resourcePath) { | ||
this.resourcePath = resourcePath; | ||
} | ||
|
||
/** | ||
* Load the settings from the PropertiesWrapper. | ||
*/ | ||
public void loadSettings(PropertiesWrapper properties) { | ||
|
||
appName = properties.get("migration.appName", appName); | ||
resourcePath = properties.get("migration.resourcePath", resourcePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/avaje/ebean/dbmigration/DbMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.avaje.ebean.dbmigration; | ||
|
||
import com.avaje.ebean.Ebean; | ||
import com.avaje.ebean.EbeanServer; | ||
import com.avaje.ebean.config.DbMigrationConfig; | ||
import com.avaje.ebean.dbmigration.model.CurrentModel; | ||
import com.avaje.ebeaninternal.api.SpiEbeanServer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* | ||
*/ | ||
public class DbMigration { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DbMigration.class); | ||
|
||
private final SpiEbeanServer server; | ||
|
||
private final DbMigrationConfig migrationConfig; | ||
|
||
public DbMigration() { | ||
this(Ebean.getDefaultServer()); | ||
} | ||
|
||
public DbMigration(EbeanServer ebeanServer) { | ||
this.server = (SpiEbeanServer) ebeanServer; | ||
this.migrationConfig = server.getServerConfig().getMigrationConfig(); | ||
} | ||
|
||
|
||
|
||
public void writeCurrent() { | ||
|
||
CurrentModel currentModel = new CurrentModel(server); | ||
|
||
File writeTo = getWritePath(); | ||
logger.info("... write to {}", writeTo.getAbsolutePath()); | ||
currentModel.writeMigration(writeTo); | ||
} | ||
|
||
public File getWritePath() { | ||
File resourceRootDir = new File("./dbmigration-test/resources"); | ||
|
||
// expect to be a relative path | ||
String resourcePath = migrationConfig.getResourcePath(); | ||
|
||
File path = new File(resourceRootDir, resourcePath); | ||
if (!path.exists()) { | ||
path.mkdirs(); | ||
} | ||
return new File(path, "migration-current.xml"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.avaje.ebean.dbmigration; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* | ||
*/ | ||
public class DbOffline { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DbOffline.class); | ||
|
||
private static final String KEY = "ebean.dboffline"; | ||
|
||
public static final String H2 = "H2"; | ||
|
||
public static void setPlatform(String platformName) { | ||
System.setProperty(KEY, platformName); | ||
} | ||
|
||
public static String getPlatform() { | ||
return System.getProperty(KEY); | ||
} | ||
|
||
public static void asH2() { | ||
setPlatform(H2); | ||
} | ||
|
||
public static boolean isSet() { | ||
return getPlatform() != null; | ||
} | ||
|
||
public static void reset() { | ||
System.clearProperty(KEY); | ||
logger.info("reset"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletions
11
src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/ColumnDdl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
package com.avaje.ebean.dbmigration.ddlgeneration; | ||
|
||
import com.avaje.ebean.dbmigration.migration.AddColumn; | ||
import com.avaje.ebean.dbmigration.migration.AlterColumn; | ||
import com.avaje.ebean.dbmigration.migration.DropColumn; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Write AddColumn or DropColumn. | ||
* Write DDL for AddColumn , DropColumn or AlterColumn. | ||
*/ | ||
public interface ColumnDdl { | ||
|
||
/** | ||
* Write a AddColumn change. | ||
* Write the add column change. | ||
*/ | ||
void generate(DdlWrite writer, AddColumn addColumn) throws IOException; | ||
|
||
/** | ||
* Write a DropColumn change. | ||
* Write the drop column change. | ||
*/ | ||
void generate(DdlWrite writer, DropColumn dropColumn) throws IOException; | ||
|
||
/** | ||
* Write the alter column changes. | ||
*/ | ||
void generate(DdlWrite writer, AlterColumn alterColumn) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.