Sistema MRP supports both SQLite for local development and PostgreSQL for production. The active database is selected at runtime through a singleDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ElthonJohan/Sistema-MRP/llms.txt
Use this file to discover all available pages before exploring further.
DATABASE_URL environment variable, with no code changes required between environments. Schema creation, incremental migrations, and the superadmin seed are all handled by init_db.py.
DATABASE_URL resolution
database.py resolves the connection string in the following order:
Streamlit secrets
Reads
st.secrets["DATABASE_URL"]. This is the preferred method for Streamlit Cloud deployments. Set it in the app’s Secrets panel in the dashboard..env file fallback
If the secret is absent (e.g. running locally),
python-dotenv loads DATABASE_URL from a .env file in the project root..env entries:
SessionLocal
The session factory is defined indatabase.py and is the only object pages should import to open a database session:
db = SessionLocal() and are responsible for calling db.close() — typically in a try/finally block. Services receive db as a parameter and must never create or close sessions themselves.
Engine configuration
The engine is created differently depending on the database backend detected fromDATABASE_URL.
- SQLite
- PostgreSQL
check_same_thread=False is required because Streamlit runs page scripts in threads that are different from the thread that created the connection.init_db.py
Runinit_db.py once on first setup. It is safe to re-run at any time.
Create all tables
Calls
Base.metadata.create_all(bind=engine), which creates every table defined across all model files. Tables that already exist are left unchanged.Run migrations
Calls
run_migrations(), which executes a series of additive ALTER TABLE statements. Each statement adds a column only if it does not already exist, so the function is fully idempotent.run_migrations() is safe to re-run on an existing database. It never drops columns, changes types, or removes data. Running init_db.py again after a code update will apply any new columns added since the last run without affecting existing rows.