alembic

Creating seed data in a flask-migrate or alembic migration

╄→尐↘猪︶ㄣ 提交于 2019-11-29 19:26:17
How can I insert some seed data in my first migration? If the migration is not the best place for this, then what is the best practice? """empty message Revision ID: 384cfaaaa0be Revises: None Create Date: 2013-10-11 16:36:34.696069 """ # revision identifiers, used by Alembic. revision = '384cfaaaa0be' down_revision = None from alembic import op import sqlalchemy as sa def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.create_table('list_type', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=80), nullable=False), sa

How to represent a custom PostgreSQL domain in SQLAlchemy?

这一生的挚爱 提交于 2019-11-29 14:22:30
问题 I'm beginning to incorporate Alembic into my project which already uses SQLAlchemy table definitions. At present my DB schema is managed external to my application, and I want to bring the entire schema into my table definitions file. In PostgreSQL I use a custom domain for storing email addresses. The PostgreSQL DDL is: CREATE DOMAIN email_address TEXT CHECK (value ~ '.+@.+') How do I represent the creation of this domain, and the usage of it as a column data type, in SQLAlchemy? 回答1: This

Alembic support for multiple Postgres schemas

旧城冷巷雨未停 提交于 2019-11-29 12:04:55
问题 How can I use Alembic's --autogenerate to migrate multiple Postgres schemas that are not hard-coded in the SQL Alchemy model? (mirror question of SQLAlchemy support of Postgres Schemas, but for Alembic). In particular, we use Postgres schemas to seperate different clients that share the same set of tables. Moreover, there is a schema with shared stuff among clients. The SQL Alchemy model has no knowledge of schemas, the schema is set at run-time using session.execute("SET search_path TO

Run alembic upgrade migrations in a transaction

家住魔仙堡 提交于 2019-11-29 09:57:52
Does alembic upgrade head run inside a transaction so that all database alterations succeed, or fail? If not, why was it designed this way? My understanding is alembic runs inside a transaction for databases that support it, like Postgres. If you're on a database that does not support this ( cough MySQL cough ), you can't use this functionality. Alessandro Cosentino That's something you can decide within the env.py , which is where you customize the behaviour of the migrations to suit your setup. You can see how to make sure your upgrades happen in a transaction from the template provided as

sqlalchemy: alembic bulk insert fails: 'str' object has no attribute '_autoincrement_column'

旧城冷巷雨未停 提交于 2019-11-29 09:56:24
My model looks like class Category(UserMixin, db.Model): __tablename__ = 'categories' uuid = Column('uuid', GUID(), default=uuid.uuid4, primary_key=True, unique=True) name = Column('name', String, nullable=False) parent = Column('parent', String, nullable=False) created_on = Column('created_on', sa.types.DateTime(timezone=True), default=datetime.utcnow()) __table_args__ = (UniqueConstraint('name', 'parent'),) def __init__(self, name, parent): self.name = name self.parent = parent def __repr__(self): return '<Category:%s:%s:%s>' % ( self.uuid, self.name, self.category_type) where GUID is custom

Alembic: alembic revision says Import Error

此生再无相见时 提交于 2019-11-29 05:33:07
问题 I am trying to integrate my Flask project with Alembic My application structure looks like project/ configuration/ __init__.py dev.py test.py core/ # all source code db/ migrations/ __init__.py alembic.ini env.py versions/ When I try to run the following from my db directory, I see File "migration/env.py", line 55, in run_migrations_online from configuration import app, db ImportError: No module named configuration I tried the solution mentioned in Request a simple alembic working example for

Check if a table column exists in the database using SQLAlchemy and Alembic

瘦欲@ 提交于 2019-11-29 02:39:08
I'm using Alembic as migration tool and I'm launching the following pseudo script on an already updated database (no revision entries for Alembic, the database schema is just up to date). revision = '1067fd2d11c8' down_revision = None from alembic import op import sqlalchemy as sa def upgrade(): op.add_column('box', sa.Column('has_data', sa.Boolean, server_default='0')) def downgrade(): pass It gives me the following error only with PostgreSQL behind (it's all good with MySQL): INFO [alembic.migration] Context impl PostgresqlImpl. INFO [alembic.migration] Will assume transactional DDL. INFO

Alembic --autogenerate producing empty migration

杀马特。学长 韩版系。学妹 提交于 2019-11-29 01:24:22
I am trying to use Alembic for the first time and want to use --autogenerate feature described here My project structure looks like project/ configuration/ __init__.py dev.py test.py core/ app/ models/ __init__.py user.py db/ alembic/ versions/ env.py alembic.ini I am using Flask and SQLAlchemy and their Flask-SQLAlchemy extension. my model User looks like class User(UserMixin, db.Model): __tablename__ = 'users' # noinspection PyShadowingBuiltins uuid = Column('uuid', GUID(), default=uuid.uuid4, primary_key=True, unique=True) email = Column('email', String, nullable=False, unique=True)

Modify data as part of an alembic upgrade

南笙酒味 提交于 2019-11-28 21:16:55
I would like to modify some database data as part of an alembic upgrade. I thought I could just add any code in the upgrade of my migration, but the following fails: def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.add_column('smsdelivery', sa.Column('sms_message_part_id', sa.Integer(), sa.ForeignKey('smsmessagepart.id'), nullable=True)) ### end Alembic commands ### from volunteer.models import DBSession, SmsDelivery, SmsMessagePart for sms_delivery in DBSession.query(SmsDelivery).all(): message_part = DBSession.query(SmsMessagePart).filter(SmsMessagePart.message

Is it possible to store the alembic connect string outside of alembic.ini?

半世苍凉 提交于 2019-11-28 17:20:58
问题 I'm using Alembic with SQL Alchemy. With SQL Alchemy, I tend to follow a pattern where I don't store the connect string with the versioned code. Instead I have file secret.py that contains any confidential information. I throw this filename in my .gitignore so it doesn't end up on GitHub. This pattern works fine, but now I'm getting into using Alembic for migrations. It appears that I cannot hide the connect string. Instead in alembic.ini, you place the connect string as a configuration