https://github.com/dlutton/csv-to-mysql-project
SWENG 480 CSV to MySQL
https://github.com/dlutton/csv-to-mysql-project
Last synced: 5 months ago
JSON representation
SWENG 480 CSV to MySQL
- Host: GitHub
- URL: https://github.com/dlutton/csv-to-mysql-project
- Owner: dlutton
- Created: 2025-10-12T22:22:16.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2025-10-14T02:01:02.000Z (7 months ago)
- Last Synced: 2025-10-26T02:45:28.394Z (7 months ago)
- Language: Python
- Size: 7.81 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```bash
.
├── backend/
│ ├── data/
│ │ └── cannabinoids.csv
│ ├── app.py
│ ├── requirements.txt
│ └── ...
├── docker-compose.yml
├── .env
└── README.md
```
---
## Prerequisites
- [Docker](https://www.docker.com/get-started)
- [Docker Compose](https://docs.docker.com/compose/install/)
---
## Setup
1.**Clone the repository**
```bash
git clone
cd
```
2.**Create a .env file in the root directory:**
```bash
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
```bash
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
```bash
docker-compose down
```
## Rebuild containers
If you make changes to code or dependencies:
```bash
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:
```bash
System: MySQL
Server: db
Username: myuser
Password: mypassword
Database: cannabinoids_db
```
---
## Example Logs when executed successfully
```bash
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
```