Questions tagged [alembic]

Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.

Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.

Some of the important operations that can be performed with alembic are

  • Upgrade(Perform Database migrations, Example: create/alter/modify)
  • Downgrade(Its the reverse operation of upgrade to undo the upgrade changes)
  • Current(Show the current revision and state of migration in the database)
  • Init(Initialize a new scripts directory)
  • Revision(Create a new revision file)

Related tags

References

854 questions
2
votes
1 answer

How to detect changes with alembic without creating a revision?

I'm trying to abstract some functionality from my models into a Mixin, and I don't actually want to change any tables — I just want to check to make sure I've done this correctly. How can I see what changes alembic detects without creating a…
Jesse
  • 860
  • 1
  • 11
  • 13
2
votes
1 answer

Override values in alembic env.py file

I am using alembic for database revisions pretty much as intended probably. Instead of defining the database string in alembic.ini, I am using the env.py file to dynamically get the database credentials from the config module, pretty much as…
Daniel
  • 1,398
  • 4
  • 20
  • 47
2
votes
0 answers

Where should I put alembic's generated folder?

I'm starting a fastapi project, and using sqlalchemy + alembic to manage the sqlite db. Everything worked fine till alembic. Here's the project folder structure: app/ - api/ - core/ - __init__.py - settings.py - db/ - __init__.py …
CSSer
  • 2,131
  • 2
  • 18
  • 37
2
votes
1 answer

How to declare NOT VALID PostgreSQL constraints with SQLAlchemy and alembic?

I'd like to create a PostgreSQL CHECK constraint that is marked as NOT VALID, yet I don't see a way to create such constraint in alembic or declare it using SQLAlchemy. It looks like SQLAlchemy added support for introspection of NOT VALID…
user8808265
  • 1,893
  • 1
  • 17
  • 25
2
votes
1 answer

using .env variables when configuring env.py file in alembic

Based on the posts I've seen this is the most common way to point the alembic.ini sqlalchemy.url to a desired db path in the alembic env.py file import os from logging.config import fileConfig from sqlalchemy import engine_from_config from…
Ben_Sven_Ten
  • 529
  • 3
  • 21
2
votes
0 answers

Python Virtual Environment in Azure Release Pipeline

I am using Alembic as mean to perform my database migrations and upgrades. I whish that this migration step would be done by my Azure Release Pipeline to run this basic script: CALL activate ./venv cd alembic alembic upgrade head My issue is that I…
2
votes
1 answer

How to migrate new Python Enum members in SQLAlchemy for PostgreSQL in semi-automated manner?

I am adding new enum members in an SQLAlchemy migration using Alembic migration tool. SQLAlchemy uses Python native Enum as: from enum import Enum class MyEnum(Enum): # Key and value names different to clarify they are separate # concepts…
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
2
votes
0 answers

Alembic: Naming convention including %(constraint_name)s token requires that constraint is explicitly named?

I have two tables in the same migration: op.create_table( "oauth2_code", sa.Column("code", sa.String(length=120), nullable=False), sa.Column("client_id", sa.String(length=48), nullable=True), sa.Column("redirect_uri",…
QLands
  • 2,424
  • 5
  • 30
  • 50
2
votes
1 answer

Flask-Migrate cannot downgrade to a down_revision with merged heads

I have got this weird issue I ran into when downgrading my migration versions in Flask using Flask-Migrate. I have this merged head revision which happened from branching and an alembic merge heads. """empty message Revision ID:…
A. Josh
  • 41
  • 5
2
votes
1 answer

alembic migrations with sqlmodel attempts to alter primary key colum

Given this model: from typing import Optional from sqlmodel import SQLModel, Field class SongBase(SQLModel): name: str artist: str = Field(index=False) #label: Optional[str] = Field(None, index=False) year: Optional[int] =…
Trondh
  • 3,221
  • 1
  • 25
  • 34
2
votes
0 answers

Use loguru with alembic

I want to use Loguru as the Alembic logger handler. Do you know if and how I can do it? I only know there are some logging properties inside alembic.ini Right now I'm seeing the two loggers mixing things up in my console: 2021-10-25 23:12:59.484 |…
A.B.
  • 105
  • 1
  • 8
2
votes
1 answer

Issue with using alembic with Azure Synapse SQL DW

Im trying to create alembic migrations for Azure Synapse DW. Im constantly getting following error : [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]111214;An attempt to complete a transaction has failed. No corresponding transaction…
ASHISH M.G
  • 522
  • 2
  • 7
  • 23
2
votes
1 answer

SqlAlchemy/ALembic migrations - how to ignore errors and apply migration

I have the following migration: def upgrade(): # ### commands auto generated by Alembic - please adjust! ### try: op.drop_index('idx_token_attribute_name', table_name='token_index') except Exception: logger =…
Huy
  • 10,806
  • 13
  • 55
  • 99
2
votes
0 answers

Alembic toggling multiple database using environment variables

I have a question about alembic multidb template or using alembic for multiple database in general. Our project has your usual three levels of database (development, testing, production). Depending on which level of database and whether it runs via…
Tata
  • 147
  • 1
  • 1
  • 9
2
votes
0 answers

Alembic/Migrate does not recognize a materialized view

I have created a postgres materialized view following Jeff Windman's methodology from here: How to make SQLAlchemy custom DDL be emitted after object inserted? and here: http://www.jeffwidman.com/blog/847/ The view factory and the model were adapted…
grommit
  • 169
  • 2
  • 14