This repository showcases database design with SQL and programmatic interaction using Python. It provides a relational database schema for personal, educational, and skill information, along with scripts for setup, data population, and querying.
The structure and relationships within the database are visualized below:
Person: Stores basic personal and contact information.Education: Details about educational institutions attended.Degree: Information about degrees obtained, linkingPersonandEducation.SkillCategory: Classifies skills (e.g., 'Programming Language', 'Database', 'Web Development').Skill: Represents individual skills, linked to aSkillCategory.PersonSkill: A junction table creating the many-to-many relationship betweenPersonandSkill.
The complete MySQL CREATE TABLE statements for setting up this database structure. Defines tables, columns, primary keys, foreign keys, and data types.
SQL INSERT statements are provided to populate the database:
sample_data_insertion.sql: Contains data for two fictional individuals (John Doe, Jane Smith) to demonstrate table population and relationships. View sample_data_insertion.sqlpersonal_data_insertion.sql: Contains INSERT statements tailored for my specific portfolio data based on my resume at the time of creation. View personal_data_insertion.sql
Example SELECT queries demonstrating how data can be retrieved from this schema, including table joins, filtering, and aggregation.
This project includes Python scripts to automate database setup, data population, and query execution, offering a more programmatic way to interact with the SQL schema.
- Python Integration:
- Automated database setup (
python_scripts/setup_database.py). - Execution of sample SQL queries (
python_scripts/run_sample_queries.py) showcasing data retrieval, joins, and aggregation. - Modular database connection logic (
python_scripts/db_connector.py.example).
- Automated database setup (
- Cloud Compatibility: Designed to work with a MySQL-compatible cloud database like TiDB Cloud (or a local MySQL server).
- Database: MySQL (with TiDB Cloud)
- Scripting: Python 3.13
- Python Libraries:
mysql-connector-python(seerequirements.txt)
Follow these steps to set up and run this project using the Python scripts:
-
Clone the Repository:
git clone https://github.com/John-Swindell/Portfolio-SQL-Schema.git cd Portfolio-SQL-Schema -
Set up your Database Server:
- Cloud Option (TiDB Cloud is what I used):
- You get a free Serverless Tier cluster on TiDB Cloud, you just have to add the DB. (You can also choose literally any other MySQL-compatible cloud provider if you prefer).
- Get your database connection details (host, user, password, port).
- Ensure your IP address is allowlisted in the cloud provider's network settings.
- If your provider requires a specific CA certificate for SSL connections (like TiDB Cloud), download it and place it in the root of this project directory (e.g., name it
isrgrootx1.pem).
- Local Option:
- Ensure you have a local MySQL server installed and running.
- Create a database (e.g.,
portfolio_db) and a user with privileges to access it. - I highly recommend using Linux for this, everything works so much more smoothly.
- Cloud Option (TiDB Cloud is what I used):
-
Configure Database Connection:
- Navigate to the
python_scripts/directory. - Make a copy of
db_connector.py.exampleand rename it todb_connector.py. - Open
python_scripts/db_connector.pyand update the placeholder variables at the top with your database credentials and settings as instructed in the file's comments.
- Navigate to the
-
Create Python Virtual Environment & Install Dependencies:
- I highly recommend you use a virtual environment. From the project root (
Portfolio-SQL-Schema/):python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
- Install the required Python packages:
pip install -r requirements.txt
- I highly recommend you use a virtual environment. From the project root (
-
Run Database Setup Script:
- Execute the setup script to create the database schema and populate data. From the project root:
python python_scripts/setup_database.py
- Follow the on-screen prompts to insert sample and/or personal data.
- Execute the setup script to create the database schema and populate data. From the project root:
-
Run Sample Queries Script:
- Execute the script to see the sample queries in action. From the project root:
python python_scripts/run_sample_queries.py
- Execute the script to see the sample queries in action. From the project root:
Here are a couple examples of the output from run_sample_queries.py:
For those who prefer to interact with the database directly using SQL commands:
- Connect to your MySQL database server.
- Run the
sql/schema.sqlscript to create the tables. - Run the
sql/sample_data_insertion.sqlscript to populate with sample data for testing. - Optionally, run the
sql/personal_data_insertion.sqlscript for the author's specific portfolio data. - Use the queries in
sql/sample_queries.sqlas a reference or execute them directly for interacting with the data.
