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
3
votes
1 answer

Alembic: how to add a new enum type in migration script without resorting to `alembic.op.execute`

I'm trying to create a new migration on Alembic, that adds a new column of a new Enum type to an existing table. But I'm getting an error that I thought Alembic would've automatically handled. I'm using Postgres 9.6.6, Alembic 0.9.10, and…
Eric Fulmer
  • 706
  • 2
  • 6
  • 23
3
votes
0 answers

Migrate SQLAlchemy models having dates without timezone to ones with timezone

I have some SQLAlchemy models defined like this: class TimeData(object): __table_args__ = {"extend_existing": True} created_on = Column(DateTime(timezone=True), server_default=db.func.now()) updated_on = Column( …
Arunmozhi
  • 1,034
  • 8
  • 17
3
votes
1 answer

How to run post upgrade code in alembic upgrade head

I am modifying a model(adding a new column) and I have a corresponding migration file. My goal is to extend this migration by adding some data to the new column. I tried to modify the migration file by adding my own sql code to achieve my goal.…
3
votes
1 answer

Do "alembic current" and "alembic history" search different paths?

I'm using Alembic with SQLAlchemy to do a schema migration and a data migration. Since I have stored migration-specific dependencies in their own module within my project's main application myapp (as per Michael Bayer's recommendation), I have run…
Nathaniel Jones
  • 939
  • 1
  • 14
  • 25
3
votes
1 answer

flask-migrate make migrations in alphabetical order

Using flask-migrate and flask-script, I set my project up, such that I only have to do python manage.py db migrate Inside the migrations folder, I get files such as 0f46602752b7_.py 8fdf8259859b_.py There is no guarantee that the first migration…
Andrei Cioara
  • 3,404
  • 5
  • 34
  • 62
3
votes
0 answers

Combine multiple Alembic version tables into a single table

Alembic version tables are an awesome way to manage multiple modules and apps migrations within a single database. I created multiple alembic_version tables based on apps and modules just as shown in Alembic few modules to single database. But the…
Tejus Prasad
  • 6,322
  • 7
  • 47
  • 75
3
votes
1 answer

Python alembic offline mode without alembic_version table

I'd like to use alembic in offline mode, and execute the SQL migrations from an external software. The external software tracks the DB version, so I don't need the alembic_version table at all. Do you know if I can generate SQL migrations without…
Kiruahxh
  • 1,276
  • 13
  • 30
3
votes
1 answer

How should a SQLAlchemy-Searchable trigger be removed using Alembic

I'm trying to correctly setup my database migration files and haven't found explicit syntax for the downgrade part. Using Flask-SQLAlchemy, Postgres and Flask-Migrate which uses Alembic My (reduced) code looks like this: from alembic import…
Sobigen
  • 2,038
  • 15
  • 23
3
votes
1 answer

alembic post migration commands

Due to some quirks in our database we need to reassign table owners post creation. Currently we leverage Alembic - has anyone got a simple way to create some sort of post hook that runs certain SQL commands after a migration?
CogitoErgoSum
  • 2,879
  • 5
  • 32
  • 45
3
votes
2 answers

sqlalchemy + flask: class is not defined

i'm using sqlalchemy + alembic + Flask and i can't map circular classes. apps/users/models.py: class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) email = Column(String) password = Column(String) …
3
votes
2 answers

How do I find the latest migration created w/ flask-migrate?

My flask application now has 20+ migrations built with flask-migrate and they all have hashed file names like: 389d9662fec7_.py I want to double check the settings on the latest migration that I ran, but don't want to open every file to look for the…
rykener
  • 711
  • 1
  • 6
  • 16
3
votes
1 answer

Alembic: Include constraint to reject strings with character

I have a table that looks like this > select * from mytable id value 0 1 hello world 1 2 hello_world 2 3 hello+world I'm trying to impose an alembic check constraint, where values in value cannot have the : character. How would I do…
hlin117
  • 20,764
  • 31
  • 72
  • 93
3
votes
1 answer

Skip alembic revision depending on backend

I have a revision in Alembic that depends on a particular backend, but on which the semantics do not explicitly depend on it (only makes things faster). I want my code to not depend on the particular backend (i.e. the revision not give an error when…
Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
3
votes
2 answers

Alembic not handling column_types.PasswordType : Flask+SQLAlchemy+Alembic

Background I'm trying to use a PostgreSQL back-end instead of Sqlite in this Flask + RESTplus server example. I faced an issue with the PasswordType db column type. In order to make it work, I had to change the following code in…
patlachance
  • 101
  • 1
  • 6
3
votes
2 answers

Flask Sql-alchemy not dropping tables created by alembic

I have flask application with Flask-migrate. Running db upgrade creates following tables: List of relations Schema | Name | Type | Owner -------+-----------------+-------+---------- public | alembic_version | table |…