From 99b830ebe7bee9e8ee1f2bdff981fa24845c3ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Mon, 25 Apr 2016 22:49:59 +1000 Subject: [PATCH] Support different schema/data DB script users Allow data and/or schema scripts to be run by different database users. Fixes gh-5402 Closes gh-5788 --- .../jdbc/DataSourceInitializer.java | 22 ++++++-- .../jdbc/DataSourceProperties.java | 53 +++++++++++++++++++ .../jdbc/DataSourceInitializerTests.java | 45 ++++++++++++++++ .../jdbc/DataSourcePropertiesTests.java | 19 +++++++ .../appendix-application-properties.adoc | 4 ++ 5 files changed, 138 insertions(+), 5 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java index 17ef8fdaec6..e8f76ffe121 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ import org.springframework.util.StringUtils; * * @author Dave Syer * @author Phillip Webb + * @author Eddú Meléndez * @since 1.1.0 * @see DataSourceAutoConfiguration */ @@ -78,7 +79,9 @@ class DataSourceInitializer implements ApplicationListener scripts = getScripts(this.properties.getSchema(), "schema"); if (!scripts.isEmpty()) { - runScripts(scripts); + String username = this.properties.getSchemaUsername(); + String password = this.properties.getSchemaPassword(); + runScripts(scripts, username, password); try { this.applicationContext .publishEvent(new DataSourceInitializedEvent(this.dataSource)); @@ -111,7 +114,9 @@ class DataSourceInitializer implements ApplicationListener scripts = getScripts(this.properties.getData(), "data"); - runScripts(scripts); + String username = this.properties.getDataUsername(); + String password = this.properties.getDataPassword(); + runScripts(scripts, username, password); } private List getScripts(String locations, String fallback) { @@ -141,7 +146,7 @@ class DataSourceInitializer implements ApplicationListener resources) { + private void runScripts(List resources, String username, String password) { if (resources.isEmpty()) { return; } @@ -154,7 +159,14 @@ class DataSourceInitializer implements ApplicationListener