Skip to content

Commit

Permalink
0005563: Add functionality to symadmin export-sym-tables to export
Browse files Browse the repository at this point in the history
alters when upgrading
  • Loading branch information
Philip Marzullo committed Nov 1, 2022
1 parent e9b9b02 commit c15307c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Expand Up @@ -123,6 +123,7 @@ public class SymmetricAdmin extends AbstractCommandLauncher {
private static final String OPTION_EXCLUDE_DEFAULTS = "exclude-defaults";
private static final String OPTION_EXCLUDE_LOG4J = "exclude-log4j";
private static final String OPTION_EXTERNAL_SECURITY = "external-security";
private static final String OPTION_ALTERS = "alters";
private static final int WIDTH = 120;
private static final int PAD = 3;

Expand Down Expand Up @@ -252,6 +253,9 @@ private void printHelpCommand(CommandLine line) {
addOption(options, null, OPTION_EXCLUDE_LOG4J, false);
addOption(options, null, OPTION_EXTERNAL_SECURITY, false);
}
if (cmd.equals(CMD_EXPORT_SYM_TABLES)) {
addOption(options, null, OPTION_ALTERS, false);
}
if (options.getOptions().size() > 0) {
format.printWrapped(writer, WIDTH, "\nOptions:");
format.printOptions(writer, WIDTH, options, PAD, PAD);
Expand Down Expand Up @@ -287,6 +291,7 @@ protected void buildOptions(Options options) {
addOption(options, null, OPTION_EXCLUDE_DEFAULTS, false);
addOption(options, null, OPTION_EXCLUDE_LOG4J, false);
addOption(options, null, OPTION_EXTERNAL_SECURITY, false);
addOption(options, null, OPTION_ALTERS, false);
buildCryptoOptions(options);
}

Expand Down Expand Up @@ -704,10 +709,14 @@ private void generateWar(CommandLine line, List<String> args) throws Exception {

private void exportSymTables(CommandLine line, List<String> args) throws IOException {
OutputStreamWriter os = getWriter(args);
os.write(getSymmetricEngine().getSymmetricDialect().getCreateSymmetricDDL());
if (line.hasOption(OPTION_ALTERS)) {
os.write(getSymmetricEngine().getSymmetricDialect().getSymmetricDdlChanges());
} else {
os.write(getSymmetricEngine().getSymmetricDialect().getCreateSymmetricDDL());
}
os.close();
}

private void exportDefaultProperties(CommandLine line, List<String> args) throws IOException {
OutputStreamWriter os = getWriter(args);
BufferedReader is = new BufferedReader(new InputStreamReader(
Expand Down
Expand Up @@ -100,7 +100,7 @@ SymAdmin.Usage.uninstall=
SymAdmin.Usage.backup-config=
SymAdmin.Usage.restore-config=
SymAdmin.Usage.module=[install <module> | remove <module> | list-files <module> | list | list-all | upgrade | convert]
SymAdmin.Help.export-sym-tables=Output the SQL to create the SymmetricDS tables. If a filename is given, the SQL statements are written to it, otherwise standard output is used.
SymAdmin.Help.export-sym-tables=Output the SQL to create the SymmetricDS tables. If --alters is specified, then alters to the existing tables will be output. If a filename is given, the SQL statements are written to it, otherwise standard output is used.
SymAdmin.Help.run-job=Run one of the scheduled jobs immediately.
SymAdmin.Help.list-engines=List each engine name and properties file configured on this instance.
SymAdmin.Help.run-purge=Run the purge process against the configured database.
Expand Down Expand Up @@ -139,6 +139,7 @@ SymAdmin.Option.exclude-fk=Don't send foreign key constraints
SymAdmin.Option.exclude-indices=Don't send indices
SymAdmin.Option.exclude-log4j=Exclude log4j logging framework and configuration
SymAdmin.Option.external-security=Use security files outside of the WAR file for encryption keys and certificates
SymAdmin.Option.alters=DDL changes necessary to alter tables will be output

DbExport.Option.compatible=Change export to be compatible with given database: db2, db2zos, derby, firebird, greenplum, h2, hsqldb, hsqldb2, informix, interbase, mssql, mysql, oracle, postgres, sybase.
DbExport.Option.add-drop-table=Add drop table commands to output.
Expand Down
Expand Up @@ -139,6 +139,18 @@ public AbstractSymmetricDialect(IParameterService parameterService, IDatabasePla
return valueMap;
});
}

public String getSymmetricDdlChanges() {
Database modelFromXml = readSymmetricSchemaFromXml();
Database modelFromDatabase = readSymmetricSchemaFromDatabase();
List<IAlterDatabaseInterceptor> alterDatabaseInterceptors = extensionService
.getExtensionPointList(IAlterDatabaseInterceptor.class);
IAlterDatabaseInterceptor[] interceptors = alterDatabaseInterceptors
.toArray(new IAlterDatabaseInterceptor[alterDatabaseInterceptors.size()]);
IDdlBuilder builder = platform.getDdlBuilder();
String alterSql = builder.alterDatabase(modelFromDatabase, modelFromXml, interceptors);
return alterSql;
}

public boolean requiresAutoCommitFalseToSetFetchSize() {
return false;
Expand Down
Expand Up @@ -255,6 +255,8 @@ public List<String> createPurgeSqlForMultipleTables(Node node, TriggerRouter tri
public String getTablePrefix();

public Database readSymmetricSchemaFromXml();

public String getSymmetricDdlChanges();

public String getTemplateNumberPrecisionSpec();

Expand Down

0 comments on commit c15307c

Please sign in to comment.