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

Convert postgres column type from enum to array of enums

I currently have a table called employees having column access_level of type enum (accessLevel). But now I want to provide the employee multiple access_levels so now I need to convert the datatype from enum to array of enum. I ran the following…
Striker
  • 67
  • 7
1
vote
1 answer

Problems setting up Alembic with Google Cloud Spanner

I am trying to set up Alembic to work with Google Cloud Spanner, but no matter what I try I end up with one of the following errors when attempting to run a simple "alembic upgrade head": sqlalchemy.exc.NoSuchModuleError: Can't load plugin:…
MacBlimp
  • 11
  • 1
1
vote
0 answers

"VACUUM cannot run inside a transaction block" on postgres, alembic and sqlalchemy

After dropping a big column in Postgres with alembic, I want to clear it's used space so I'd like to run a VACCUM FULL. When trying to execute the command I get the following error: sqlalchemy.exc.ProgrammingError: (pg8000.dbapi.ProgrammingError)…
RoieL
  • 109
  • 7
1
vote
2 answers

Start from another min value when max value is reached on Postgres Sequence

I have this Sequence defined in sqlalchemy for postgres import sqlalchemy as sa user_id_sequence = sa.Sequence(name='user_id_seq', start=100000, increment=10, …
Chubutin
  • 165
  • 2
  • 9
1
vote
0 answers

Customizing sqlalchemy create table DDL for alembic+snowflake

I'm using sqlalchemy declarative models to create my snowflake schema, but since sqlalchemy generates ddl using lower-case identifiers, and snowflake uses upper-case identifiers, alembic can never conclude that a table already exists in snowflake…
Peter Dowdy
  • 439
  • 2
  • 16
1
vote
1 answer

Alembic 1.8 + DEFERRABLE INITIALLY IMMEDIATE

I am now using Alembic 1.8, SQLAlchemy 1.4 and PostgreSQL I would like to set my FK constraints as "DEFERRABLE INITIALLY IMMEDIATE". I passed the FK options as shown below: sa.Column( "group_id", sa.BigInteger, sa.ForeignKey( …
pincoin
  • 665
  • 5
  • 19
1
vote
0 answers

Alembic: How to alter column datatype from Enum to Text?

I'm trying to convert a column datatype from an Enum to Text using Alembic with SQLAlchemy PostgreSQL. In my migration file, the upgrade function works perfectly fine and it's able to convert the type from an Enum to Text, but the downgrade doesn't…
HudZah
  • 55
  • 1
  • 8
1
vote
1 answer

unable to perform flask-migrate migrations on cloud SQL

I am trying to implement flask-migrate with cloud SQL database. for this, I created a PostgreSQL instance on cloud sql. following is my app.py file from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import…
1
vote
0 answers

unable to connect alembic to Cloud sql

I am trying to run alembic on GCP cloud shell and do some basic schema migrations on cloud SQL. for the setup, I created a MySQL instance on cloud SQL and created a database and user. I installed alembic on the cloud shell and did "alembic init…
1
vote
1 answer

GitHub workflows doesn't find a module

I'm trying to configure tests in the GitHub workflows for my FastAPI application. My alembic.ini -file is located in app folder. The alembic ´env.py´ is located in app/alembic. This is how I try to run migrations: - name: Migrate env: …
lr_optim
  • 299
  • 1
  • 10
  • 30
1
vote
0 answers

Index a relationship in SQLAlchemy and Almbic

I have two tables like bellow: Table 1: class Table1(Base): __tablename__ = "table1" id = Column(UUID, primary_key=True) created_at = Column(DateTime(True), nullable=False, server_default=func.now()) status_id = Column(ForeignKey("lookups.id"),…
magerine
  • 43
  • 4
1
vote
2 answers

Create CompositeArray of CompositeType without using sqlalchemy_utils

Within my FastAPI, SQLAlchemy, Alembic project, I was using postgresql engine, and now I'm trying to migrate to async with postgresql+asyncpg. The issue here is that one of my DB schemas has this structure: class MyTable(...): __tablename__ =…
lvl
  • 109
  • 3
  • 6
1
vote
1 answer

pg_restore: error: unrecognized data block type (0) while searching archive while trying to import postgres database to heroku

I was trying to import a local database to Heroku, I got inspired from this StackOverflow question Push database to Heroku: how to use Heroku pg:push. The command I was running was PGUSER=postgres PGPASSWORD=mypassword heroku pg:push mydatabse_name…
DINA TAKLIT
  • 7,074
  • 10
  • 69
  • 74
1
vote
0 answers

Python, sqlalchemy compare the model and the table in the database

Is it possible to compare a model and a table in a database and print out the difference between them? For example different columns, different data types of columns. I don't need migrations, just compare model and table. Thanks.
1
vote
0 answers

Alembic migration : How to alter table to add gin index

def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('person', sa.Column('__ts_vector__', postgresql.TSVECTOR(), sa.Computed("to_tsvector('english', name || ' ' || surname)", persisted=True),…
magerine
  • 43
  • 4