This project is a simple web application similar to IMDb that interacts with a MySQL/MariaDB database. The application features a Flask-based UI that allows users to view movie and actor details, like movies, and execute SQL queries.
The project is structured to learn SQL by implementing queries and database interactions manually.
IMPORTANT: Object Relational Model (ORM) based queries are not allowed for any task. All queries must be written using raw SQL statements without any Python-based processing.
Before you start PA 1.2, you need to update your existing code with the latest changes. You can do this in one of two ways:
-
Using Git:
- Open your terminal.
- Navigate to your project directory using the command:
cd <path to your project directory>
- Run the following command to pull the latest changes:
git pull
-
Manually Downloading the Update:
- Visit the YourOwnIMDb GitHub repository.
- Click the green "Code" button.
- Select "Download ZIP" to get the updated code.
- Python (3.10 or later)
- MariaDB
- Flask (for the web framework)
- PyMySQL (for database connectivity)
- All dependencies from
requirements.txt
-
Installation
NOTE: If you have already set up MariaDB for Written Assignment 2, you may skip the first two sections (Installation and Starting the MariaDB Server).
Choose the appropriate installation method for your operating system:
- MacOS (Homebrew)
brew install mariadb
- Ubuntu/Debian
sudo apt install mariadb-server
- Windows
Download and install from MariaDB Official Website.
- MacOS (Homebrew)
-
Start MariaDB Server
# MacOS brew services start mariadb # Linux sudo systemctl start mariadb
(For Windows, the service starts automatically after installation.)
-
Create a new database and user for the project Open a terminal and start MariaDB:
mysql -u root -p
Inside MySQL, run the following:
NOTE: Below commands must be run in your MySQL shell inside terminal.
CREATE DATABASE moviedb; CREATE USER 'imdb'@'localhost' IDENTIFIED BY 'cosi-127b'; GRANT ALL PRIVILEGES ON moviedb.* TO 'imdb'@'localhost'; FLUSH PRIVILEGES;
- Clone the repository using:
git clone https://github.com/SSD-Brandeis/IMDbDatabase
- Or download it manually from GitHub by clicking the green "Code" button → Download ZIP.
Open the project in your preferred code editor and update the ini.env
file:
DB_USER=imdb
DB_PASSWORD=cosi-127b
DB_HOST=localhost
DB_DATABASE=moviedb
(Replace cosi-127b
with the password, if you used different while setting up MariaDB in Step 1.3 for imdb
user)
Use the SQL scripts provided to set up the database.
- Open a terminal and start MySQL:
mysql -u imdb -p moviedb
NOTE: Starting next step, all commands must be run in your MySQL shell inside terminal.
- Create required tables as per the provided schema and ER-diagram in project document. Pay attention for required constraints (
CHECK
,PRIMARY KEY
,FOREIGN KEY
withON DELETE CASCADE
) while creating tables. Don't forget to run the below command before you start creating tables.USE moviedb; --- This takes you inside moviedb
- Verify that the tables are created successfully:
SHOW TABLES;
- Execute the
data.sql
commands to insert initial data once tables are created. - Verify that your tables have some data into them:
SELECT * FROM MotionPicture;
Once your database is set up and populated with sample data, follow these steps to start the Flask application:
NOTE: The following commands must be run in your command prompt (terminal), NOT inside the MySQL shell.
- Install required dependencies:
pip install -r requirements.txt
- Run the Flask app:
python run.py
- Open a browser and visit:
http://127.0.0.1:5000/
The project requires students to write raw SQL queries for two functionalities.
- Familiarize yourself with
database.py
, which handles all database queries. - See how
execute()
is used to interact with the database.
Modify the function inside actors.py
to fetch all actors' details from the database.
- Replace
query = """ """
with an SQL query to fetchname
,nationality
,dob
, andgender
fromPeople
.
Modify the function inside movies.py
to allow users to like a movie.
- Replace
query = """ """
with an SQL query to insert a like. - Use the
Database.execute()
function correctly with parameters.
If you encounter issues, use the following commands:
- Truncate table data (removes all rows but keeps table structure):
TRUNCATE TABLE <table_name>;
- Drop table and recreate:
DROP TABLE <table_name>;
- Fix foreign key constraint errors when truncating/deleting:
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE <table_name>;
SET FOREIGN_KEY_CHECKS=1;
- Complete the missing SQL queries in
actors.py
andmovies.py
. - Ensure your application runs without errors and the database is correctly set up.
To verify:
- Run
python run.py
and check if movies and actors display correctly. - Test if users can like a movie.
- Do not modify
database.py
logic. - Ensure your
.sql
queries execute correctly before implementing them in Flask. - Queries in
queries.py
will be used for future assignments. Do not modify this file now.