service-architecture/db
Robin Marin--Muller 700abc480f
Update README.md
2024-12-24 11:37:20 +01:00
..
db.sh Scripts: Populating database, autocreating .env file. CI/CD: Removed Deployement for now. 2024-12-21 14:12:53 +01:00
db.sql db: Created "connections" table to store tokens. backend: created "/connect" endpoint. 2024-12-22 10:51:28 +01:00
init.sql Backend: Added "change_status" endpoint which checks the role before doing any action. DB: Added 3 dummy users with the 3 different roles. 2024-12-23 00:01:47 +01:00
README.md Update README.md 2024-12-24 11:37:20 +01:00

Database Initialization

Install mariadb:

On Arch-Linux

pacman -S mariadb
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo chown -R mysql:mysql /var/lib/mysql
sudo systemctl enable mariadb
sudo systemctl start mariadb

Create a user

sudo mariadb -u root -p
CREATE USER '<user>'@'localhost' IDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON *.* TO '<user>'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Run the init.sh to create the database.

If you want to update the database, it is recommended to run remove.sh before hand.

Install MariaDB on Debian

  1. Update the package list:

    sudo apt update
    
  2. Install MariaDB:

    sudo apt install mariadb-server mariadb-client
    
  3. Secure the installation:

    sudo mysql_secure_installation
    
  4. Enable and start MariaDB:

    sudo systemctl enable mariadb
    sudo systemctl start mariadb
    

Create a Database User

  1. Access MariaDB as root:

    sudo mariadb -u root -p
    
  2. Execute the following commands to create a new user:

    CREATE USER '<user>'@'localhost' IDENTIFIED BY '<password>';
    GRANT ALL PRIVILEGES ON *.* TO '<user>'@'localhost' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    

Initialize the Database

  • Run the init.sh script to set up the database:

    ./init.sh
    
  • To clean up before reinitializing, execute:

    ./remove.sh