Skip to content

Commit

Permalink
chore(rent-service): use flyway as db migration tool
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo.corso committed Mar 24, 2024
1 parent 7e0b9b2 commit 691e55d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion debezium-connectors/postgres-debezium-connector.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"database.password": "admin",
"database.dbname": "db",
"database.server.name": "postgres-outbox",
"table.include.list": "public.outbox",
"table.include.list": "public.outbox,rent-service.outbox",
"tombstones.on.delete": "false",
"transforms": "outbox",
"transforms.outbox.type": "it.vincenzocorso.carsharing.debezium.transformer.CustomTransformer",
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ services:
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
POSTGRES_DATABASE: db
POSTGRES_SCHEMA: rent-service
POSTGRES_USERNAME: admin
POSTGRES_PASSWORD: admin
KAFKA_BOOSTRAP_SERVERS: kafka:9092
Expand Down
1 change: 1 addition & 0 deletions rent-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.flywaydb:flyway-core:9.10.2'
implementation 'org.postgresql:postgresql:42.2.23'
annotationProcessor 'org.hibernate:hibernate-jpamodelgen:6.1.6.Final'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static void setupDatasource(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.username", postgreSQLContainer::getUsername);
registry.add("spring.datasource.password", postgreSQLContainer::getPassword);
registry.add("spring.datasource.driver-class-name", postgreSQLContainer::getDriverClassName);
registry.add("spring.jpa.hibernate.ddl-auto", () -> "create-drop");
registry.add("spring.jpa.hibernate.ddl-auto", () -> "none");
registry.add("spring.flyway.defaultSchema", () -> "public");
}

@Autowired
Expand Down
7 changes: 5 additions & 2 deletions rent-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
spring.datasource.url = jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
spring.datasource.url = jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}?currentSchema=${POSTGRES_SCHEMA}
spring.datasource.username = ${POSTGRES_USERNAME}
spring.datasource.password = ${POSTGRES_PASSWORD}
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.ddl-auto = none

spring.flyway.locations = classpath:db/migration/postgres
spring.flyway.defaultSchema = ${POSTGRES_SCHEMA}

spring.kafka.consumer.group-id = rent-service
spring.kafka.consumer.bootstrap-servers = ${KAFKA_BOOSTRAP_SERVERS}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS outbox (
message_id text primary key,
channel text not null,
message_key text not null,
payload text not null,
headers text not null
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS rents (
rent_id uuid primary key,
version bigint not null,
customer_id text not null,
vehicle_id text not null,
current_state text not null
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS rent_state_transitions (
rent UUID,
sequence_number SMALLINT,
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL,
state TEXT NOT NULL,
PRIMARY KEY (rent, sequence_number),
FOREIGN KEY (rent) REFERENCES rents(rent_id)
);

0 comments on commit 691e55d

Please sign in to comment.