#13 WIP: (testing if needed) Copy flyway history to new bubble initially

Closed
kris wants to merge 8 commits from kris/copy_flyway_history into master
  1. +2
    -0
      automation/roles/bubble/files/init_bubble_db.sh
  2. +14
    -0
      bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java

+ 2
- 0
automation/roles/bubble/files/init_bubble_db.sh View File

@@ -5,6 +5,7 @@
echo "$@" > /tmp/init.args

LOG=/dev/null
FLYWAY_MIGRATION_TABLE=flyway_schema_history

function die {
echo 1>&2 "${1}"
@@ -115,6 +116,7 @@ if [[ $(count_table_rows ${DB_NAME} account 2> /dev/null) -eq 0 ]] ; then
fi
log "Dumping schema from ${TEMP_DB} -> ${DB_NAME}"
pg_dump --schema-only ${TEMP_DB} | psql ${DB_NAME}
pg_dump --data-only --inserts --table ${FLYWAY_MIGRATION_TABLE} ${TEMP_DB} | psql ${DB_NAME}
# log "Rekeying: fromKey=${DB_KEY}, toKey=${TO_KEY}"
java -cp ${BUBBLE_JAR} bubble.main.RekeyDatabaseMain \
--jar ${BUBBLE_JAR} \


+ 14
- 0
bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java View File

@@ -41,6 +41,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.cobbzilla.util.daemon.ZillaRuntime.*;
import static org.cobbzilla.util.io.FileUtil.abs;
import static org.cobbzilla.wizard.server.config.PgRestServerConfiguration.ENV_PGPASSWORD;
import static org.cobbzilla.wizard.server.listener.FlywayMigrationListener.getFlywayTableName;

@Service @Slf4j
public class DatabaseFilterService {
@@ -87,6 +88,19 @@ public class DatabaseFilterService {
if (!schemaResult.isZeroExitStatus()) return die("copyDatabase: error populating schema for "+dbName+": "+schemaResult);
}

// Copy full flyway schema history to new database
final var flywayHistory = new File(temp, "flyway.sql");
log.info("copyDatabase: dumping flyway schema history data for current database to file: "
+ abs(flywayHistory));
try (InputStream in = new FileInputStream(configuration.pgDumpDataOnly(flywayHistory,
getFlywayTableName()))) {
log.info("copyDatabase: writing dumped flyway history data to new database " + dbName);
final var result = pgExec("psql", dbName, in, null);
if (!result.isZeroExitStatus()) {
return die("copyDatabase: error populating flyway history data for " + dbName + ": " + result);
}
}

log.info("copyDatabase: copying/filtering data into new database: "+dbName+", "+planApps.size()+" apps enabled") ;
final int port = PortPicker.pickOrDie();



Loading…
Cancel
Save