Alembic
Alembic provides version-controlled database migration management for support systems built on SQLAlchemy. Create, test, and deploy schema changes across environments while preserving data integrity and enabling safe rollbacks.
Alembic helps you manage and version control database schema changes through automated migration scripts.
AI-generated summary based on this skill's SKILL.md
Install
manutej/luxor-claude-marketplace/alembic · repository language: Shell
git clone https://github.com/manutej/luxor-claude-marketplace
cp -r luxor-claude-marketplace ~/.claude/skills/alembicgenerated, unverified - the skill's exact subdirectory could not be determined; check the repository on GitHub
npx skillfed install manutej/luxor-claude-marketplace/alembicFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What is Alembic and how does it manage database migrations?
Alembic is a database migration tool that provides version-controlled schema change management for SQLAlchemy-based applications. It enables you to create, test, and deploy schema changes across environments while preserving data integrity and enabling safe rollbacks. Alembic tracks all modifications to your database structure, allowing teams to collaborate on schema evolution without manual SQL management.
How do you use Alembic for schema changes in your database?
Alembic manages schema changes through a structured workflow: initialize your project with `alembic init`, define your SQLAlchemy models, auto-generate migration scripts using `alembic revision --autogenerate`, review the generated Python migration files, and apply them with `alembic upgrade head`. Each migration is version-controlled and can be reviewed before deployment, ensuring safe and traceable schema evolution.
Can Alembic auto-generate migrations from SQLAlchemy models?
Yes, Alembic can auto-generate migrations from your SQLAlchemy declarative base models. Using the `alembic revision --autogenerate` command, Alembic compares your current model definitions against the database schema and creates migration scripts that capture the differences. This automation reduces manual SQL writing while maintaining full control through code review before applying changes.
How does Alembic enable rollback and downgrade of database changes?
Alembic tracks database modifications through revision history, allowing you to downgrade or rollback changes using the `alembic downgrade` command. You can revert to any previous schema version by specifying the target revision. Each migration script contains both upgrade and downgrade logic, enabling safe reversal of changes if issues arise during deployment or testing.
What role does env.py play in Alembic configuration?
Alembic's env.py is the core configuration file that controls how migrations execute. It defines database connection settings, logging behavior, and the migration context. You customize env.py to support different environments (development, staging, production), configure SQLAlchemy engine creation, and control whether migrations run in online or offline mode for flexibility in deployment scenarios.
How do you initialize Alembic in a new project?
Initialize Alembic in a new project using `alembic init <directory_name>`, which creates the migration environment with subdirectories for versions, configuration files (alembic.ini and env.py), and templates. Configure the database connection string in alembic.ini, link your SQLAlchemy models to the migration context, then begin creating migrations. This setup establishes version control for all future schema changes.