Goods Inventory uses Flask-SQLAlchemy to manage all database interactions. The connection is configured through environment variables, and the schema is created automatically on first run.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AndresLopezCorrales/Goods-Inventory/llms.txt
Use this file to discover all available pages before exploring further.
SQLAlchemy initialization
The shared SQLAlchemy instance lives inapp/database.py:
app/database.py
db instance is imported by every model file and bound to the Flask application at startup via db.init_app(app) inside create_app(). Keeping the instance separate from the app factory avoids circular imports and allows models to be defined independently of the application context.
Connection string
The database URI is assembled from environment variables insidemain.py before the app context is pushed:
main.py
mysql+pymysql dialect prefix instructs SQLAlchemy to use PyMySQL as the underlying driver — a pure-Python MySQL client that requires no system-level binary installation.
Auto schema creation
After the application is configured,db.create_all() is called inside the app context on every startup:
main.py
db.create_all() inspects all registered SQLAlchemy models and issues CREATE TABLE IF NOT EXISTS statements for any tables that are not yet present. It does not drop or alter tables that already exist, so existing data is always preserved.
Database auto-creation
Before SQLAlchemy attempts to connect to the target database,main.py opens a temporary connection to MySQL without specifying a database and runs a CREATE DATABASE statement:
main.py
.env file and start the server.