Skip to content

Commit 91b2851

Browse files
committed
refactoring for local development
1 parent 0859630 commit 91b2851

File tree

3 files changed

+37
-56
lines changed

3 files changed

+37
-56
lines changed

docker-compose.yml

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,59 +35,6 @@ services:
3535
timeout: 5s
3636
retries: 5
3737

38-
app:
39-
build: ./
40-
environment:
41-
OTEL_SERVICE_NAME: "PetClinic"
42-
OTEL_EXPORTER_OTLP_ENDPOINT: "http://host.docker.internal:5050"
43-
# Logs are disabled by default
44-
OTEL_LOGS_EXPORTER: "otlp"
45-
# Digma entries
46-
CODE_PACKAGE_PREFIXES: "org.springframework.samples.petclinic"
47-
DEPLOYMENT_ENV: "SAMPLE_ENV"
48-
SPRING_PROFILES_ACTIVE: postgres
49-
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/petclinic
50-
SPRING_DATASOURCE_USERNAME: postgres
51-
SPRING_DATASOURCE_PASSWORD: postgres
52-
healthcheck:
53-
test: [ "CMD", "curl", "-f", "http://localhost:9753/" ]
54-
interval: 20s
55-
timeout: 10s
56-
retries: 4
57-
start_period: 5s
58-
ports:
59-
- "9753:9753"
60-
entrypoint: java -jar -javaagent:/opentelemetry-javaagent.jar -Dotel.javaagent.extensions=/digma-otel-agent-extension.jar app.jar
61-
depends_on:
62-
postgres:
63-
condition: service_healthy
64-
extra_hosts:
65-
- "host.docker.internal:host-gateway"
66-
67-
tester:
68-
build: ./
69-
environment:
70-
OTEL_SERVICE_NAME: "PetClinicTester"
71-
OTEL_EXPORTER_OTLP_ENDPOINT: "http://host.docker.internal:5050"
72-
# Logs are disabled by default
73-
OTEL_LOGS_EXPORTER: "otlp"
74-
PETSHOP_URL: "http://app:9753"
75-
# Digma entries
76-
CODE_PACKAGE_PREFIXES: "org.springframework.samples.petclinic"
77-
DEPLOYMENT_ENV: "SAMPLE_ENV"
78-
SPRING_PROFILES_ACTIVE: postgres
79-
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/petclinic
80-
SPRING_DATASOURCE_USERNAME: postgres
81-
SPRING_DATASOURCE_PASSWORD: postgres
82-
entrypoint: java -cp app.jar -Dloader.main=petclinic.client.ClientTester org.springframework.boot.loader.PropertiesLauncher
83-
depends_on:
84-
app:
85-
condition: service_healthy
86-
postgres:
87-
condition: service_healthy
88-
extra_hosts:
89-
- "host.docker.internal:host-gateway"
90-
9138
volumes:
9239
postgres_data:
9340
mysql_data:

src/main/java/org/springframework/samples/petclinic/patientrecords/PatientRecordDataService.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.slf4j.LoggerFactory;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.beans.factory.annotation.Qualifier;
8+
import org.springframework.beans.factory.annotation.Value;
89
import org.springframework.context.annotation.Profile;
910
import org.springframework.samples.petclinic.model.PatientRecord;
1011
import org.springframework.stereotype.Service;
@@ -15,6 +16,7 @@
1516
import org.springframework.transaction.support.DefaultTransactionDefinition;
1617
import org.springframework.jdbc.core.JdbcTemplate;
1718

19+
import jakarta.annotation.PostConstruct;
1820
import java.time.LocalDateTime;
1921
import java.time.ZoneId;
2022
import java.util.ArrayList;
@@ -34,6 +36,9 @@ public class PatientRecordDataService {
3436
private final JdbcTemplate mysqlJdbcTemplate;
3537
private final PlatformTransactionManager mysqlTransactionManager;
3638

39+
@Value("${app.patient.records.auto-init:false}")
40+
private boolean autoInitEnabled;
41+
3742
// List of veterinary treatment types
3843
private static final List<String> TREATMENT_TYPES = List.of(
3944
"Annual Wellness Exam", "Vaccination (Rabies)", "Vaccination (DHPP)", "Vaccination (FVRCP)",
@@ -55,6 +60,35 @@ public PatientRecordDataService(PatientRecordRepository repository,
5560
this.mysqlTransactionManager = mysqlTransactionManager;
5661
}
5762

63+
@PostConstruct
64+
public void initializeSchema() {
65+
if (autoInitEnabled) {
66+
logger.info("Auto-initialization enabled - creating patient_records table if it doesn't exist");
67+
try {
68+
String createTableSql =
69+
"CREATE TABLE IF NOT EXISTS patient_records (" +
70+
"id INT AUTO_INCREMENT PRIMARY KEY," +
71+
"treatment_type VARCHAR(255) NOT NULL," +
72+
"patient_weight INT NOT NULL," +
73+
"visit_date TIMESTAMP NOT NULL," +
74+
"treatment_completed BOOLEAN NOT NULL," +
75+
"medical_notes TEXT," +
76+
"INDEX idx_treatment_type (treatment_type)," +
77+
"INDEX idx_visit_date (visit_date)," +
78+
"INDEX idx_treatment_completed (treatment_completed)" +
79+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
80+
81+
mysqlJdbcTemplate.execute(createTableSql);
82+
logger.info("Patient records table initialized successfully");
83+
} catch (Exception e) {
84+
logger.error("Failed to initialize patient records schema", e);
85+
throw new RuntimeException("Failed to initialize patient records schema: " + e.getMessage(), e);
86+
}
87+
} else {
88+
logger.info("Auto-initialization disabled - patient_records table must be created manually");
89+
}
90+
}
91+
5892
@Transactional("mysqlTransactionManager")
5993
public void cleanupPatientRecords() {
6094
logger.info("Received request to clean up all patient records.");

src/main/resources/application-mysql.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ spring.sql.init.mode=always
3232
spring.sql.init.continue-on-error=false
3333
spring.sql.init.separator=;
3434

35-
# MySQL Patient Records - NO AUTO INITIALIZATION
36-
# Patient records schema must be manually created when needed
37-
app.patient.records.auto-init=false
35+
# MySQL Patient Records - AUTO INITIALIZATION ENABLED
36+
# Patient records schema will be created automatically on startup
37+
app.patient.records.auto-init=true
3838
app.patient.records.enabled=${PATIENT_RECORDS_ENABLED:true}
3939

4040
# JPA/Hibernate Settings - PostgreSQL (Main PetClinic Data)

0 commit comments

Comments
 (0)