Giter Club home page Giter Club logo

im-cw2's Introduction

im-cw2

License PostgreSQL

1 Prerequisites

1.1 Docker

Ensure the Docker engine is installed on your system with version 18.06.0 or higher.

You can download and install the Docker engine from the official Docker website.

Note

  • Especially on Linux, make sure your user has the required permissions to interact with the Docker daemon.
  • If you are unable to do this, either append sudo in front of each docker command or switch to root using sudo -s.

1.2 Docker Compose

Ensure that Docker Compose is installed on your system with version 1.28.0 or higher.

You can download and install Docker Compose from the official Docker website.

1.3 PostgreSQL

Ensure that PostgreSQL is installed on your system with version 13 or higher.

You can download PostgreSQL using the following command based on your operating system:

macOS:

  • Install Homebrew (if not already installed).
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Note

  • Visit Homebrew's official website here for more information.
  • You will require administrative priviledges during the installation process.
brew install postgresql

Note

  • You may have to export the PostgreSQL bin directory to use the PostgreSQL commands system wide.
  • First, find out what shell you are currently using with:
echo $SHELL
  • Open your shell config file (prefixed with a .) with an appropriate text editor (e.g. nano, vim, nvim, etc.).
nano <SHELL_CONFIG_FILE>
  • Add the following line:
export PATH="/usr/local/opt/postgresql@16/bin:$PATH"
  • Update your shell based on the config file changes.
source <SHELL_CONFIG_FILE>

Linux:

  • Debian/Ubuntu:
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
  • CentOS/RHEL:
sudo yum check-update
sudo yum install ftp
  • Fedora:
sudo dnf check-update
sudo dnf install ftp
  • Arch:
sudo pacman -Sy
sudo pacman -S ftp

Windows:

You can download the PostgreSQL installer from the official website here and follow the installation instructions.

1.4 Port availability

The PostgreSQL service running on the Docker Container uses Port 5433 on your host system. Ensure that this port is free and is not running any conflicting services or has any firewall rules concerning them.

2 Usage

  1. Clone the repository to your local machine.
git clone https://github.com/iArcanic/im-cw2
  1. Navigate to the project's directory.
cd im-cw2
  1. Build and run all Docker containers.
docker-compose up

Note

With Docker Compose, you can also optionally use the following:

  • If you want to build the images each time (or changed a Dockerfile), use:
docker-compose up --build
  • If you want to run all the services in the background, use:
docker-compose up -d

After, you can optionally view Docker images, status of containers, and interact with running containers using the Docker Desktop application.

  1. Use the PostgreSQL CLI to connect to the Docker container.
psql -h localhost -p 5433 -U postgres

Note

  • The default PostgreSQL user is postgres and its password is changeme.
  • The default port is 5433.
  • These values can be found in the .env file and can be changed if necessary.
  1. Connect to the database.
\c student_db

Note

  • The default database name is student_db.
  • These values can be found in the .env file and can be changed if necessary.
  1. Experiment with connecting to the database as different users.
\c student_db <USERNAME>

For example:

\c student_db admin_user

Note

The credentials for these users are found in sql/06_create_users.sql.

Important

When referencing the tables, you must use the schema name student_info before the table name.

  1. Experiment with Role-Based Access Control (RBAC).

For example, as admin_user (assuming that you have connected as admin_user beforehand):

SELECT date_of_birth FROM student_info.students;

You should see the following:

ERROR:  permission denied for schema student_info

Note

The permissions for these roles are found in sql/05_grant_permissions.sql.

  1. Backup and export the database

Navigate to the scripts folder.

cd scripts

Make the backup.sh script an executable.

chmod +x backup.sh

Run the backup.sh script.

./backup.sh

Navigate to your home folder and you should see the backup folder (student_db-backups) with a database dump .sql file (timestamped accordingly).

Note

  • You will be prompted to enter a password for this script.
  • This is the password of the user that the script is using.
  • In this case, it is the default user postgres with its password changeme.
  • These values can be found in the .env file and can be changed if necessary.
  1. Quit the PostgreSQL connection to the Docker container after usage.
\q
  1. Destroy the Docker container after usage.
docker-compose down

im-cw2's People

Contributors

iarcanic avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.