Giter Club home page Giter Club logo

Comments (5)

graingert avatar graingert commented on June 24, 2024

I think this is an alembic bug. @zzzeek?

from sqlalchemy-redshift.

zzzeek avatar zzzeek commented on June 24, 2024

alembic's autogenerate render does not currently render the info dictionary. SQLA itself doesn't use .info at all so is not part of what it needs to render column DDL. However, if redshift and other dialects are relying upon info for extra DDL hints, that is a supported case so alembic should support rendering .info. A fix for this though should include .info for everything, columns, tables, indexes, etc. It also should be careful not to barf if there are un-reprable things in that .info dictionary (as any application can put any kind of object in this dictionary), and perhaps even only render simple ints, strings and booleans from the dictionary. this would take place in alembic/autogenerate/render.py and of course be exercised in new unit tests in tests/test_autogen_render.py.

I would note that alembic allows user-defined rendering right now, which would allow redshift to supply a workaround if this was worth it, but it would have to define the whole Column render itself: http://alembic.zzzcomputing.com/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure.params.render_item probably not worth it.

from sqlalchemy-redshift.

acharp avatar acharp commented on June 24, 2024

@DanCardin @graingert @zzzeek
If you are still having this need (or if some people have it in the future) of auto-generating the alembic migration script for some Redshift tables with columns encoding.

Indeed it is currently not possible using Alembic but there is a workaround : write the migration script manually as following (using the example given by DanCardin)

def upgrade():
    from tables.models.example import Example
    Example.__table__.create(bind=op.get_bind())

Using this trick you avoid Alembic's code generation and use directly the sqlalchemy-redshift adaptor which itself is aware of the info={'encode': 'lzo'} field and will include it while creating the table.

from sqlalchemy-redshift.

graingert avatar graingert commented on June 24, 2024

from sqlalchemy-redshift.

crflynn avatar crflynn commented on June 24, 2024

Using @zzzeek 's suggested workaround, this renderer was sufficient for including info dicts in Redshift migrations.

def render_redshift_column(type_, col, autogen_context):
    """Render columns with info dicts for Redshift migrations."""
    if type_ == "column":
        render = "sa.Column("
        render += "'{name}'".format(name=col.name)
        render += ", sa.{coltype}".format(coltype=repr(col.type))
        render += ", nullable={null}".format(null=str(col.nullable))
        render += ", info={info})".format(info=str(col.info))
        return render
    else:
        return False

from sqlalchemy-redshift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.