metadata.create_all do not create Enum in postgre ARRAY
Issue #2729
resolved
metadata.create_all do not create work_place_roles if Enum in sqlalchemy.dialects.postgresql.ARRAY
class WorkPlacement(Base):
__tablename__ = 'work_placement'
roles = Column(ARRAY(Enum('manager', 'place_admin', 'carwash_admin',
'parking_admin', 'service_admin', 'tire_admin',
'mechanic', 'carwasher', 'tire_mechanic', name="work_place_roles")))
i need do so:
class WorkPlacement(Base):
__tablename__ = 'work_placement'
tmp_role = Column(Enum('manager', 'place_admin', 'carwash_admin',
'parking_admin', 'service_admin', 'tire_admin',
'mechanic', 'carwasher', 'tire_mechanic', name="work_place_roles"))
roles = Column(ARRAY(Enum(name="work_place_roles")))
Comments (9)
-
repo owner -
Account Deleted thx for elegant solution -))
-
repo owner - changed milestone to 0.9.xx
-
repo owner - changed milestone to 1.0.xx
-
repo owner Issue
#3437was marked as a duplicate of this issue. -
repo owner - edited description
- changed milestone to 1.x.xx
-
repo owner part of the effort here though we still need to handle result rows
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 0c48ea8..1d2da8b 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -1496,7 +1496,7 @@ class Interval(_DateAffinity, TypeDecorator): return self.impl.coerce_compared_value(op, value) -class Array(Indexable, Concatenable, TypeEngine): +class Array(SchemaEventTarget, Indexable, Concatenable, TypeEngine): """Represent a SQL Array type. .. note:: This type serves as the basis for all ARRAY operations. @@ -1735,6 +1735,19 @@ class Array(Indexable, Concatenable, TypeEngine): def compare_values(self, x, y): return x == y + def _set_parent(self, column): + """Support SchemaEventTarget""" + + if isinstance(self.item_type, SchemaEventTarget): + self.item_type._set_parent(column) + + def _set_parent_with_dispatch(self, parent): + """Support SchemaEventTarget""" + + if isinstance(self.item_type, SchemaEventTarget): + self.item_type._set_parent_with_dispatch(parent) + + class REAL(Float): diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py index f5ab1a8..2397efb 100644 --- a/lib/sqlalchemy/sql/type_api.py +++ b/lib/sqlalchemy/sql/type_api.py @@ -774,13 +774,13 @@ class TypeDecorator(SchemaEventTarget, TypeEngine): return self.impl._type_affinity def _set_parent(self, column): - """Support SchemaEentTarget""" + """Support SchemaEventTarget""" if isinstance(self.impl, SchemaEventTarget): self.impl._set_parent(column) def _set_parent_with_dispatch(self, parent): - """Support SchemaEentTarget""" + """Support SchemaEventTarget""" if isinstance(self.impl, SchemaEventTarget): self.impl._set_parent_with_dispatch(parent)
-
repo owner - changed status to resolved
- The use of a :class:
.postgresql.ARRAY
object that refers to a :class:.types.Enum
or :class:.postgresql.ENUM
subtype will now emit the expected "CREATE TYPE" and "DROP TYPE" DDL when the type is used within a "CREATE TABLE" or "DROP TABLE". fixes#2729
→ <<cset 371f1a82c598>>
-
repo owner - changed milestone to 1.1
- Log in to comment
good catch. Here is a better workaround for now: