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

Is adding an api interface to an alembic model a bad idea?

I'm using a distributed selenoid cloud infrastructure to distribute my automated tests. In order to keep track of the selenoid instances I have a selenoid table in MySQL which tracks which selenoid instances are enabled and disabled. I have this…
Ryan Nygard
  • 200
  • 8
0
votes
0 answers

SQLAlchemy delete-orphan behavior

I have a situation where I want to create a many-to-one relationship between Tasks and their respective execution period (period chosen from one of two tables as shown below): Task Table class Task(Base): id = Column(Integer, primary_key=True) …
Jai Mehra
  • 21
  • 2
0
votes
0 answers

How to perform a data migration with Alembic and two versions of my Table?

I'm trying to refactor a database model; separate one column out of a table into another new one. I'd like to do this using existing SQLAlchemy Core models & Alembic. I'd also like to use server-side INSERT ... FROM SELECT ...-style query to migrate…
gertvdijk
  • 24,056
  • 6
  • 41
  • 67
0
votes
1 answer

How to cascade delete from parent using alembic?

Maybe I'm missing something here that is super simple, but I have a postgresql db that has several tables structured as such: - releases |- releases_contributions |- releases_primary contributions |- recording |- recording_contributions |-…
Kevin G
  • 168
  • 2
  • 15
0
votes
1 answer

Updating models breaks past alembic migrations

I have a series of alembic migrations similar to the following # 1 def upgrade(): op.create_table('my_model', sa.Column('id', sa.Integer(), nullable=False), sa.Column('text', sa.Text()) ) # 2 def upgrade(): my_model =…
Jim Jeffries
  • 9,841
  • 15
  • 62
  • 103
0
votes
1 answer

How do I get Alembic to emit a length constraint on a TEXT column?

I'm not sure if it's actually called "length constraint", but I have a SQL statement that works when testing in a local docker container with mysql: create unique index _uq_data on data(question_id, reply_id, text(50)); The constraint/length…
Per Fagrell
  • 835
  • 7
  • 15
0
votes
1 answer

How to use SQLAlchemy models to generate raw SQL which is able to create all tables?

It is possible to generate raw SQL statement to create any SQLAlchemy table as shown here. However, I would like to generate raw SQL which creates all tables, not just one. Let's assume I have such tables (this table design is not real-world, but it…
Karol Zlot
  • 2,887
  • 2
  • 20
  • 37
0
votes
1 answer

Inner Join syntax error in Alembic execute

I have a "DevAssociation" table with columns prod_id and dev_id where dev_id is a fk from DevRun, I would like to move prod_id to DevRun table, so I created a new column in DevRun called prod_id. Then I am doing the following SQL command to move the…
A1122
  • 1,324
  • 3
  • 15
  • 35
0
votes
1 answer

How to initialize Alembic on an existing DB

I have an existing app which uses SQLAlchemy for DB access. It works well. Now I want to introduce DB migrations, and I read alembic is the recommended way. Basically I want to start with the "current DB state" (not empty DB!) as revision 0, and…
user124114
  • 8,372
  • 11
  • 41
  • 63
0
votes
2 answers

Alembic Primary Key issue with mssql ( Azure Synapse SQL DW )

Im trying to apply migrations using alembic to Azure Synapse SQL DW. Im facing following issue while performing alembic upgrade head: sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL…
ASHISH M.G
  • 522
  • 2
  • 7
  • 23
0
votes
1 answer

Alembic: put a "version_num" for each schema

In my team we have multiple projects/microservices all hosted on the same database, but each service has a specific schema. I want to manage the migrations of each project independently of other projects, a way of achieving that could be to specify…
Be Chiller Too
  • 2,502
  • 2
  • 16
  • 42
0
votes
0 answers

Python SQLAlchemy Alembic Migrations on Multiple Models

I have checked out Alembic Migrations on Multiple Models but the I way I build my SQLAlchemy models is different. In src/models/__init__.py: from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() from .Model1 import Model1 MyMetadata =…
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
0
votes
1 answer

Is it possible to update the properties of a table with Flask + SQLAlchemy?

I created a table model that has a 'unique=true' property (flask code) class Books(db.Model): id = db.Column(db.Integer, unique=True, primary_key=True) name = db.Column(db.String(255), unique=True, nullable=False) author =…
Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
0
votes
0 answers

How to specify encoding in Alembic migrations

I am working to add Alembic migration to a legacy project. I am hoping to execute some raw sql, including some insert statements with unicode that I want to be encoded with UTF-8, but am getting a UnicodeDecodeError. To reproduce this error, I…
Stew
  • 4,495
  • 6
  • 31
  • 41
0
votes
2 answers

ID primary key of ONE to MANY related tables jumping numbers with POSTGRESQL

I am having an issue where the id column of tables users and posts are jumping in increments users and have many notes ==> one to many relationship table users id | email | first_name | last_name | password ==================================== 1 …
uberrebu
  • 3,597
  • 9
  • 38
  • 73