INFO-H303 @ULB
This project is a PostgreSQL database application built using psycopg2, a PostgreSQL adapter for Python. It aims to provide an implementation of the project for the course INFO-H303
(Database) at the Université Libre de Bruxelles.
The database is a simple restaurant reviewing system. It allows users to add restaurants, add reviews to restaurants, and search for restaurants based on their name, location, or type of cuisine. It also allows the user to see the menu of a restaurant.
The interaction with the database is done through a Python terminal interface.
Before you begin, ensure you have the following installed on your local machine:
- Python 3 (>=3.8)
- PostgreSQL (>=15)
- Clone the repository
git clone https://github.com/rcroughs/iFoodDB.git
cd iFoodDB
- Install the dependencies
pip install -r requirements.txt
- Create a new PostgreSQL database
- Run psql as a superuser and with user postgres:
sudo -u postgres psql
- Create a new database with the following commands on
psql
:
CREATE DATABASE iFoodDB;
CREATE USER ifooddb_user WITH PASSWORD 'password';
ALTER ROLE ifooddb_user SET client_encoding TO 'utf8';
ALTER ROLE ifooddb_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE ifooddb_user SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE iFoodDB TO ifooddb_user;
\q
- Setup the database schema by running the following command:
sudo -u postgres psql -d iFoodDB
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO ifooddb_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON TABLES TO ifooddb_user;
ALTER SCHEMA public OWNER TO ifooddb_user;
\q
Note: The database name, user, and password can be changed in the config.py
file.
- Initialize the intial datas (must be run only once)
python3 init.py
- Run the application
python3 ifood.py
- Drop all tables If you want to reset the database, you can drop all tables by running the following command:
sudo -u postgres psql -d iFoodDB
Enter the following command in the psql
shell:
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO ifooddb_user;
\q