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

Will Flask-Migrate migrations work across different database engines?

I am writing a Flask application that uses Flask-SQLAlchemy and Flask-Migrate. Production has a PostgreSQL database, but for development, I was hoping to use SQLite instead of having to install full PostgreSQL on my development machine. I set up…
Dominick Pastore
  • 4,177
  • 2
  • 17
  • 29
2
votes
3 answers

Sqlalchemy sqlite url relative to home or environment variable

A relative sqlalchemy path to a sqlite database can be written as: sqlite:///folder/db_file.db And an absolute one as: sqlite:////home/user/folder/db_file.db Is it possible to write a path relative to home? Like…
jabozzo
  • 591
  • 1
  • 6
  • 17
2
votes
0 answers

SQLAlchemy metadata conflict between model imports and alembic schema upgrade in test

I have a Flask application with a PostgreSQL database, Alembic migrations and SQLAlchemy. Recently I started writing an integration test against the database. I import a model, say Item, that is mapped to table "item" and doing "from models import…
CptPicard
  • 196
  • 1
  • 5
  • 17
2
votes
1 answer

Importing separate script in alembic revision

I have a few functions in my Alembic migrations that tend to be used in multiple revision scripts (for example, adding creation/updated timestamps to a table). I'd like to not need to copy-paste the same function over and over, but I've been having…
pipai
  • 21
  • 2
2
votes
0 answers

Alembic execute SQL as part of migration

I want alembic to get the current stored procedure from DB compare it to the one in the code. If they are different to update the DB. I edited the env.py file to check for this, and generate an upgrade versions of the raw SQL. when running the…
Lev
  • 999
  • 2
  • 10
  • 26
2
votes
1 answer

Flask-Migrate creates the same duplicate migration when used with postgres schemas

I have a very simple and silly problem but I don't know what I'm missing. Basically, the way I've currently written my manage app, it seems flask migrate always creates an absolute migration and not just a change-set to migrate from the previous…
s5s
  • 11,159
  • 21
  • 74
  • 121
2
votes
3 answers

How to directly access SQLite database to delete alembic_version table?

I am building a Flask web app, and at some point accidentally deleted a migration file for my SQLite database. I am using SQLAlchemy in Flask for database commands, and flask-alembic for migrations. I am trying to delete the "alembic_version" file…
Drew Petersen
  • 25
  • 1
  • 4
2
votes
0 answers

Is it possible to connect to another database during an alembic migration upgrade?

I am performing a standard alembic migration on Database A, however, there is a table in Database B I will need to query during my upgrade. Is it possible to connect to Database B to query and retrieve the result during the upgrade on Database A? db…
2
votes
1 answer

Modfying ForeignKeyConstraint schema in Alembic post process

I'm using process_revision_directives to apply some post-processing of the operations generated against a reference schema. The one I'm stuck on is removing the postgres schema from the instructions, so it can be generically changed at runtime using…
Gricey
  • 1,321
  • 1
  • 18
  • 38
2
votes
0 answers

Alembic --automigrate generates an empty commit

Trying to auto generate initial Alembic files. I have a flask app and I need to set up Alembic to keep track of the database. I generated a fresh dbmodels.py file with the current schema using sqlacodegen…
Lev
  • 999
  • 2
  • 10
  • 26
2
votes
2 answers

How do you create a sequence using Sqlalchemy and add that particular sequence to a table?

rollback.py : def write_to_db(dataset_id): try: initialize_datamodels() EpdUmpPushRollback = datamodels.relational_tables.EpdUmpPushRollback with session_scope() as session: epdumppushrollback_obj =…
Vishal Patil
  • 65
  • 1
  • 5
2
votes
0 answers

Sharing project code with DB migration code

Sometimes we want to share project code with DB migration scripts, e.g. utilities and models, for readability, usability, fast development and all that. The issue is that each migration script should have its own copy of the shared code, or else we…
Sagi
  • 592
  • 5
  • 15
2
votes
0 answers

How to avoid "TypeError: argument 2 must be a connection, cursor or None" with SQLAlchemy/psycopg2 when creating engine from engine_from_config()

After patching psycopg2 with the latest aws-xray-python-sdk (v2.2.0), my alembic script started to throw exception : TypeError: argument 2 must be a connection, cursor or None. The `TypeError: argument 2 must be a connection, cursor or None` in…
ThatChrisGuy
  • 559
  • 2
  • 7
  • 23
2
votes
1 answer

SQL Alchemy update time not working in Alembic revision

I have a column in an alembic revision for update_time to show when the Column is updated. Currently I have tried: sa.Column('update_time', sa.dialects.mysql.DATETIME(fsp=3), nullable=False, server_default=str(datetime.utcnow()),…
William Ross
  • 3,568
  • 7
  • 42
  • 73
2
votes
1 answer

SqlAlchemy alembic migration files dont use the connection settings in env.py?

I have a migration that works on a generic schema named tenant_schema. In the run_migrations_online function in env.py i set up a schema_translate_map for tenant_schema. I expected sqlalchemy to translate this migration operation to run on the…
moshevi
  • 4,999
  • 5
  • 33
  • 50