From d8076dfca54e1d201a0733259a1b585b39fe0cbf Mon Sep 17 00:00:00 2001 From: Mahesh Panchaksharaiah Date: Mon, 12 Oct 2020 09:09:35 +0530 Subject: [PATCH] Do not sync all changelog tables * This is to support syncing data between databases which are already migrated and GoCD 20.5.0 compliant. --- README.md | 4 ++-- src/main/java/com/thoughtworks/go/dbsync/DbSync.java | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2190f19..5e57229 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ Know more about GoCD support for multiple databases [here](https://docs.gocd.org * As part of migrating data from a older GoCD `v20.4.0` (or below) to the GoCD `v20.5.0` database, users can convert/sync data from one database to another. This allows GoCD users to switch from any of the existing database to `H2`, `PostgreSQL` or `MySQL` database. -### Note: This tool currently supports only migration of data from older GoCD database `v20.4.0` (or below) to the GoCD `v20.5.0` compatible database. Post migration, you cannot use this tool to sync data between different databases. +* For databases which are already migrated and are GoCD `v20.5.0` compliant, this tool can be used to sync data to a new database post the initial migration to GoCD `v20.5.0`. +E.g Sync data from a GoCD `v20.5.0` H2 database to a new PostgreSQL database. Verifyied to work till GoCD `v20.8.0`. ## Supported Databases @@ -20,7 +21,6 @@ Know more about GoCD support for multiple databases [here](https://docs.gocd.org * PostgreSQL (`9.6` and above) * MySQL (`8.0`) - ## Installation #### 1. From The Source: diff --git a/src/main/java/com/thoughtworks/go/dbsync/DbSync.java b/src/main/java/com/thoughtworks/go/dbsync/DbSync.java index fa7c972..769b1ea 100644 --- a/src/main/java/com/thoughtworks/go/dbsync/DbSync.java +++ b/src/main/java/com/thoughtworks/go/dbsync/DbSync.java @@ -394,9 +394,10 @@ private static Map listTables(BasicDataSource sourceDataSource) .fetch(); for (Record1 record : result) { - String value = record.getValue(field); - if (!value.equalsIgnoreCase("CHANGELOG")) { - tables.put(value, using(connection).fetchCount(table(value))); + String tableName = record.getValue(field); + + if (!isChangeLogTable(tableName)) { + tables.put(tableName, using(connection).fetchCount(table(tableName))); } } }); @@ -404,4 +405,9 @@ private static Map listTables(BasicDataSource sourceDataSource) return tables; } + private static boolean isChangeLogTable(String tableName) { + return tableName.equalsIgnoreCase("CHANGELOG") || + tableName.equalsIgnoreCase("DATABASECHANGELOG") || + tableName.equalsIgnoreCase("DATABASECHANGELOGLOCK"); + } }