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

Alembic runs migration on each startup and executes the same revision repeatedly

I'm new to alembic so this is very likely a beginners fallacy. I have a FastAPI server which runs SQL migrations on startup. The problem is, that these migrations are being executed every time the server is starting up. This results in an error…
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
0
votes
2 answers

(Alembic, SQLAlchemy) Can I copy data from non partitioned key to a partitioned one in the migration script?

I have a table needs to be partitioned, but since the postgresql_partition_by wasn't added while the creation of the table so am trying to: create a new partitioned table that is similar the origin one. moving the data from the old one to the new…
0
votes
0 answers

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "postgres" to address: nodename nor servname provided

I am following a youtube tutorial to create an API using FastAPI. I am new to both Docker and FastAPI. I have managed to create a Docker container for the API and another one for the Postgres database using this Dockerfile and…
0
votes
2 answers

sqlalchemy change from immutable ARRAY type to mutable requires migration?

I use sqlalchemy 1.4 and alembic for migrations. Previously, my column type looked like this: has_bubble_in_countries = sa.Column((ARRAY(sa.Enum(Country))), nullable=False, default=[]) Which was not allowing me to add or remove any elements from…
Razvan
  • 143
  • 8
0
votes
0 answers

Alembic: run only changes necessary to reflect the latest datamodel instead of all revisions

A pet example to demonstrate what I want. Say I have a table User that looks like this: class User(Base): __tablename__ = 'user' id = Column(Integer, primary_key=True) name = Column(String, nullable=False) created_on =…
RogerKint
  • 454
  • 5
  • 13
0
votes
0 answers

Directly creating a pyodbc connection works but using sql.alchemyurl does not work

This works fully as expected. import pyodbc connection = pyodbc.connect("DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;DATABASE=test;UID=SA;PWD=", autocommit=True) Why is this and what is going on? However, when I…
RogerKint
  • 454
  • 5
  • 13
0
votes
0 answers

How to setup Alembic versioning for a specific schema in a database?

I have a database with multiple schemas in which multiple schemas exist and each schema has tables related to a different part of my business. I have a schema registration that contains relevant tables to a registration app. The tables related to…
RogerKint
  • 454
  • 5
  • 13
0
votes
1 answer

Alembic version in database is not in the version history

According to Alembic's docs, the migration algorithm is trying to calculate the migration "path" to target revision from the version it finds in the alembic_version table. Upon checking that in the db of the service I'm working with, I found out…
acalabash
  • 33
  • 5
0
votes
1 answer

Can I attach migrations to a corresponding data warehouse model using SQLAlchemy and Alembic?

Let's say I want to build a data warehouse using these two tools. I was thinking of something like root - database_schema -- table1.py (SQLAlchemy model) -- table2.py ... - database_schema2 -- table1.py ... - alembic However, alembic is creating…
romanzdk
  • 930
  • 11
  • 30
0
votes
1 answer

How to interrogate/alter a database sequence in python?

I'm using alembic and sqlalchemy to work with different database types. I use an own create_sequence-methode and the drop_sequence-method of Operations from alembic. Now I'm making unittests to test my functionality. I want to alter/interrogate the…
selinski
  • 13
  • 4
0
votes
0 answers

Write set of sql files to same table

I have a set of *.sql files (>2000) which contain table creation scripts per file. My goal is to write all of the sql files to one table. I want to accomplish this by creating the table before reading and writing the files. Each file I read I want…
inneb
  • 1,060
  • 1
  • 9
  • 20
0
votes
1 answer

Alembic migration server default value is recognized as null when trying to update a column

I am trying to do a migration to update the value of the column has_bubble_in_countries based on the has_bubble_v1 s column value. I created before the upgrade() the table: subscription_old_table = sa.Table( 'Subscription', …
Razvan
  • 143
  • 8
0
votes
0 answers

Alembic Revision Autogenerate Didn't Recognized The Default Value Change

I was testing Alembic. Initially I created a model something like this: from main import Base from sqlalchemy import Column, BigInteger, SmallInteger, String, Sequence, ForeignKey class Users(Base): __tablename__ = "users" id =…
0
votes
1 answer

Using an existing Enum in new Alembic migration in python

I've created Enum for one model in first migration: def upgrade() -> None: … gender_enum = postgresql.ENUM('MALE', 'FEMALE', 'OTHER', name='genderenum', create_type=False) gender_enum.create(op.get_bind(), checkfirst=True) …
aryadovoy
  • 11
  • 2
0
votes
1 answer

SQLModel error when autogenerating Alembic revisions

I have a repository.models.models file: from datetime import date from typing import Type, Optional, List from sqlmodel import SQLModel, Field, Relationship class Compra(SQLModel, table=True): com_id: Optional[int] = Field(default=None,…
André Carvalho
  • 111
  • 1
  • 11