Skip to content

Commit

Permalink
#2270 adding postgres to default profile
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioGii committed Dec 12, 2024
1 parent 3cb3dd8 commit 1f3fc97
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 33 deletions.
6 changes: 5 additions & 1 deletion exampleYmlFiles/docker-compose-latest-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ services:
SYSTEM_MAXFILESIZE: "100"
METRICS_ENABLED: "true"
SYSTEM_GOOGLEVISIBILITY: "true"
SPRING_PROFILES_ACTIVE: postgres
SPRING_DATASOURCE_URL: "jdbc:postgresql://db:5432/stirling_pdf"
SPRING_DATASOURCE_USERNAME: "admin"
SPRING_DATASOURCE_PASSWORD: "stirling"
SPRING_JPA_HIBERNATE_DDL_AUTO: "update"
SPRING_DATASOURCE_DRIVER_CLASS_NAME: "org.postgresql.Driver"
# SPRING_JPA_HIBERNATE_DDL_AUTO: "update"
SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT: "org.hibernate.dialect.PostgreSQLDialect"
# SPRING_JPA_DATABASE_PLATFORM: "org.hibernate.dialect.PostgreSQLDialect"
restart: on-failure:5

db:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@

import lombok.Getter;
import stirling.software.SPDF.model.ApplicationProperties;
import stirling.software.SPDF.model.exception.UnsupportedDriverException;

@Getter
@Configuration
public class DatabaseConfig {

@Autowired private ApplicationProperties applicationProperties;
private final ApplicationProperties applicationProperties;

public DatabaseConfig(@Autowired ApplicationProperties applicationProperties) {
this.applicationProperties = applicationProperties;
}

@Bean
public Connection connection() throws SQLException {
ApplicationProperties.Datasource datasource =
applicationProperties.getSystem().getDatasource();

DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriverClassName()));
dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriver()));
dataSourceBuilder.url(datasource.getUrl());
dataSourceBuilder.username(datasource.getUsername());
dataSourceBuilder.password(datasource.getPassword());
Expand All @@ -34,18 +37,15 @@ public Connection connection() throws SQLException {

private String getDriverClassName(ApplicationProperties.Driver driverName) {
switch (driverName) {
case POSTGRESQL -> {
return "org.postgresql.Driver";
}
case ORACLE -> {
return "oracle.jdbc.OracleDriver";
}
case MY_SQL -> {
return "com.mysql.cj.jdbc.Driver";
}
default ->
throw new UnsupportedDriverException(
"The database driver " + driverName + " is not supported.");
default -> {
return "org.postgresql.Driver";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static class System {
@Data
public static class Datasource {
private String url;
private Driver driverClassName;
private Driver driver;
private String username;
private String password;
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/application-mysql.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.driver=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/stirling_pdf?createDatabaseIfNotExist=true
spring.datasource.username=admin
spring.datasource.password=stirling
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-oracle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.driver=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:stirling_pdf
spring.datasource.username=admin
spring.datasource.password=stirling
Expand Down
9 changes: 0 additions & 9 deletions src/main/resources/application-postgres.properties

This file was deleted.

10 changes: 8 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
spring.profiles.active=postgres

multipart.enabled=true

logging.level.org.springframework=WARN
Expand Down Expand Up @@ -41,6 +39,14 @@ spring.mvc.async.request-timeout=${SYSTEM_CONNECTIONTIMEOUTMILLISECONDS:1200000}
#spring.thymeleaf.prefix=file:/customFiles/templates/,classpath:/templates/
#spring.thymeleaf.cache=false

spring.datasource.driver=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.open-in-view=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
server.servlet.session.timeout=30m
# Change the default URL path for OpenAPI JSON
springdoc.api-docs.path=/v1/api-docs
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/settings.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ legal:
impressum: '' # URL to the impressum of your application (e.g. https://example.com/impressum). Empty string to disable or filename to load from local file in static folder

system:
springProfilesActive: postgres # set the default environment (e.g. 'postgres', 'mysql', 'oracle')
springProfilesActive: '' # set the default environment (e.g. 'mysql', 'oracle')
defaultLocale: en-US # set the default language (e.g. 'de-DE', 'fr-FR', etc)
googlevisibility: false # 'true' to allow Google visibility (via robots.txt), 'false' to disallow
enableAlphaFunctionality: false # set to enable functionality which might need more testing before it fully goes live (this feature might make no changes)
Expand All @@ -88,7 +88,7 @@ system:
enableAnalytics: undefined # set to 'true' to enable analytics, set to 'false' to disable analytics; for enterprise users, this is set to true
datasource:
url: jdbc:postgresql://localhost:5432/postgres
driverClassName: postgresql
driver: postgresql
username: postgres
password: postgres

Expand Down

0 comments on commit 1f3fc97

Please sign in to comment.