From 30139072b200302d2d601f3179e6067d89bcf888 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 06:18:37 +0000 Subject: [PATCH 01/11] Initial plan From 0324ecf44ace31fa34cd087a1a32747cb1a446a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 06:29:48 +0000 Subject: [PATCH 02/11] feat: add Flyway integration to BraintreeActivator for automatic DB table creation Co-authored-by: reshmabidikar <85998496+reshmabidikar@users.noreply.github.com> --- pom.xml | 5 ++ .../braintree/core/BraintreeActivator.java | 7 +++ .../V20200101000000__create_tables.sql | 48 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/main/resources/migration/V20200101000000__create_tables.sql diff --git a/pom.xml b/pom.xml index f71f808..a9044ab 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,11 @@ + + org.flywaydb + flyway-core + 7.7.3 + com.braintreepayments.gateway braintree-java diff --git a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java index 3e04133..b52c4ec 100644 --- a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java +++ b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java @@ -21,6 +21,7 @@ import javax.servlet.Servlet; import javax.servlet.http.HttpServlet; +import org.flywaydb.core.Flyway; import org.killbill.billing.osgi.api.Healthcheck; import org.killbill.billing.osgi.api.OSGIPluginProperties; import org.killbill.billing.osgi.libs.killbill.KillbillActivatorBase; @@ -49,6 +50,12 @@ public void start(final BundleContext context) throws Exception { super.start(context); final String region = PluginEnvironmentConfig.getRegion(configProperties.getProperties()); + // Run Flyway migrations to create/update database tables + final Flyway flyway = Flyway.configure(getClass().getClassLoader()) + .dataSource(dataSource.getDataSource()) + .locations("classpath:migration") + .load(); + flyway.migrate(); // Register an event listener for plugin configuration braintreeConfigurationHandler = new BraintreeConfigPropertiesConfigurationHandler(region, PLUGIN_NAME, killbillAPI); diff --git a/src/main/resources/migration/V20200101000000__create_tables.sql b/src/main/resources/migration/V20200101000000__create_tables.sql new file mode 100644 index 0000000..8f6e8fc --- /dev/null +++ b/src/main/resources/migration/V20200101000000__create_tables.sql @@ -0,0 +1,48 @@ +/* + * Copyright 2021 Wovenware, Inc + * + * Wovenware licenses this file to you under the Apache License, version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +create table braintree_responses ( + record_id serial +, kb_account_id char(36) not null +, kb_payment_id char(36) not null +, kb_payment_transaction_id char(36) not null +, transaction_type varchar(32) not null +, amount numeric(15,9) +, currency char(3) +, braintree_id varchar(255) not null +, additional_data longtext default null +, created_date datetime not null +, kb_tenant_id char(36) not null +, primary key(record_id) +) /*! CHARACTER SET utf8 COLLATE utf8_bin */; +create index braintree_responses_kb_payment_id on braintree_responses(kb_payment_id); +create index braintree_responses_kb_payment_transaction_id on braintree_responses(kb_payment_transaction_id); +create index braintree_responses_braintree_id on braintree_responses(braintree_id); + +create table braintree_payment_methods ( + record_id serial +, kb_account_id char(36) not null +, kb_payment_method_id char(36) not null +, braintree_id varchar(255) not null +, is_deleted smallint not null default 0 +, additional_data longtext default null +, created_date datetime not null +, updated_date datetime not null +, kb_tenant_id char(36) not null +, primary key(record_id) +) /*! CHARACTER SET utf8 COLLATE utf8_bin */; +create unique index braintree_payment_methods_kb_payment_id on braintree_payment_methods(kb_payment_method_id); +create index braintree_payment_methods_braintree_id on braintree_payment_methods(braintree_id); From ecd8a95e0e0a6dbbf25e6fca79297c3ff5e4a27f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 06:47:44 +0000 Subject: [PATCH 03/11] fix: set baselineOnMigrate(true) to handle pre-existing schemas without Flyway history Co-authored-by: reshmabidikar <85998496+reshmabidikar@users.noreply.github.com> --- .../billing/plugin/braintree/core/BraintreeActivator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java index b52c4ec..d5ddc61 100644 --- a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java +++ b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java @@ -54,6 +54,7 @@ public void start(final BundleContext context) throws Exception { final Flyway flyway = Flyway.configure(getClass().getClassLoader()) .dataSource(dataSource.getDataSource()) .locations("classpath:migration") + .baselineOnMigrate(true) .load(); flyway.migrate(); From 6dec50d1e620c1e9dd1b3c4b9e593656f592602b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 07:06:16 +0000 Subject: [PATCH 04/11] feat: add configurable runMigrations flag to conditionally run Flyway migrations Co-authored-by: reshmabidikar <85998496+reshmabidikar@users.noreply.github.com> --- .../plugin/braintree/core/BraintreeActivator.java | 14 ++++++++------ .../braintree/core/BraintreeConfigProperties.java | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java index d5ddc61..373e564 100644 --- a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java +++ b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java @@ -51,12 +51,14 @@ public void start(final BundleContext context) throws Exception { final String region = PluginEnvironmentConfig.getRegion(configProperties.getProperties()); // Run Flyway migrations to create/update database tables - final Flyway flyway = Flyway.configure(getClass().getClassLoader()) - .dataSource(dataSource.getDataSource()) - .locations("classpath:migration") - .baselineOnMigrate(true) - .load(); - flyway.migrate(); + if (BraintreeConfigProperties.shouldRunMigrations(configProperties.getProperties())) { + final Flyway flyway = Flyway.configure(getClass().getClassLoader()) + .dataSource(dataSource.getDataSource()) + .locations("classpath:migration") + .baselineOnMigrate(true) + .load(); + flyway.migrate(); + } // Register an event listener for plugin configuration braintreeConfigurationHandler = new BraintreeConfigPropertiesConfigurationHandler(region, PLUGIN_NAME, killbillAPI); diff --git a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeConfigProperties.java b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeConfigProperties.java index 983142b..e56aea1 100644 --- a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeConfigProperties.java +++ b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeConfigProperties.java @@ -42,7 +42,8 @@ public class BraintreeConfigProperties { private static final String KEY_VALUE_DELIMITER = "#"; private static final String DEFAULT_CONNECTION_TIMEOUT = "30000"; private static final String DEFAULT_READ_TIMEOUT = "60000"; - + private static final String DEFAULT_RUN_MIGRATIONS = "true"; + private final String region; private final String btEnvironment; private final String btMerchantId; @@ -54,7 +55,8 @@ public class BraintreeConfigProperties { private final Map paymentMethodToExpirationPeriod = new LinkedHashMap(); private final String chargeDescription; private final String chargeStatementDescriptor; - + private final boolean runMigrations; + public BraintreeConfigProperties(final Properties properties, final String region) { this.region = region; this.btEnvironment = properties.getProperty(PROPERTY_PREFIX + "btEnvironment", "sandbox"); @@ -66,6 +68,7 @@ public BraintreeConfigProperties(final Properties properties, final String regio this.pendingPaymentExpirationPeriod = readPendingExpirationProperty(properties); this.chargeDescription = Ascii.truncate(MoreObjects.firstNonNull(properties.getProperty(PROPERTY_PREFIX + "chargeDescription"), "Kill Bill charge"), 22, "..."); this.chargeStatementDescriptor = Ascii.truncate(MoreObjects.firstNonNull(properties.getProperty(PROPERTY_PREFIX + "chargeStatementDescriptor"), "Kill Bill charge"), 22, "..."); + this.runMigrations = Boolean.parseBoolean(properties.getProperty(PROPERTY_PREFIX + "runMigrations", DEFAULT_RUN_MIGRATIONS)); } public String getRegion() { @@ -116,6 +119,14 @@ public String getChargeStatementDescriptor() { return chargeStatementDescriptor; } + public boolean isRunMigrations() { + return runMigrations; + } + + public static boolean shouldRunMigrations(final Properties properties) { + return Boolean.parseBoolean(properties.getProperty(PROPERTY_PREFIX + "runMigrations", DEFAULT_RUN_MIGRATIONS)); + } + public Period getPendingPaymentExpirationPeriod(@Nullable final String paymentMethod) { if (paymentMethod != null && paymentMethodToExpirationPeriod.get(paymentMethod.toLowerCase()) != null) { return paymentMethodToExpirationPeriod.get(paymentMethod.toLowerCase()); From f3649b77fac5eee4c3135da7bb575efc05eda32b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 08:11:53 +0000 Subject: [PATCH 05/11] feat: rename Flyway schema history table to braintree_schema_history Co-authored-by: reshmabidikar <85998496+reshmabidikar@users.noreply.github.com> --- .../billing/plugin/braintree/core/BraintreeActivator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java index 373e564..a58fd61 100644 --- a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java +++ b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java @@ -55,6 +55,7 @@ public void start(final BundleContext context) throws Exception { final Flyway flyway = Flyway.configure(getClass().getClassLoader()) .dataSource(dataSource.getDataSource()) .locations("classpath:migration") + .table("braintree_schema_history") .baselineOnMigrate(true) .load(); flyway.migrate(); From 75212285d6c43647d4f636ffceb728b913884637 Mon Sep 17 00:00:00 2001 From: Reshma Bidikar Date: Mon, 9 Mar 2026 13:52:34 +0530 Subject: [PATCH 06/11] Minor cleanup --- pom.xml | 10 +++---- .../braintree/core/BraintreeActivator.java | 26 ++++++++++++------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index a9044ab..6575bf8 100644 --- a/pom.xml +++ b/pom.xml @@ -53,11 +53,6 @@ - - org.flywaydb - flyway-core - 7.7.3 - com.braintreepayments.gateway braintree-java @@ -117,6 +112,11 @@ org.apache.felix.framework provided + + org.flywaydb + flyway-core + 7.7.3 + org.jooby jooby diff --git a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java index a58fd61..15bd60a 100644 --- a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java +++ b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java @@ -50,16 +50,7 @@ public void start(final BundleContext context) throws Exception { super.start(context); final String region = PluginEnvironmentConfig.getRegion(configProperties.getProperties()); - // Run Flyway migrations to create/update database tables - if (BraintreeConfigProperties.shouldRunMigrations(configProperties.getProperties())) { - final Flyway flyway = Flyway.configure(getClass().getClassLoader()) - .dataSource(dataSource.getDataSource()) - .locations("classpath:migration") - .table("braintree_schema_history") - .baselineOnMigrate(true) - .load(); - flyway.migrate(); - } + runMigrationsIfEnabled(); // Register an event listener for plugin configuration braintreeConfigurationHandler = new BraintreeConfigPropertiesConfigurationHandler(region, PLUGIN_NAME, killbillAPI); @@ -119,4 +110,19 @@ private void registerHealthcheck(final BundleContext context, final Healthcheck props.put(OSGIPluginProperties.PLUGIN_NAME_PROP, PLUGIN_NAME); registrar.registerService(context, Healthcheck.class, healthcheck, props); } + + private void runMigrationsIfEnabled() { + // Run Flyway migrations to create/update database tables + if (BraintreeConfigProperties.shouldRunMigrations(configProperties.getProperties())) { + final Flyway flyway = Flyway.configure(getClass().getClassLoader()) + .dataSource(dataSource.getDataSource()) + .locations("classpath:migration") + .table("braintree_schema_history") + .baselineOnMigrate(true) + .load(); + flyway.migrate(); + } else { + logger.info("Skipping Flyway migrations as 'runMigrations' is set to false"); + } + } } From 49f1f30e1f75d4fe7dadbfa667af83898e8b2eec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 08:27:43 +0000 Subject: [PATCH 07/11] feat: move migrations into db-specific sub-directories (mysql/postgresql) Co-authored-by: reshmabidikar <85998496+reshmabidikar@users.noreply.github.com> --- .../braintree/core/BraintreeActivator.java | 2 +- .../V20200101000000__create_tables.sql | 0 ...s_default_to_braintree_payment_methods.sql | 0 .../V20200101000000__create_domains.sql | 21 +++++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) rename src/main/resources/migration/{ => mysql}/V20200101000000__create_tables.sql (100%) rename src/main/resources/migration/{ => mysql}/V20200127071214__add_is_default_to_braintree_payment_methods.sql (100%) create mode 100644 src/main/resources/migration/postgresql/V20200101000000__create_domains.sql diff --git a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java index 15bd60a..b646a03 100644 --- a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java +++ b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java @@ -116,7 +116,7 @@ private void runMigrationsIfEnabled() { if (BraintreeConfigProperties.shouldRunMigrations(configProperties.getProperties())) { final Flyway flyway = Flyway.configure(getClass().getClassLoader()) .dataSource(dataSource.getDataSource()) - .locations("classpath:migration") + .locations("classpath:migration/mysql") .table("braintree_schema_history") .baselineOnMigrate(true) .load(); diff --git a/src/main/resources/migration/V20200101000000__create_tables.sql b/src/main/resources/migration/mysql/V20200101000000__create_tables.sql similarity index 100% rename from src/main/resources/migration/V20200101000000__create_tables.sql rename to src/main/resources/migration/mysql/V20200101000000__create_tables.sql diff --git a/src/main/resources/migration/V20200127071214__add_is_default_to_braintree_payment_methods.sql b/src/main/resources/migration/mysql/V20200127071214__add_is_default_to_braintree_payment_methods.sql similarity index 100% rename from src/main/resources/migration/V20200127071214__add_is_default_to_braintree_payment_methods.sql rename to src/main/resources/migration/mysql/V20200127071214__add_is_default_to_braintree_payment_methods.sql diff --git a/src/main/resources/migration/postgresql/V20200101000000__create_domains.sql b/src/main/resources/migration/postgresql/V20200101000000__create_domains.sql new file mode 100644 index 0000000..897ce5d --- /dev/null +++ b/src/main/resources/migration/postgresql/V20200101000000__create_domains.sql @@ -0,0 +1,21 @@ +/* + * Copyright 2020-2020 Equinix, Inc + * Copyright 2014-2020 The Billing Project, LLC + * + * The Billing Project licenses this file to you under the Apache License, version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +/* We cannot use timestamp in MySQL because of the implicit TimeZone conversions it does behind the scenes */ +CREATE DOMAIN datetime AS timestamp without time zone; + +CREATE DOMAIN longtext AS text; From 6d96df62b268a8dbe790353015268a6994436235 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 08:38:29 +0000 Subject: [PATCH 08/11] feat: detect DB engine at runtime and route Flyway to the correct migration directory Co-authored-by: reshmabidikar <85998496+reshmabidikar@users.noreply.github.com> --- .../braintree/core/BraintreeActivator.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java index b646a03..2e8833f 100644 --- a/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java +++ b/src/main/java/org/killbill/billing/plugin/braintree/core/BraintreeActivator.java @@ -16,6 +16,7 @@ package org.killbill.billing.plugin.braintree.core; +import java.sql.SQLException; import java.util.Hashtable; import javax.servlet.Servlet; @@ -34,6 +35,8 @@ import org.killbill.billing.plugin.core.config.PluginEnvironmentConfig; import org.killbill.billing.plugin.core.resources.jooby.PluginApp; import org.killbill.billing.plugin.core.resources.jooby.PluginAppBuilder; +import org.killbill.billing.plugin.dao.PluginDao; +import org.killbill.billing.plugin.dao.PluginDao.DBEngine; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -114,9 +117,31 @@ private void registerHealthcheck(final BundleContext context, final Healthcheck private void runMigrationsIfEnabled() { // Run Flyway migrations to create/update database tables if (BraintreeConfigProperties.shouldRunMigrations(configProperties.getProperties())) { + DBEngine dbEngine; + try { + dbEngine = PluginDao.getDBEngine(dataSource.getDataSource()); + } catch (final SQLException e) { + logger.warn("Unable to determine database engine, defaulting to MySQL migrations", e); + dbEngine = DBEngine.MYSQL; + } + + final String locations; + switch (dbEngine) { + case POSTGRESQL: + locations = "classpath:migration/postgresql"; + break; + case GENERIC: + case H2: + case MYSQL: + default: + // H2 and GENERIC use MySQL-compatible migration scripts + locations = "classpath:migration/mysql"; + break; + } + final Flyway flyway = Flyway.configure(getClass().getClassLoader()) .dataSource(dataSource.getDataSource()) - .locations("classpath:migration/mysql") + .locations(locations) .table("braintree_schema_history") .baselineOnMigrate(true) .load(); From 38d2d0192c1d8d5bac55469afc737d02b3e7c38b Mon Sep 17 00:00:00 2001 From: Reshma Bidikar Date: Mon, 9 Mar 2026 14:37:47 +0530 Subject: [PATCH 09/11] Fix migrations --- .../V20200101000000__create_tables.sql | 55 +++++++++++++++++++ ..._default_to_braintree_payment_methods.sql} | 5 +- 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/migration/postgresql/V20200101000000__create_tables.sql rename src/main/resources/migration/postgresql/{V20200101000000__create_domains.sql => V20200127071214__add_is_default_to_braintree_payment_methods.sql} (77%) diff --git a/src/main/resources/migration/postgresql/V20200101000000__create_tables.sql b/src/main/resources/migration/postgresql/V20200101000000__create_tables.sql new file mode 100644 index 0000000..c9fd369 --- /dev/null +++ b/src/main/resources/migration/postgresql/V20200101000000__create_tables.sql @@ -0,0 +1,55 @@ +/* + * Copyright 2020-2020 Equinix, Inc + * Copyright 2014-2020 The Billing Project, LLC + * + * The Billing Project licenses this file to you under the Apache License, version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +/* We cannot use timestamp in MySQL because of the implicit TimeZone conversions it does behind the scenes */ +CREATE DOMAIN datetime AS timestamp without time zone; + +CREATE DOMAIN longtext AS text; + +create table braintree_responses ( + record_id serial + , kb_account_id char(36) not null + , kb_payment_id char(36) not null + , kb_payment_transaction_id char(36) not null + , transaction_type varchar(32) not null + , amount numeric(15,9) + , currency char(3) + , braintree_id varchar(255) not null + , additional_data longtext default null + , created_date datetime not null + , kb_tenant_id char(36) not null + , primary key(record_id) +) /*! CHARACTER SET utf8 COLLATE utf8_bin */; +create index braintree_responses_kb_payment_id on braintree_responses(kb_payment_id); +create index braintree_responses_kb_payment_transaction_id on braintree_responses(kb_payment_transaction_id); +create index braintree_responses_braintree_id on braintree_responses(braintree_id); + +create table braintree_payment_methods ( + record_id serial + , kb_account_id char(36) not null + , kb_payment_method_id char(36) not null + , braintree_id varchar(255) not null + , is_deleted smallint not null default 0 + , additional_data longtext default null + , created_date datetime not null + , updated_date datetime not null + , kb_tenant_id char(36) not null + , primary key(record_id) +) /*! CHARACTER SET utf8 COLLATE utf8_bin */; +create unique index braintree_payment_methods_kb_payment_id on braintree_payment_methods(kb_payment_method_id); +create index braintree_payment_methods_braintree_id on braintree_payment_methods(braintree_id); + diff --git a/src/main/resources/migration/postgresql/V20200101000000__create_domains.sql b/src/main/resources/migration/postgresql/V20200127071214__add_is_default_to_braintree_payment_methods.sql similarity index 77% rename from src/main/resources/migration/postgresql/V20200101000000__create_domains.sql rename to src/main/resources/migration/postgresql/V20200127071214__add_is_default_to_braintree_payment_methods.sql index 897ce5d..f806c7e 100644 --- a/src/main/resources/migration/postgresql/V20200101000000__create_domains.sql +++ b/src/main/resources/migration/postgresql/V20200127071214__add_is_default_to_braintree_payment_methods.sql @@ -15,7 +15,4 @@ * under the License. */ -/* We cannot use timestamp in MySQL because of the implicit TimeZone conversions it does behind the scenes */ -CREATE DOMAIN datetime AS timestamp without time zone; - -CREATE DOMAIN longtext AS text; +ALTER TABLE braintree_payment_methods ADD COLUMN is_default SMALLINT NOT NULL DEFAULT 0; \ No newline at end of file From f2105d5d1b14f8b7303bdb1e01d78024b485b4eb Mon Sep 17 00:00:00 2001 From: Reshma Bidikar <85998496+reshmabidikar@users.noreply.github.com> Date: Fri, 13 Mar 2026 10:47:06 +0530 Subject: [PATCH 10/11] Update readme --- README.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d6e3c80..5b3a44e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ A full end-to-end integration demo is available [here](https://github.com/killbi ## Requirements * An active Braintree account is required for using the plugin. A Braintree sandbox account may be used for testing purposes. -* The plugin needs a database. The latest version of the schema can be found [here](https://github.com/killbill/killbill-braintree/tree/master/src/main/resources). +* The plugin needs a database. The database tables are automatically created and updated at plugin startup by default. Alternatively, if you would like to manage the database schema manually, you can disable automatic migrations and use the SQL scripts provided in the (https://github.com/killbill/killbill-braintree/tree/master/src/main/resources/migration)[src/main/resources/migration] directory to create or update the database tables as needed. See the [Configuration](#configuration) section below for details about disabling automatic migrations. + ## Build @@ -73,6 +74,23 @@ Some important notes: * The plugin attempts to load the credentials either from the per-tenant configuration or the Kill Bill properties file while the unit tests require the properties to be set as environment variables. * In order to facilitate automated testing, you should disable all fraud detection within your sandbox account. These can generate gateway rejection errors when processing multiple test transactions. In particular make sure to disable [Duplicate Transaction Checking](https://articles.braintreepayments.com/control-panel/transactions/duplicate-checking#configuring-duplicate-transaction-checking). +In addition, the `org.killbill.billing.plugin.braintree.runMigrations` property can be used to control Flyway DB migrations at plugin startup. This property eliminates the need to manually install or update the database tables, as the plugin will handle schema setup automatically. + +Default value: + +```properties +org.killbill.billing.plugin.braintree.runMigrations=true +``` + +To skip automatic migrations (for example, if you prefer to manage the database schema manually), set: + +```properties +org.killbill.billing.plugin.braintree.runMigrations=false +``` + + +When `org.killbill.billing.plugin.braintree.runMigrations` is disabled, ensure that the required database tables are created manually using the SQL scripts provided in the (https://github.com/killbill/killbill-braintree/tree/master/src/main/resources/migration)[src/main/resources/migration] directory. + ## Testing 1. Ensure that the plugin is installed and configured as explained above. @@ -223,6 +241,3 @@ curl -v \ -H "X-Killbill-Comment: demo" \ "http://127.0.0.1:8080/1.0/kb/accounts//paymentMethods/refresh" ``` - - - From 23645831086c87b14a7ac0f73606fa5cc4f5ba80 Mon Sep 17 00:00:00 2001 From: Reshma Bidikar <85998496+reshmabidikar@users.noreply.github.com> Date: Fri, 13 Mar 2026 12:02:11 +0530 Subject: [PATCH 11/11] Fix for postgres migrations --- src/main/resources/ddl-postgresql.sql | 10 ++++++++-- .../postgresql/V20200101000000__create_tables.sql | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/resources/ddl-postgresql.sql b/src/main/resources/ddl-postgresql.sql index 897ce5d..a9da5c2 100644 --- a/src/main/resources/ddl-postgresql.sql +++ b/src/main/resources/ddl-postgresql.sql @@ -16,6 +16,12 @@ */ /* We cannot use timestamp in MySQL because of the implicit TimeZone conversions it does behind the scenes */ -CREATE DOMAIN datetime AS timestamp without time zone; +DO $$ BEGIN + CREATE DOMAIN datetime AS timestamp without time zone; +EXCEPTION WHEN duplicate_object THEN NULL; +END $$; -CREATE DOMAIN longtext AS text; +DO $$ BEGIN + CREATE DOMAIN longtext AS text; +EXCEPTION WHEN duplicate_object THEN NULL; +END $$; diff --git a/src/main/resources/migration/postgresql/V20200101000000__create_tables.sql b/src/main/resources/migration/postgresql/V20200101000000__create_tables.sql index c9fd369..2037644 100644 --- a/src/main/resources/migration/postgresql/V20200101000000__create_tables.sql +++ b/src/main/resources/migration/postgresql/V20200101000000__create_tables.sql @@ -16,9 +16,15 @@ */ /* We cannot use timestamp in MySQL because of the implicit TimeZone conversions it does behind the scenes */ -CREATE DOMAIN datetime AS timestamp without time zone; +DO $$ BEGIN + CREATE DOMAIN datetime AS timestamp without time zone; +EXCEPTION WHEN duplicate_object THEN NULL; +END $$; -CREATE DOMAIN longtext AS text; +DO $$ BEGIN + CREATE DOMAIN longtext AS text; +EXCEPTION WHEN duplicate_object THEN NULL; +END $$; create table braintree_responses ( record_id serial