mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Intermediate commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package io.ebeaninternal.dbmigration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.ebean.plugin.Plugin;
|
||||
import io.ebean.plugin.SpiServer;
|
||||
|
||||
public class DbMigrationPlugin implements Plugin {
|
||||
|
||||
private DefaultDbMigration dbMigration;
|
||||
|
||||
@Override
|
||||
public void configure(SpiServer server) {
|
||||
dbMigration = new DefaultDbMigration();
|
||||
dbMigration.setServer(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void online(boolean online) {
|
||||
try {
|
||||
if (dbMigration.generate) {
|
||||
dbMigration.generateMigration();
|
||||
}
|
||||
if (dbMigration.generateInit) {
|
||||
dbMigration.generateInitMigration();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Error while generating migration");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
dbMigration = null;
|
||||
}
|
||||
|
||||
}
|
||||
+20
-1
@@ -71,6 +71,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import javax.persistence.EnumType;
|
||||
|
||||
@@ -131,6 +132,8 @@ public class DefaultDbMigration implements DbMigration {
|
||||
private int lockTimeoutSeconds;
|
||||
protected boolean includeBuiltInPartitioning = true;
|
||||
protected boolean includeIndex;
|
||||
protected boolean generate = true;
|
||||
protected boolean generateInit = false;
|
||||
|
||||
/**
|
||||
* Create for offline migration generation.
|
||||
@@ -187,6 +190,8 @@ public class DefaultDbMigration implements DbMigration {
|
||||
online = props.getBoolean("migration.online", online);
|
||||
vanillaPlatform = props.getBoolean("migration.vanillaPlatform", vanillaPlatform);
|
||||
version = props.get("migration.version", version);
|
||||
generate = props.getBoolean("migration.generate", generate);
|
||||
generateInit = props.getBoolean("migration.generateInit", generateInit);
|
||||
// header & strictMode must be configured at DatabaseConfig level
|
||||
parsePlatforms(props.get("migration.platforms"), config.getClassLoadConfig());
|
||||
}
|
||||
@@ -413,7 +418,18 @@ public class DefaultDbMigration implements DbMigration {
|
||||
}
|
||||
|
||||
String pendingVersion = generatePendingDrop();
|
||||
if (pendingVersion != null) {
|
||||
if ("auto".equals(pendingVersion)) {
|
||||
StringJoiner sj = new StringJoiner(",");
|
||||
String diff = generateDiff(request);
|
||||
if (diff != null) {
|
||||
sj.add(diff);
|
||||
request = createRequest(initMigration);
|
||||
}
|
||||
for (String pendingDrop : request.getPendingDrops()) {
|
||||
sj.add(generatePendingDrop(request, pendingDrop));
|
||||
}
|
||||
return sj.toString();
|
||||
} else if (pendingVersion != null) {
|
||||
return generatePendingDrop(request, pendingVersion);
|
||||
} else {
|
||||
return generateDiff(request);
|
||||
@@ -650,6 +666,9 @@ public class DefaultDbMigration implements DbMigration {
|
||||
logError("migration already exists, not generating DDL");
|
||||
return null;
|
||||
} else {
|
||||
if (request.initMigration) {
|
||||
FIXME: Hier sollten wir dann die vorhandenen löschen
|
||||
}
|
||||
if (!platforms.isEmpty()) {
|
||||
writeExtraPlatformDdl(fullVersion, request.currentModel, dbMigration, request.migrationDir);
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
io.ebeaninternal.dbmigration.DbMigrationPlugin
|
||||
@@ -46,6 +46,39 @@ public class EbeanServerFactory_MultiTenancy_Test extends BaseTestCase {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tests using multi tenancy per database
|
||||
*/
|
||||
@Test
|
||||
public void create_new_server_with_multi_tenancy_db_with_master() {
|
||||
|
||||
String tenant = "customer";
|
||||
CurrentTenantProvider tenantProvider = Mockito.mock(CurrentTenantProvider.class);
|
||||
Mockito.doReturn(tenant).when(tenantProvider).currentId();
|
||||
|
||||
TenantDataSourceProvider dataSourceProvider = Mockito.mock(TenantDataSourceProvider.class);
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
|
||||
config.setName("h2");
|
||||
config.loadFromProperties();
|
||||
config.setRegister(false);
|
||||
config.setDefaultServer(false);
|
||||
config.setDdlGenerate(false);
|
||||
config.setDdlRun(false);
|
||||
|
||||
config.setTenantMode(TenantMode.DB_WITH_MASTER);
|
||||
config.setCurrentTenantProvider(tenantProvider);
|
||||
config.setTenantDataSourceProvider(dataSourceProvider);
|
||||
|
||||
Mockito.doReturn(config.getDataSource()).when(dataSourceProvider).dataSource(tenant);
|
||||
|
||||
config.setDatabasePlatform(new PostgresPlatform());
|
||||
|
||||
final Database database = DatabaseFactory.create(config);
|
||||
database.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests using multi tenancy per schema
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user