.. changelog::
:version: 1.1.0b1
+ .. change::
+ :tags: bug, postgresql
+ :tickets: 2729
+
+ 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".
+
+ .. seealso::
+
+ :ref:`change_2729`
+
.. change::
:tags: bug, sql
:tickets: 3531
:ticket:`3514`
+.. _change_2729:
+
+ARRAY with ENUM will now emit CREATE TYPE for the ENUM
+------------------------------------------------------
+
+A table definition like the following will now emit CREATE TYPE
+as expected::
+
+ enum = Enum(
+ 'manager', 'place_admin', 'carwash_admin',
+ 'parking_admin', 'service_admin', 'tire_admin',
+ 'mechanic', 'carwasher', 'tire_mechanic', name="work_place_roles")
+
+ class WorkPlacement(Base):
+ __tablename__ = 'work_placement'
+ id = Column(Integer, primary_key=True)
+ roles = Column(ARRAY(enum))
+
+
+ e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)
+ Base.metadata.create_all(e)
+
+emits::
+
+ CREATE TYPE work_place_roles AS ENUM (
+ 'manager', 'place_admin', 'carwash_admin', 'parking_admin',
+ 'service_admin', 'tire_admin', 'mechanic', 'carwasher',
+ 'tire_mechanic')
+
+ CREATE TABLE work_placement (
+ id SERIAL NOT NULL,
+ roles work_place_roles[],
+ PRIMARY KEY (id)
+ )
+
+
+:ticket:`2729`
+
Dialect Improvements and Changes - MySQL
=============================================
from .base import ischema_names
from ...sql import expression, operators
+from ...sql.base import SchemaEventTarget
from ... import types as sqltypes
try:
OVERLAP = operators.custom_op("&&", precedence=5)
-class ARRAY(sqltypes.Array):
+class ARRAY(SchemaEventTarget, sqltypes.Array):
"""Postgresql ARRAY type.
def compare_values(self, x, y):
return x == y
+ def _set_parent(self, column):
+ """Support SchemaEentTarget"""
+
+ if isinstance(self.item_type, SchemaEventTarget):
+ self.item_type._set_parent(column)
+
+ def _set_parent_with_dispatch(self, parent):
+ """Support SchemaEentTarget"""
+
+ if isinstance(self.item_type, SchemaEventTarget):
+ self.item_type._set_parent_with_dispatch(parent)
+
def _proc_array(self, arr, itemproc, dim, collection):
if dim is None:
arr = list(arr)
set([('1', '2', '3'), ('4', '5', '6'), (('4', '5'), ('6', '7'))])
)
+ def test_array_plus_native_enum_create(self):
+ m = MetaData()
+ t = Table(
+ 't', m,
+ Column(
+ 'data_1',
+ postgresql.ARRAY(
+ postgresql.ENUM('a', 'b', 'c', name='my_enum_1')
+ )
+ ),
+ Column(
+ 'data_2',
+ postgresql.ARRAY(
+ types.Enum('a', 'b', 'c', name='my_enum_2')
+ )
+ )
+ )
+
+ t.create(testing.db)
+ eq_(
+ set(e['name'] for e in inspect(testing.db).get_enums()),
+ set(['my_enum_1', 'my_enum_2'])
+ )
+ t.drop(testing.db)
+ eq_(inspect(testing.db).get_enums(), [])
+
class HashableFlagORMTest(fixtures.TestBase):
"""test the various 'collection' types that they flip the 'hashable' flag