From 372c1ad35d337c00817d828e9bc33462b19fce28 Mon Sep 17 00:00:00 2001 From: Bassem Girgis Date: Wed, 18 Aug 2021 00:01:56 -0500 Subject: [PATCH] add more db inits --- .gitignore | 2 ++ db/mariadb/init.sql | 27 +++++++++++++++++++++++++++ db/mysql/init.sql | 27 +++++++++++++++++++++++++++ db/postgres/init.sql | 7 ++++--- docker-compose.yml | 40 +++++++++++++++++++++++++++++++++------- 5 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 db/mariadb/init.sql create mode 100644 db/mysql/init.sql diff --git a/.gitignore b/.gitignore index ea8c4bf..8d9c2a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +Cargo.lock +*.log diff --git a/db/mariadb/init.sql b/db/mariadb/init.sql new file mode 100644 index 0000000..e115d49 --- /dev/null +++ b/db/mariadb/init.sql @@ -0,0 +1,27 @@ +CREATE DATABASE demo; +USE demo; + +-- a single table is used for all events in the cqrs system +CREATE TABLE events +( + aggregate_type VARCHAR(256) NOT NULL, + aggregate_id VARCHAR(256) NOT NULL, + sequence bigint CHECK (sequence >= 0) , + payload TEXT , + metadata TEXT , + timestamp timestamp DEFAULT (CURRENT_TIMESTAMP), + PRIMARY KEY (aggregate_type, aggregate_id, sequence) +); + +CREATE + USER + 'demo_user'@'localhost' +IDENTIFIED BY + 'password'; + +GRANT + ALL +ON + demo.* +TO + 'demo_user'@'localhost'; diff --git a/db/mysql/init.sql b/db/mysql/init.sql new file mode 100644 index 0000000..55568f6 --- /dev/null +++ b/db/mysql/init.sql @@ -0,0 +1,27 @@ +CREATE DATABASE demo; +USE demo; + +-- a single table is used for all events in the cqrs system +CREATE TABLE events +( + aggregate_type VARCHAR(256) NOT NULL, + aggregate_id VARCHAR(256) NOT NULL, + sequence bigint CHECK (sequence >= 0) NOT NULL, + payload TEXT NOT NULL, + metadata TEXT NOT NULL, + timestamp timestamp DEFAULT (CURRENT_TIMESTAMP), + PRIMARY KEY (aggregate_type, aggregate_id, sequence) +); + +CREATE + USER + 'demo_user'@'localhost' +IDENTIFIED BY + 'password'; + +GRANT + ALL +ON + demo.* +TO + 'demo_user'@'localhost'; diff --git a/db/postgres/init.sql b/db/postgres/init.sql index 9f1c6c0..d835c8f 100644 --- a/db/postgres/init.sql +++ b/db/postgres/init.sql @@ -1,3 +1,6 @@ +CREATE DATABASE demo; +\c demo; + -- a single table is used for all events in the cqrs system CREATE TABLE events ( @@ -21,8 +24,6 @@ ENCRYPTED PASSWORD GRANT ALL PRIVILEGES ON TABLE - events, - snapshots, - queries + events TO demo_user; diff --git a/docker-compose.yml b/docker-compose.yml index 45a7d9e..25fc64b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,16 +1,41 @@ version: "3.4" services: - db: - image: postgres + maria-db: + image: mariadb volumes: - - "./db:/docker-entrypoint-initdb.d" + - "./db/mariadb:/docker-entrypoint-initdb.d" networks: - default ports: - - "5433:5432" + - "8084:3306" + environment: + #- "MARIADB_USER=root" + - "MARIADB_ROOT_PASSWORD=admin_pass" + command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW + + mysql-db: + image: mysql + volumes: + - "./db/mysql:/docker-entrypoint-initdb.d" + networks: + - default + ports: + - "8086:3306" + environment: + #- "MYSQL_USER=root" + - "MYSQL_ROOT_PASSWORD=admin_pass" + command: --default-authentication-plugin=mysql_native_password + + postgres-db: + image: postgres + volumes: + - "./db/postgres:/docker-entrypoint-initdb.d" + networks: + - default + ports: + - "8087:5432" environment: - - "POSTGRES_DB=demo" - "POSTGRES_USER=admin" - "POSTGRES_PASSWORD=admin_pass" @@ -20,6 +45,7 @@ services: networks: - default ports: - - "8081:8080" + - "8083:8080" depends_on: - - db + - mysql-db + - postgres-db