From f90ca0d64e12b39e613d8f20f2e0520721b0ab11 Mon Sep 17 00:00:00 2001 From: rafaelpereira Date: Fri, 26 Apr 2024 12:19:35 +0100 Subject: [PATCH] refactor: split database for write and read model. add schema of read database to flyway Use root user on database for now. --- .../adapter/outbound/account/jpa/AccountOutAdapter.kt | 1 - demo-transactions/src/main/resources/application-local.yaml | 2 +- demo-transactions/src/main/resources/application.yaml | 6 +++++- .../src/main/resources/db/V0_0_3__account_balance_table.sql | 5 ----- .../resources/db/read/V0_0_3__account_balance_table.sql | 5 +++++ .../{ => write}/V0_0_1__create_tables_account_customer.sql | 0 .../db/{ => write}/V0_0_2__add_balance_account.sql | 0 7 files changed, 11 insertions(+), 8 deletions(-) delete mode 100644 demo-transactions/src/main/resources/db/V0_0_3__account_balance_table.sql create mode 100644 demo-transactions/src/main/resources/db/read/V0_0_3__account_balance_table.sql rename demo-transactions/src/main/resources/db/{ => write}/V0_0_1__create_tables_account_customer.sql (100%) rename demo-transactions/src/main/resources/db/{ => write}/V0_0_2__add_balance_account.sql (100%) diff --git a/demo-transactions/src/main/kotlin/io/holixon/cqrshexagonaldemo/demoparent/transactions/adapter/outbound/account/jpa/AccountOutAdapter.kt b/demo-transactions/src/main/kotlin/io/holixon/cqrshexagonaldemo/demoparent/transactions/adapter/outbound/account/jpa/AccountOutAdapter.kt index 0eb6880..eb0d2e2 100644 --- a/demo-transactions/src/main/kotlin/io/holixon/cqrshexagonaldemo/demoparent/transactions/adapter/outbound/account/jpa/AccountOutAdapter.kt +++ b/demo-transactions/src/main/kotlin/io/holixon/cqrshexagonaldemo/demoparent/transactions/adapter/outbound/account/jpa/AccountOutAdapter.kt @@ -42,7 +42,6 @@ class AccountOutAdapter( jpaAccountOutAdapter.save(accountEntityMapper.toEntity(account)) - return account } diff --git a/demo-transactions/src/main/resources/application-local.yaml b/demo-transactions/src/main/resources/application-local.yaml index 730c078..2d71e01 100644 --- a/demo-transactions/src/main/resources/application-local.yaml +++ b/demo-transactions/src/main/resources/application-local.yaml @@ -1,5 +1,5 @@ spring: datasource: url: jdbc:mysql://localhost:3306/cqrs-meets-hexagonal - username: SA + username: root password: Aut0mat0rs! diff --git a/demo-transactions/src/main/resources/application.yaml b/demo-transactions/src/main/resources/application.yaml index eef4966..f603ae6 100644 --- a/demo-transactions/src/main/resources/application.yaml +++ b/demo-transactions/src/main/resources/application.yaml @@ -38,4 +38,8 @@ spring: password: ${spring.datasource.password} url: ${spring.datasource.url} locations: - - classpath:db + - classpath:db/write + - classpath:db/read + schemas: + - cqrs-meets-hexagonal + - cqrs-meets-hexagonal-read-db \ No newline at end of file diff --git a/demo-transactions/src/main/resources/db/V0_0_3__account_balance_table.sql b/demo-transactions/src/main/resources/db/V0_0_3__account_balance_table.sql deleted file mode 100644 index 29ea539..0000000 --- a/demo-transactions/src/main/resources/db/V0_0_3__account_balance_table.sql +++ /dev/null @@ -1,5 +0,0 @@ -create table account_balance( - iban VARCHAR(255) NOT NULL, - balance DECIMAL NOT NULL, - primary key (iban) -); diff --git a/demo-transactions/src/main/resources/db/read/V0_0_3__account_balance_table.sql b/demo-transactions/src/main/resources/db/read/V0_0_3__account_balance_table.sql new file mode 100644 index 0000000..56ac6e9 --- /dev/null +++ b/demo-transactions/src/main/resources/db/read/V0_0_3__account_balance_table.sql @@ -0,0 +1,5 @@ +CREATE TABLE `cqrs-meets-hexagonal-read-db`.account_balance( + iban VARCHAR(255) NOT NULL, + balance DECIMAL NOT NULL, + PRIMARY KEY (iban) +); diff --git a/demo-transactions/src/main/resources/db/V0_0_1__create_tables_account_customer.sql b/demo-transactions/src/main/resources/db/write/V0_0_1__create_tables_account_customer.sql similarity index 100% rename from demo-transactions/src/main/resources/db/V0_0_1__create_tables_account_customer.sql rename to demo-transactions/src/main/resources/db/write/V0_0_1__create_tables_account_customer.sql diff --git a/demo-transactions/src/main/resources/db/V0_0_2__add_balance_account.sql b/demo-transactions/src/main/resources/db/write/V0_0_2__add_balance_account.sql similarity index 100% rename from demo-transactions/src/main/resources/db/V0_0_2__add_balance_account.sql rename to demo-transactions/src/main/resources/db/write/V0_0_2__add_balance_account.sql