An open API service indexing awesome lists of open source software.

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

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
```