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
0 answers

Is there a way for Alembic's migration metadata and SqlAlchemy's ORM mapping metadata to be shared automatically?

Been coming up to speed with SqlAlchemy and Alembic (for migration). I understand that the Alembic revision files get "locked down" as a form of documentation of the migration history. That said, it seems like there ought to be a way to "flatten"…
ipmcc
  • 29,581
  • 5
  • 84
  • 147
2
votes
0 answers

How do I change a sqlalchemy model to reflect a migration done using alembic?

I have a model defined using sqlalchemy, something like: class Recommendation(Base): """ An entry is created by each recommender per URL """ __tablename__ = 'recommendation' id = Column(Integer, primary_key=True) url_id =…
mmr
  • 14,781
  • 29
  • 95
  • 145
2
votes
0 answers

Alembic/SQLAlchemy after_create not triggering

I'm working on a project where I need to attach some custom triggers to a table that's defined using SQLAlchemy, and controlled using Alembic. Right now, I have a simple loop that attaches a after_create event to each declarative table…
Fake Name
  • 5,556
  • 5
  • 44
  • 66
2
votes
0 answers

Alembic autogenerate does not generate upgrade script

I am using sqlalchemy and postgressql in Flask application. The migration tool that I am using is alembic=0.6.3. if I type alembic current it shows me: Current revision for postgres://localhost/myDb: None which is correct database connection. But…
Max
  • 2,425
  • 6
  • 35
  • 54
2
votes
1 answer

Perform alembic upgrade in multiple schemas

I am using flask + sqlalchemy + alembic + postgresql, and am trying to find a simple architecture to solve the following problem. I have a simple database structure, lets say two tables : -- Users -- UserItems My users are in several different…
Noam
  • 1,881
  • 1
  • 12
  • 20
2
votes
1 answer

Sqlalchemy (and alembic) Concrete table inheritance without polymorphic union

I'm new to SQLAlchmey, and I'm trying to achieve the following objects/db tables structure (by using alembic as well): class BaseConfig(Base): pk = Column(Integer, primary_key=True) name = Column(Unicode(150), nullable=False, unique=True) ... #…
Lin
  • 2,445
  • 5
  • 27
  • 37
2
votes
0 answers

Include alembic as part of a custom installer script, to create or upgrade database?

I am sending users a python script which will install our product. As part of the installation, I want to be able to create a set of database tables as well. It seems that alembic would be perfect for the job; because for each upgrade of our…
David H
  • 1,461
  • 2
  • 17
  • 37
2
votes
1 answer

How to use custom template during alembic initialization

According to the docs, alembic's template can be specified as alembic init --template pylons ./scripts. But alembic searches for templates in only one folder in its root (python_path/lib/python2.7/site-packages/alembic/templates). Is there any way…
AlexanderLedovsky
  • 727
  • 1
  • 6
  • 18
2
votes
1 answer

Alembic --autogenerate fails for me

The command I'm running: alembic -c development.ini revision --autogenerate -m "test" I get the following result: Traceback (most recent call last): File "/Users/charleswesley/.virtualenvs/foundation/bin/alembic", line 9, in
shroud
  • 725
  • 8
  • 13
2
votes
1 answer

python: How can I test my database model using in-memory db?

I am developing a project in Flask and using SQLAlchemy as ORM I have a User model as class User(UserMixin, db.Model): __tablename__ = 'users' # noinspection PyShadowingBuiltins uuid = Column('uuid', GUID(), default=uuid.uuid4,…
daydreamer
  • 87,243
  • 191
  • 450
  • 722
1
vote
1 answer

Alembic does not recognize the default schema when creating initial migrations

I'm at my wits end here. I'm trying to create an initial migration to my Postgres database using alembic. I'm autogenerating the migration from my SQLAlchemy ORM models. Here's my models.py file: from typing import List, Optional from sqlalchemy…
P4nd4b0b3r1n0
  • 1,951
  • 3
  • 22
  • 31
1
vote
1 answer

NameError: name 'User' is not defined (Python @classmethod not recognizing class defintion)

Using Python 3.11 with SQLAlchemy==2.0.18, alembic==1.11.1, fastapi==0.100.0, pydantic==2.0.2 The class is defined above, with a classmethod below it. User.py from .base import Base class User(Base): __tablename__ = "users" id: Mapped[UUID] =…
1
vote
1 answer

Alembic - composite primary key results in incorrect table definition for MySQL

I have multiple "versioned" database SQLALchemy models that use a composite primary key by combining an auto-increment int field ("id") and a datetime field ("record_valid_from"). I'm trying to run this against a MySQL database setup locally in a…
1
vote
0 answers

Alembic Migration giving DuplicateColumn Error but the column doesn't existed before

I am trying to run alembic migration via the bitbucket pipeline. Below is the code of the bitbucket pipeline. steps: - step: &health-check name: Health Check script: - export…
Paras jain
  • 432
  • 3
  • 15
1
vote
1 answer

Alembic : Ignore a schema and its tables but also use foreign key constraint on one of it

I have a project where one of the DB Schema ("alpha") was already existing, and it comprises of "user" table. The entire schema and its tables were being managed using go and goose, and contains all the auth related tables. Now, my team wants to…
Ouroboros
  • 1,432
  • 1
  • 19
  • 41