Skip to content

Commit 1f44d8e

Browse files
committed
Introduce quarkus.datasource.devservices.init-privileged-script-path config
This is to separate scripts run as a privileged user from the app user
1 parent 4ecfbf9 commit 1f44d8e

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

docs/src/main/asciidoc/flyway.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ quarkus.openshift.init-task-defaults.wait-for-container.image=my/wait-for-image:
454454
=== Oracle: Multiple schemas in Dev Services
455455

456456
When having multiple schemas in Oracle, you can use the `quarkus.flyway.schemas` property to specify the schemas that Flyway should manage.
457-
However, because this is executed in the DB as the `quarkus` user, you need to either give DBA privileges to the user that is executing the migration (`quarkus`) or perform the necessary DDLs before the Dev Service starts. This is done with the `quarkus.datasource.devservices.init-script-path` configuration.
457+
However, because this is executed in the DB as the `quarkus` user, you need to either give DBA privileges to the user that is executing the migration (`quarkus`) or perform the necessary DDLs before the Dev Service starts. This is done with the `quarkus.datasource.devservices.init-privileged-script-path` configuration.
458458

459459
==== Giving DBA privileges to the user
460460

@@ -470,5 +470,5 @@ GRANT DBA TO quarkus;
470470

471471
[source,properties]
472472
----
473-
quarkus.datasource.devservices.init-script-path=001-devservice-init.sql
473+
quarkus.datasource.devservices.init-privileged-script-path=001-devservice-init.sql
474474
----

extensions/datasource/deployment-spi/src/main/java/io/quarkus/datasource/deployment/spi/DevServicesDatasourceContainerConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class DevServicesDatasourceContainerConfig {
1717
private final Optional<String> username;
1818
private final Optional<String> password;
1919
private final Optional<List<String>> initScriptPath;
20+
private final Optional<List<String>> initPrivilegedScriptPath;
2021
private final Map<String, String> volumes;
2122
private final boolean reuse;
2223
private final boolean showLogs;
@@ -31,6 +32,7 @@ public DevServicesDatasourceContainerConfig(Optional<String> imageName,
3132
Optional<String> username,
3233
Optional<String> password,
3334
Optional<List<String>> initScriptPath,
35+
Optional<List<String>> initPrivilegedScriptPath,
3436
Map<String, String> volumes,
3537
boolean reuse,
3638
boolean showLogs) {
@@ -44,6 +46,7 @@ public DevServicesDatasourceContainerConfig(Optional<String> imageName,
4446
this.username = username;
4547
this.password = password;
4648
this.initScriptPath = initScriptPath;
49+
this.initPrivilegedScriptPath = initPrivilegedScriptPath;
4750
this.volumes = volumes;
4851
this.reuse = reuse;
4952
this.showLogs = showLogs;
@@ -89,6 +92,10 @@ public Optional<List<String>> getInitScriptPath() {
8992
return initScriptPath;
9093
}
9194

95+
public Optional<List<String>> getInitPrivilegedScriptPath() {
96+
return initPrivilegedScriptPath;
97+
}
98+
9299
public boolean isShowLogs() {
93100
return showLogs;
94101
}

extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private static Map<String, Object> buildMapFromBuildConfig(DataSourcesBuildTimeC
189189
res.put(name + ".devservices.db-name", config.devservices().dbName());
190190
res.put(name + ".devservices.image-name", config.devservices().imageName());
191191
res.put(name + ".devservices.init-script-path", config.devservices().initScriptPath());
192+
res.put(name + ".devservices.init-privileged-script-path", config.devservices().initPrivilegedScriptPath());
192193
res.put(name + ".devservices.password", config.devservices().password());
193194
res.put(name + ".devservices.port", config.devservices().port());
194195
res.put(name + ".devservices.properties", config.devservices().properties());
@@ -301,6 +302,7 @@ private RunningDevService startDevDb(
301302
dataSourceBuildTimeConfig.devservices().username(),
302303
dataSourceBuildTimeConfig.devservices().password(),
303304
dataSourceBuildTimeConfig.devservices().initScriptPath(),
305+
dataSourceBuildTimeConfig.devservices().initPrivilegedScriptPath(),
304306
dataSourceBuildTimeConfig.devservices().volumes(),
305307
dataSourceBuildTimeConfig.devservices().reuse(),
306308
dataSourceBuildTimeConfig.devservices().showLogs());

extensions/datasource/runtime/src/main/java/io/quarkus/datasource/runtime/DevServicesBuildTimeConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ public interface DevServicesBuildTimeConfig {
8888
*/
8989
Optional<List<@WithConverter(TrimmedStringConverter.class) String>> initScriptPath();
9090

91+
/**
92+
* The paths to SQL scripts to be loaded from the classpath and applied to the Dev Service database using the SYS privileged
93+
* user.
94+
* Not all databases provide a privileged user. In these cases, the property is ignored.
95+
* This has no effect if the provider is not a container-based database, such as H2 or Derby.
96+
*/
97+
Optional<List<@WithConverter(TrimmedStringConverter.class) String>> initPrivilegedScriptPath();
98+
9199
/**
92100
* The volumes to be mapped to the container.
93101
* <p>

extensions/devservices/oracle/src/main/java/io/quarkus/devservices/oracle/deployment/OracleDevServicesProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
9090

9191
containerConfig.getAdditionalJdbcUrlProperties().forEach(container::withUrlParam);
9292
containerConfig.getCommand().ifPresent(container::setCommand);
93-
if (containerConfig.getInitScriptPath().isPresent()) {
94-
for (String initScript : containerConfig.getInitScriptPath().get()) {
93+
containerConfig.getInitScriptPath().ifPresent(container::withInitScripts);
94+
if (containerConfig.getInitPrivilegedScriptPath().isPresent()) {
95+
for (String initScript : containerConfig.getInitPrivilegedScriptPath().get()) {
9596
container.withCopyFileToContainer(MountableFile.forClasspathResource(initScript),
9697
"/container-entrypoint-startdb.d/" + initScript);
9798
}

0 commit comments

Comments
 (0)