feat: Implement Alembic database migrations#9
Merged
Conversation
Implement Alembic-based database migration system to enable safe schema evolution and version control for database changes. Migrations automatically apply at startup, replacing the previous create_all() approach. Includes comprehensive documentation and support for both SQLite and PostgreSQL. Key changes: - Add Alembic configuration and initial migration with all current models - Enhance database abstraction with PostgreSQLConfig support - Add run_migrations() method with automatic fallback to create_all() - Include detailed MIGRATIONS.md with usage examples and best practices
Move model imports to top of file following standard Python conventions. The database URL configuration doesn't need to happen before model imports, so there's no reason to deviate from normal import ordering. This eliminates E402 linting errors without requiring noqa suppressions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
7126c91 to
b5b1a47
Compare
- Removed unnecessary package find configuration in pyproject.toml.
…ations - Deleted the main FastAPI application file to streamline the backend structure. - Updated database management to utilize Alembic migrations instead of manual table creation. - Introduced a new initial schema migration file for database setup. - Adjusted database connection logic to support migration execution with optional reset functionality.
- Move alembic/ and alembic.ini into syftai_space/ for PyPI compatibility - Add migration for ingestion_jobs and marketplaces tables - Implement dev/prod migration behavior: - DEBUG=true: fallback to create_all + stamp on failure - DEBUG=false: fail loudly on migration errors - Fix env.py to respect programmatically-set database URL - Add all entity imports to env.py for autogenerate support
- Add justfile with commands for migration management: - status, upgrade, downgrade, downgrade-all - generate, merge-heads, check - wipe, rebuild, reset-to-release - validate-release, mark-release - Add RELEASE_MARKER to track last released migration - Add CI workflow for migration validation on PRs - Rewrite MIGRATIONS.md as beginner-friendly guide with: - Scenario-based workflows - Clear command reference - Troubleshooting section - Consolidate migrations into single initial schema
shubham3121
added a commit
that referenced
this pull request
May 4, 2026
- #9: rename InvoiceStatus.FAILED -> CANCELLED. Maps Xendit's payment_session.canceled event onto a distinct status (was lumped under EXPIRED), giving the previously-orphaned enum value a real path. Earnings page references and dropdown label updated. No DB migration needed: the status column is a plain string with no CHECK constraint and no rows carry the old "failed" value (no path ever set it). - #12: get_user_balance now rejects non-gateway wallet types (e.g. MPP) with HTTP 400 instead of silently returning 0.0. Mirrors the wallet-type validation already in create_invoice. - #13: add a TODO on list_for_tenant noting that pagination + date-range filters are wanted before any tenant exceeds ~5k invoices. Defer until there's a concrete scale need. - #17: fix EndpointRepository.get_by_id type hint (was int, column is UUID). Pre-existing nit. Skipped: #11 (endpoint hard-delete clears endpoint_id from ledger via SET NULL cascade) — design call, current behavior is defensible since the archived flag exists for soft-delete.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a complete Alembic-based database migration management system for the backend, including developer tooling, CI automation, and project configuration. The changes add migration dependencies, configuration files, and developer scripts, and establish a release marker for tracking migration state.
The most important changes are:
Migration Infrastructure & Tooling
pyproject.tomlto enable database migrations.justfilewith commands for migration status, upgrades/downgrades, conflict resolution, database rebuild/reset, and release validation for developer convenience.Alembic Project Configuration
alembic.iniand a custom migration script templatescript.py.makofor consistent migration generation and logging. [1] [2]alembic/env.pyto integrate with SQLModel, auto-discover entities, and support both offline and online migration modes.CI Automation
migration-check.yml) to check for migration conflicts and test fresh installs on every pull request to backend code.Release Management
RELEASE_MARKERfile to track the latest released migration revision and version, supporting reproducible database states and upgrade/downgrade testing.