Skip to content

Commit 6040a4a

Browse files
Feature/create databases (#42)
2 parents b9b198d + 7a29b95 commit 6040a4a

File tree

11 files changed

+219
-2
lines changed

11 files changed

+219
-2
lines changed

.github/workflows/docker_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
# Add any future services relative paths from . here
18-
service: [client, server/chat, server/gateway, server/matching, server/user, genai]
18+
service: [client, server/chat, server/gateway, server/matching, server/user, genai, database/userdb, database/chatdb, database/matchdb]
1919

2020
steps:
2121

database/chatdb/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Creates an image with a mysql database based on the template init_chatdb.sql
2+
# Expects a root password to be passed via the MYSQL_ROOT_PASSWORD environmental variable
3+
4+
# Use mysql as base image for the databases
5+
FROM mysql:8.0
6+
7+
# ENV MYSQL_ROOT_PASSWORD=password
8+
ENV MYSQL_DATABASE=chatdb
9+
10+
# Initialize database
11+
COPY init_chatdb.sql /docker-entrypoint-initdb.d/
12+
13+
# Expose port for MySQL
14+
EXPOSE 3306

database/chatdb/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Meet@Mensa Chat Database Service
2+
3+
A mysql database for managing chat information
4+
5+
## Local Deployment with Docker
6+
```
7+
# Build and tag the Docker image
8+
docker build -t chatdb .
9+
10+
# Run the Docker container forwarding port 3306 to 3306 and setting the root password via
11+
docker run --name chatdb-service -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 chatdb .
12+
13+
# List running containers (if needed)
14+
docker ps
15+
16+
# Stop the container
17+
docker stop chatdb-service
18+
19+
# Remove the container
20+
docker remove chatdb-service
21+
```
22+
23+
The mysql database will be available on `http://127.0.0.1:3306` with user: `root` and password: `<MYSQL_ROOT_PASSWORD>`.

database/chatdb/init_chatdb.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Create user-data table
2+
-- chat_id: UUID of the chat
3+
-- group_id: UUID of the group in the chat
4+
CREATE TABLE IF NOT EXISTS `chats` (
5+
chat_id INT PRIMARY KEY,
6+
group_id INT
7+
);
8+
9+
-- Create user-credentials table
10+
-- message_id: UUID of the message
11+
-- chat_id: UUID of the chat the message was sent in
12+
-- user_id: UUID of the author of the message
13+
-- timestamp: time the message was sent
14+
-- content: content of the message
15+
CREATE TABLE IF NOT EXISTS `messages` (
16+
message_id INT PRIMARY KEY,
17+
chat_id INT,
18+
user_id INT,
19+
timestamp INT,
20+
content VARCHAR(255) NOT NULL
21+
);

database/matchdb/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Creates an image with a mysql database based on the template init_matchdb.sql
2+
# Expects a root password to be passed via the MYSQL_ROOT_PASSWORD environmental variable
3+
4+
# Use mysql as base image for the databases
5+
FROM mysql:8.0
6+
7+
# ENV MYSQL_ROOT_PASSWORD=password
8+
ENV MYSQL_DATABASE=matchdb
9+
10+
# Initialize database
11+
COPY init_matchdb.sql /docker-entrypoint-initdb.d/
12+
13+
# Expose port for MySQL
14+
EXPOSE 3306

database/matchdb/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Meet@Mensa Match Database Service
2+
3+
A mysql database for managing matching information
4+
5+
## Local Deployment with Docker
6+
```
7+
# Build and tag the Docker image
8+
docker build -t matchdb .
9+
10+
# Run the Docker container forwarding port 3306 to 3307 and setting the root password via
11+
docker run --name matchdb-service -e MYSQL_ROOT_PASSWORD=root -p 3307:3306 matchdb .
12+
13+
# List running containers (if needed)
14+
docker ps
15+
16+
# Stop the container
17+
docker stop matchdb-service
18+
19+
# Remove the container
20+
docker remove matchdb-service
21+
```
22+
23+
The mysql database will be available on `http://127.0.0.1:3307` with user: `root` and password: `<MYSQL_ROOT_PASSWORD>`.

database/matchdb/init_matchdb.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Create user-data table
2+
-- user_id UUID associated with a user
3+
-- group_id UUID of the group a user has been matched withe
4+
CREATE TABLE IF NOT EXISTS `matching` (
5+
user_id INT PRIMARY KEY,
6+
group_id INT
7+
);
8+
9+
-- Create groups table
10+
-- group_id: UUID of each matched group
11+
-- meetup_time: Date and Time a group is set to meet
12+
CREATE TABLE IF NOT EXISTS `groups` (
13+
group_id INT PRIMARY KEY,
14+
meetup_time INT
15+
);

database/userdb/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Creates an image with a mysql database based on the template init_userdb.sql
2+
# Expects a root password to be passed via the MYSQL_ROOT_PASSWORD environmental variable
3+
4+
# Use mysql as base image for the databases
5+
FROM mysql:8.0
6+
7+
# ENV MYSQL_ROOT_PASSWORD=password
8+
ENV MYSQL_DATABASE=userdb
9+
10+
# Initialize database
11+
COPY init_userdb.sql /docker-entrypoint-initdb.d/
12+
13+
# Expose port for MySQL
14+
EXPOSE 3306

database/userdb/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Meet@Mensa User Database Service
2+
3+
A mysql database for managing user information
4+
5+
## Local Deployment with Docker
6+
```
7+
# Build and tag the Docker image
8+
docker build -t userdb .
9+
10+
# Run the Docker container forwarding port 3306 to 3308 and setting the root password via
11+
docker run --name userdb-service -e MYSQL_ROOT_PASSWORD=root -p 3308:3306 userdb .
12+
13+
# List running containers (if needed)
14+
docker ps
15+
16+
# Stop the container
17+
docker stop userdb-service
18+
19+
# Remove the container
20+
docker remove userdb-service
21+
```
22+
23+
The mysql database will be available on `http://127.0.0.1:3308` with user: `root` and password: `<MYSQL_ROOT_PASSWORD>`.

database/userdb/init_userdb.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Create user-data table
2+
-- user_id: UUID of the given user
3+
-- name: user's name
4+
-- gender: user's gender
5+
-- TODO: Add more data
6+
CREATE TABLE IF NOT EXISTS `user_data` (
7+
user_id INT PRIMARY KEY,
8+
name VARCHAR(255) NOT NULL,
9+
gender VARCHAR(255) NOT NULL
10+
);
11+
12+
-- Create user-credentials table
13+
-- user_id: UUID of the given user
14+
-- email: user's email used on login
15+
-- password_hash: user's hashed password
16+
CREATE TABLE IF NOT EXISTS `user_credentials` (
17+
user_id INT PRIMARY KEY,
18+
email VARCHAR(255) UNIQUE NOT NULL,
19+
password_hash VARCHAR(255) NOT NULL
20+
);

0 commit comments

Comments
 (0)