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

How to automatically test that an alembic migration is implemented properly

In alembic, we have to implement the upgrade and downgrade functions, for each migration we add. AFAIK the downgrade function is suppose to revert all changes made by the upgrade. Is there a way to automatically test if the downgrade function is…
Diogo Melo
  • 1,735
  • 3
  • 20
  • 29
0
votes
0 answers

Running alembic migrations on postgres with docker compose

I have a fastapi application that connects to postgres. I've dockerized the application such that the api runs in one container and postgres runs in another container on the same network and they can talk to each other happily. I want to make some…
0
votes
1 answer

Alembic - how to create hypertable

How to generate hypertable using Alembic? Some custom call must be added I suppose, but where? I tried event.listen but Alembic does not register it.
romanzdk
  • 930
  • 11
  • 30
0
votes
1 answer

how to perform an action when launching the app with FastAPI

I want to check when launching the application if there is an administrator in the user table. If it is not there, then it should be automatically added to the postgresql(sqlalchemy) table. Is it possible to do this? It turns out that I need to…
0
votes
1 answer

How can I use multiple postgres schemas with SQLAlchemy and Alembic

We have a postgres database with two schemas one for dev and one for prod. So we would like to migrate changes from our sqlalchemy orm first to dev, test it and then migrate them to prod. But Albemic is not really working with this. I started by…
0
votes
0 answers

Ignore a failed alembic migration

For the context: I am using a Postgres RDS which comes with some infinite timestamp for some default roles. Alembic (or more precisely, psycopg) does not like that at all. My first revision is updating some those timestamps to something legit (aka…
Guillaume
  • 2,325
  • 2
  • 22
  • 40
0
votes
0 answers

how to correctly rename an indexed column with alembic & sqlalchemy

so..I am perfectly able to rename a column using op.alter_column. HOWEVER, indices created for that column in the past still reference the old column name! e.g. Table name is dupe_check. The old column name was 'old_id', and the renamed column is…
doublea
  • 33
  • 4
0
votes
0 answers

Dynamically Adding a Column to a SQLAlchemy Table

I have a SQLAlchemy Table which is defined as: class Student(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.Text(), nullable=False) I am loading this table with data from a .csv file, and I may have columns…
0
votes
0 answers

Sqlalchemy event listen/remove behavior

From alembic migration version script, I added line below to surpass event trigger. My question is do I need to reregister at the end of the script? Or migration is using totally different session from the entire application, so it won't…
Libertatem
  • 71
  • 1
  • 6
0
votes
0 answers

How do I add a relationship to an existing table alembic sqlalchemy?

I'm doing an update on the existing table. I add new relation and Foreign Key Constraint. But i am getting error; sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (3780, "Referencing column 'product_id' and referenced column 'id' in…
Sheeva
  • 1
  • 1
0
votes
1 answer

Get alembic autogenerate migrations for all schemas in Postgres database

Expectation Support Postgres Multitenancy using Schemas with Sqlalchemy and alembic. Model class User(Base): __tablename__ = 'users' __table_args__ = ({"schema": "test"}) id = Column(Integer, primary_key=True) name =…
Manisha Bayya
  • 137
  • 1
  • 9
0
votes
1 answer

Flask-migrate (alembic) only detects changes in public schema

I have multiple schemas in my database, and several models per schema. Flask-migrate (which is Alembic) is unable to detect changes in any schema besides the public schema. Running flask db migrate followed by flask db upgrade will yield an error…
0
votes
0 answers

SQLAlchemy + Alembic - can I run ALTER TABLE without migrations?

My current flow for batch data processing looks like this: create tables with SQLAlchemy, fill them with data (lots of data, with Apache Spark), and then I want to add indexes. SQLAlchemy does not support ALTER TABLE statements, except for simple…
qalis
  • 1,314
  • 1
  • 16
  • 44
0
votes
0 answers

Alembic creates tables despite errors in migration upgrade()

I've a simple migration script which is supposed to create a few tables. For brevity, this is basically the content: op.create_table( 'a', sa.Column('id', sa.BIGINT, primary_key=True), ) op.create_table( 'b', sa.Column('id',…
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
0
votes
0 answers

Alembic: manage migrations from several apps in one schema

I want to implement tool that will manage migrations from several apps in my project using alembic. With following structure apps +- app1 | +- alembic | | +- versions | | | +- 0000_initial.py | | +- __init__.py | | +- env.py …
Alexander
  • 1
  • 2