Skip to content

dlutton/csv-to-mysql-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cannabinoids Database Project

This project is a Python backend service to manage cannabinoid data with MySQL, using Docker for easy setup. It reads a CSV file, inserts data into a MySQL database, and allows you to manage the database with Adminer.


Project Structure

.
├── backend/
│ ├── data/
│ │ └── cannabinoids.csv
│ ├── app.py
│ ├── requirements.txt
│ └── ...
├── docker-compose.yml
├── .env
└── README.md

Prerequisites


Setup

1.Clone the repository

git clone <your-repo-url>
cd <your-repo-name>

2.Create a .env file in the root directory:

DB_ROOT_PASSWORD=rootpassword
DB_NAME=mydatabase
DB_USER=myuser
DB_PASSWORD=mypassword
DB_PORT=330

⚠️ Keep .env secret; do not commit it to Git.

3.Place your CSV file in backend/data/cannabinoids.csv

Running with Docker

Build and start containers

docker-compose up --build

This will:

Start a MySQL database container (db)

Start the Python backend container (python_backend)

Wait for the database to be ready

Run Alembic migrations automatically

Read the CSV and insert rows into the database


Stop and remove containers

docker-compose down

Rebuild containers

If you make changes to code or dependencies:

docker-compose up --build --force-recreate

Adminer Web Interface

Adminer is included for easy database management.

Open your browser: http://localhost:8080

Login using credentials from your .env file:

System: MySQL
Server: db
Username: myuser
Password: mypassword
Database: cannabinoids_db

Example Logs when executed successfully

python_backend  | Connecting to MySQL database at db:3306 as myuser
python_backend  | Waiting for database... ((pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'db' ([Errno 111] Connection refused)")
python_backend  | (Background on this error at: https://sqlalche.me/e/20/e3q8))
python_backend  | ✅ Database is ready
python_backend  | INFO  [alembic.runtime.migration] Context impl MySQLImpl.
python_backend  | INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
python_backend  | ✅ Database is ready!
python_backend  | Read 25 rows from CSV.
python_backend  | ✅ Inserted 25 rows into cannabinoids table.
python_backend  | cannabinoids rows: 25

About

SWENG 480 CSV to MySQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published