From 4ecfb72629930da6f8ae0bcded8c70b55c5e2c5d Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Tue, 12 May 2020 12:53:18 +0200 Subject: [PATCH 1/7] update lib --- utils/cobbzilla-wizard | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 0c698bab..6452b3f1 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 0c698babbbffdbc4be53bc844ceec64fc6f2a981 +Subproject commit 6452b3f19cb049c4c9a65291fb5f39d5e645e5e0 -- 2.17.1 From a0dd981747d2cea0b8f5a81bad04a7b6dee32954 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Tue, 12 May 2020 12:53:32 +0200 Subject: [PATCH 2/7] Copy flyway history on new bubble --- .../service/dbfilter/DatabaseFilterService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java b/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java index 278f6a22..f0fbe159 100644 --- a/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java +++ b/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java @@ -24,6 +24,7 @@ import org.cobbzilla.util.system.CommandResult; import org.cobbzilla.util.system.CommandShell; import org.cobbzilla.wizard.model.Identifiable; import org.cobbzilla.wizard.server.config.DatabaseConfiguration; +import org.flywaydb.core.Flyway; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -87,6 +88,18 @@ 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(schema)); + try (InputStream in = new FileInputStream(configuration.pgDumpDataOnly(flywayHistory, + Flyway.configure().getTable()))) { + 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(); -- 2.17.1 From ea87a40cff59458bdb77a0b3f82869a2fcc25ba7 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Thu, 14 May 2020 12:41:42 +0200 Subject: [PATCH 3/7] Fix file name in log line --- .../java/bubble/service/dbfilter/DatabaseFilterService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java b/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java index f0fbe159..2d41cdda 100644 --- a/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java +++ b/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java @@ -90,7 +90,8 @@ public class DatabaseFilterService { // 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(schema)); + log.info("copyDatabase: dumping flyway schema history data for current database to file: " + + abs(flywayHistory)); try (InputStream in = new FileInputStream(configuration.pgDumpDataOnly(flywayHistory, Flyway.configure().getTable()))) { log.info("copyDatabase: writing dumped flyway history data to new database " + dbName); -- 2.17.1 From 69f86c8ebf4400cbe2a828cb53e55d3057f5218d Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Thu, 14 May 2020 17:17:54 +0200 Subject: [PATCH 4/7] Copy flyway history table's data on bubble init --- automation/roles/bubble/files/init_bubble_db.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/automation/roles/bubble/files/init_bubble_db.sh b/automation/roles/bubble/files/init_bubble_db.sh index 3e6467a1..8031bb22 100644 --- a/automation/roles/bubble/files/init_bubble_db.sh +++ b/automation/roles/bubble/files/init_bubble_db.sh @@ -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} \ -- 2.17.1 From 6d8873766d45d8ae3f257ca9856c555e9687ba0d Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 15 May 2020 13:51:43 +0200 Subject: [PATCH 5/7] update lib --- utils/cobbzilla-wizard | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 6452b3f1..21e85705 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 6452b3f19cb049c4c9a65291fb5f39d5e645e5e0 +Subproject commit 21e85705225e51e3f34582ea67cc3677c381ac4d -- 2.17.1 From 21fbe08a5a9befd1b911bd29b44aa65f1bae23c0 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 15 May 2020 14:33:08 +0200 Subject: [PATCH 6/7] update lib --- utils/cobbzilla-wizard | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cobbzilla-wizard b/utils/cobbzilla-wizard index 21e85705..18b71b0f 160000 --- a/utils/cobbzilla-wizard +++ b/utils/cobbzilla-wizard @@ -1 +1 @@ -Subproject commit 21e85705225e51e3f34582ea67cc3677c381ac4d +Subproject commit 18b71b0f948344af581bc7bb7723a960f4662169 -- 2.17.1 From eeefaa6e18ac04c40243f6b7469b6a2364fffdfe Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Mon, 18 May 2020 10:25:13 +0200 Subject: [PATCH 7/7] Use project-inner method for fetching flyway table name --- .../java/bubble/service/dbfilter/DatabaseFilterService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java b/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java index 2d41cdda..9ccbefca 100644 --- a/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java +++ b/bubble-server/src/main/java/bubble/service/dbfilter/DatabaseFilterService.java @@ -24,7 +24,6 @@ import org.cobbzilla.util.system.CommandResult; import org.cobbzilla.util.system.CommandShell; import org.cobbzilla.wizard.model.Identifiable; import org.cobbzilla.wizard.server.config.DatabaseConfiguration; -import org.flywaydb.core.Flyway; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -42,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 { @@ -93,7 +93,7 @@ public class DatabaseFilterService { log.info("copyDatabase: dumping flyway schema history data for current database to file: " + abs(flywayHistory)); try (InputStream in = new FileInputStream(configuration.pgDumpDataOnly(flywayHistory, - Flyway.configure().getTable()))) { + getFlywayTableName()))) { log.info("copyDatabase: writing dumped flyway history data to new database " + dbName); final var result = pgExec("psql", dbName, in, null); if (!result.isZeroExitStatus()) { -- 2.17.1