Skip to content

feat: Implement Alembic database migrations#9

Merged
shubham3121 merged 8 commits into
mainfrom
feat/db-migrations
Jan 12, 2026
Merged

feat: Implement Alembic database migrations#9
shubham3121 merged 8 commits into
mainfrom
feat/db-migrations

Conversation

@shubham3121

@shubham3121 shubham3121 commented Nov 12, 2025

Copy link
Copy Markdown
Member

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

  • Added Alembic as a dependency in pyproject.toml to enable database migrations.
  • Added a comprehensive justfile with commands for migration status, upgrades/downgrades, conflict resolution, database rebuild/reset, and release validation for developer convenience.

Alembic Project Configuration

  • Added Alembic configuration file alembic.ini and a custom migration script template script.py.mako for consistent migration generation and logging. [1] [2]
  • Implemented Alembic environment config alembic/env.py to integrate with SQLModel, auto-discover entities, and support both offline and online migration modes.

CI Automation

  • Introduced a GitHub Actions workflow (migration-check.yml) to check for migration conflicts and test fresh installs on every pull request to backend code.

Release Management

  • Added a RELEASE_MARKER file to track the latest released migration revision and version, supporting reproducible database states and upgrade/downgrade testing.

shubham3121 and others added 2 commits November 18, 2025 18:26
 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>
- 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 shubham3121 merged commit 11f6ca6 into main Jan 12, 2026
2 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant