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 MotionPictureDb 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
IMPORTANT: If your database is already set up and populated, you can skip the initial setup steps in this section and jump to Section 3.
-
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 KEYwithON 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.sqlcommands 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 18 raw SQL queries in queries.py. Each query corresponds to a specific question (Q1-Q20) that tests your understanding of SQL concepts. May sure you load the databse from data/data2.sql before you start implementing the queries, as some of the queries require data from that file.
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
queries.py. - Ensure your application runs without errors and the database is correctly set up.
To verify:
- Run
python run.pyand check if all Q1-Q20 queries work correctly.