From b2038cc1f237a0cccf14cf9c55272c7210d35c10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Filip=20Pit=C3=A1k?= <xpitak@fi.muni.cz>
Date: Sun, 14 Apr 2024 21:59:00 +0200
Subject: [PATCH] Create database container with data initialization

---
 .docker/db/scripts/init_db.sql | 21 +++++++++++++++++++++
 .docker/dummyFile              |  2 --
 README.md                      |  4 ++--
 docker-compose.yaml            | 16 +++++++++++++++-
 4 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 .docker/db/scripts/init_db.sql
 delete mode 100644 .docker/dummyFile

diff --git a/.docker/db/scripts/init_db.sql b/.docker/db/scripts/init_db.sql
new file mode 100644
index 0000000..20e2ca1
--- /dev/null
+++ b/.docker/db/scripts/init_db.sql
@@ -0,0 +1,21 @@
+CREATE SCHEMA IF NOT EXISTS bank_user;
+CREATE USER "ACC_USER" WITH PASSWORD 'userAccPasswd';
+REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM "ACC_USER";
+REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM "ACC_USER";
+ALTER ROLE "ACC_USER" SET SEARCH_PATH TO bank_user;
+GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA bank_user TO "ACC_USER";
+
+CREATE SCHEMA IF NOT EXISTS bank_account;
+CREATE USER "ACC_ACCOUNT" WITH PASSWORD 'accountAccPasswd';
+REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM "ACC_ACCOUNT";
+REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM "ACC_ACCOUNT";
+ALTER ROLE "ACC_ACCOUNT" SET SEARCH_PATH TO bank_account;
+GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA bank_account TO "ACC_ACCOUNT";
+
+CREATE SCHEMA IF NOT EXISTS bank_transaction;
+CREATE USER "ACC_TRANSACTION" WITH PASSWORD 'transactionAccPasswd';
+REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM "ACC_TRANSACTION";
+REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM "ACC_TRANSACTION";
+ALTER ROLE "ACC_TRANSACTION" SET SEARCH_PATH TO bank_transaction;
+GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA bank_transaction TO "ACC_TRANSACTION";
+
diff --git a/.docker/dummyFile b/.docker/dummyFile
deleted file mode 100644
index bf3a7bd..0000000
--- a/.docker/dummyFile
+++ /dev/null
@@ -1,2 +0,0 @@
-created just to commit the '.docker' directory.
-Remove after other files have been added into the directory.
\ No newline at end of file
diff --git a/README.md b/README.md
index 69ad99b..2d8cbf5 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ which can report total and average (per account) transactions (deposits, withdra
 ## Use case diagram
 <img src="./useCaseDiagram.png" width="800">
 
-## Artefact Structure
+## Artifact Structure
 
 | Service	                    | Specification	                                                                                                        |
 |-----------------------------|-----------------------------------------------------------------------------------------------------------------------|
@@ -25,7 +25,7 @@ which can report total and average (per account) transactions (deposits, withdra
 
 ## Module Architecture
 Each service is implemented as a separate maven artifact consisting of a Spring-boot application. Within each project
-we used the principles of `Hexagonal architecture` and `DDD`, where the domain itself consists of only pure Java classes,
+we used the principles of `Hexagonal architecture`, where the domain itself consists of only pure Java classes,
 with no technological dependencies. By using such separation, we nicely created an extra separated layer on top of the
 traditional `Controller, Facade, Service and Repository` layers. The main benefit of such separation is visible mainly when 
 extending new features, implementation of tests and usage of custom abstractions with ease.
diff --git a/docker-compose.yaml b/docker-compose.yaml
index c5fab82..a6a6ad0 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -1,2 +1,16 @@
-version: "3.8"
+version: "3.9"
+name: online-banking
 
+services:
+
+  banking-db:
+    image: "postgres:16.2"
+    ports:
+      - "5432:5432"
+    environment:
+      - POSTGRES_USER=root
+      - POSTGRES_PASSWORD=passwd
+      - POSTGRES_DB=banking
+    volumes:
+      - ./.docker/db/scripts:/docker-entrypoint-initdb.d
+    
\ No newline at end of file
-- 
GitLab