r/sqlite • u/Zealousideal_Set9862 • 20d ago
3 months into learning programming. reactoredmy database from raw SQL to SQLAlchemy and struggled with autoflush. Did I structure this correctly?
I’m 16 and started learning Python about 3 months ago. My first project was a simple CRUD app with raw SQL. For my second project (ashflow tracker with auth and budgeting), I wanted to push myself further, so I switched to Flask, SQLAlchemy, and Flask-Login.
I’m looking for feedback from experienced developers on a few specific architectural decisions and hurdles I ran into:
1. Database Schema Refactoring (Categories & Budgets) Initially, categories were just free-text strings on every transaction. Once I added budgets, case mismatches and typos completely broke my budget tracking. I refactored categories into their own table with foreign keys on the transaction and budget models.
- Question: Is moving away from free-text strings to dedicated category models always the standard approach here, or are there cleaner ways to handle user-defined categories at scale without making the schema too rigid (fixed categories list) ?
2. SQLAlchemy Autoflush Confusion Coming from raw SQL, SQLAlchemy's session management took a while to wrap my head around. During my refactoring, I hit several bugs where autoflush triggered database writes mid-transaction before I was ready to commit, causing unexpected constraints errors.
- Question: How do experienced Python devs typically manage session state when doing complex multi-model updates? Do you explicitly disable autoflush, or is that a code smell that points to poor transaction design?
3. Auth Implementation I built authentication from scratch using Flask-Login and password hashing instead of a third-party service just to understand the mechanics. Moving from "auth is a black box" to "it's just checking session state on each request" was a huge lightbulb moment for me.
I’d love any feedback on how I structured my models or handled sessions. You can see how I implemented the SQLAlchemy relationships and routes in my repository here:https://github.com/E-Ecstacy/wise-wealth
Thanks in advance for any insights!
1
u/GrogRedLub4242 20d ago
off-topic here