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.
.
├── backend/
│ ├── data/
│ │ └── cannabinoids.csv
│ ├── app.py
│ ├── requirements.txt
│ └── ...
├── docker-compose.yml
├── .env
└── README.md1.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=3303.Place your CSV file in backend/data/cannabinoids.csv
Build and start containers
docker-compose up --buildThis 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
docker-compose downIf you make changes to code or dependencies:
docker-compose up --build --force-recreateAdminer 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_dbpython_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