Thanks for figuring this out.

On Monday, February 17, 2020 at 3:05:30 PM UTC-5, Mike Bayer wrote:
>
> Here is your SQL output, enum is created correctly:
>
> CREATE TYPE test_schema.enum1 AS ENUM ('One', 'Two')
>
>
> however table does not refer to the correct enum:
>
> CREATE TABLE test_schema.table1 (
> id SERIAL NOT NULL,
> type1 enum1,
> PRIMARY KEY (id)
> )
>
>
> this is SQLAlchemy bug 
> https://github.com/sqlalchemy/sqlalchemy/issues/5158 will be fixed in 
> 1.3.14
>
>
> On Mon, Feb 17, 2020, at 2:51 PM, Mike Bayer wrote:
>
> mm nope we have plenty of tests for this here:
>
>
> https://github.com/sqlalchemy/sqlalchemy/blob/master/test/dialect/postgresql/test_compiler.py#L223
>
>
>
> On Mon, Feb 17, 2020, at 2:49 PM, Mike Bayer wrote:
>
> it's possible also that PG Enum CREATE TYPE doesn't work with 
> schema_translate_map, would need to evaluate that on the SQLAlchemy side.
>
> On Mon, Feb 17, 2020, at 2:45 PM, Mike Bayer wrote:
>
> schema_translate_map is not yet supported with all Alembic ops:
>
> https://github.com/sqlalchemy/alembic/issues/555
>
> you will need to fill in the "schema" parameter explicitly when you call 
> upon op.create_table()
>
>
>
> On Mon, Feb 17, 2020, at 12:47 PM, Brian Hill wrote:
>
> I'm having trouble using enums in conjunction with schema_translate_map 
> for postgres migrations.
>
> My model, single table, single enum.
>
> import enum
> from sqlalchemy import MetaData, Enum, Column, Integer
> from sqlalchemy.ext.declarative import declarative_base
>
>
> metadata = MetaData()
> Base = declarative_base(metadata=metadata)
>
>
>
>
> class Enum1(enum.Enum):
>     One = 1
>     Two = 2
>
>
>
>
> class Table1(Base):
>     __tablename__ = 'table1'
>     id = Column(Integer, primary_key=True)
>     type1 = Column(Enum(Enum1))
>
> Version file.
>
>
> """initial revision
>
>
> Revision ID: 844dd0269c1b
> Revises: 
> Create Date: 2020-02-17 12:23:31.125308
>
>
> """
> from alembic import op
> import sqlalchemy as sa
>
>
>
>
> # revision identifiers, used by Alembic.
> revision = '844dd0269c1b'
> down_revision = None
> branch_labels = None
> depends_on = None
>
>
>
>
> def upgrade():
>     # ### commands auto generated by Alembic - please adjust! ###
>     op.create_table('table1',
>     sa.Column('id', sa.Integer(), nullable=False),
>     sa.Column('type1', sa.Enum('One', 'Two', name='enum1'), nullable=True
> ),
>     sa.PrimaryKeyConstraint('id')
>     )
>     # ### end Alembic commands ###
>
>
>
>
> def downgrade():
>     # ### commands auto generated by Alembic - please adjust! ###
>     op.drop_table('table1')
>     # ### end Alembic commands ###
>
>
> Run migration funtion from env.py (creating foo schema):
>
>
>
> def run_migrations_online():
>     connectable = engine_from_config(
>         config.get_section(config.config_ini_section),
>         prefix="sqlalchemy.",
>         poolclass=pool.NullPool,
>     )
>
>
>     with connectable.connect() as connection:
>
>
>         # use different schema
>         connection.execute(f'create schema if not exists foo')
>         connection = connection.execution_options(
>             schema_translate_map={None: 'foo'}
>         )
>
>
>         context.configure(
>             connection=connection,
>             target_metadata=target_metadata,
>             include_schema=True,
>         )
>
>
>         with context.begin_transaction():
>             context.run_migrations()
>
>
> I get the following error when i run *alembic upgrade head*:
>
>
> sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedObject) type 
> "enum1" does not exist
> LINE 4:  type1 enum1, 
>                ^
>
>
> [SQL: 
> CREATE TABLE foo.table1 (
>         id SERIAL NOT NULL, 
>         type1 enum1, 
>         PRIMARY KEY (id)
> )
>
>
> ]
> (Background on this error at: http://sqlalche.me/e/f405)
>
> It works when I comment out schema_translate_map.
>
> I feel like I'm missing something fundamental about using 
> schema_translate_map for multi-tenant/schema.
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy-alembic" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy-alembic+unsubscr...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy-alembic/f8513719-4dd0-4bb2-b769-ff874e2017f2%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy-alembic/f8513719-4dd0-4bb2-b769-ff874e2017f2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy-alembic" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy-alembic+unsubscr...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy-alembic/1ffea337-b61f-4712-9b90-c73056895e45%40www.fastmail.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy-alembic/1ffea337-b61f-4712-9b90-c73056895e45%40www.fastmail.com?utm_medium=email&utm_source=footer>
> .
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy-alembic" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy-alembic+unsubscr...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy-alembic/078033be-3f96-4ebe-8be7-b23e3842c312%40www.fastmail.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy-alembic/078033be-3f96-4ebe-8be7-b23e3842c312%40www.fastmail.com?utm_medium=email&utm_source=footer>
> .
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy-alembic" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy-alembic+unsubscr...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy-alembic/5be055e0-1c86-43d8-b879-45423c6641c5%40www.fastmail.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy-alembic/5be055e0-1c86-43d8-b879-45423c6641c5%40www.fastmail.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy-alembic/89f61ee6-269b-4d35-9327-d8471e9c1dd3%40googlegroups.com.

Reply via email to