]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Add HSTORE to render_type_w_subtype
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 26 Jan 2018 15:02:16 +0000 (10:02 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 26 Jan 2018 15:50:23 +0000 (10:50 -0500)
Fixed the autogenerate of the module prefix
when rendering the text_type parameter of
postgresql.HSTORE, in much the same way that
we do for ARRAY's type and JSON's text_type.

Change-Id: Ie8c2cdd1f4aeebcbb306c7f74168f8ac33688b1a
Fixes: #480
alembic/ddl/postgresql.py
docs/build/unreleased/480.rst [new file with mode: 0644]
tests/test_postgresql.py

index 7f582b3999257061d03e5ccfdd10909c303e00b3..a2a7dbccaa39165df71d4241474bf1464e37dc8e 100644 (file)
@@ -199,6 +199,11 @@ class PostgresqlImpl(DefaultImpl):
 
         return False
 
+    def _render_HSTORE_type(self, type_, autogen_context):
+        return render._render_type_w_subtype(
+            type_, autogen_context, 'text_type', r'(.+?\(.*text_type=)'
+        )
+
     def _render_ARRAY_type(self, type_, autogen_context):
         return render._render_type_w_subtype(
             type_, autogen_context, 'item_type', r'(.+?\()'
diff --git a/docs/build/unreleased/480.rst b/docs/build/unreleased/480.rst
new file mode 100644 (file)
index 0000000..f753e7f
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, postgresql
+    :tickets: 480
+
+    Fixed the autogenerate of the module prefix
+    when rendering the text_type parameter of
+    postgresql.HSTORE, in much the same way that
+    we do for ARRAY's type and JSON's text_type.
index ae74c0866710adaf84afa496bf5967311faff934..cbf0f2f0ffc03ba4b2da3d2eebbbc14d50a496fc 100644 (file)
@@ -32,7 +32,7 @@ from sqlalchemy.sql import false
 
 
 if util.sqla_09:
-    from sqlalchemy.dialects.postgresql import JSON, JSONB
+    from sqlalchemy.dialects.postgresql import JSON, JSONB, HSTORE
 
 
 class PostgresqlOpTest(TestBase):
@@ -693,6 +693,29 @@ unique=False, """
         assert 'from sqlalchemy.dialects import postgresql' in \
             self.autogen_context.imports
 
+    @config.requirements.sqlalchemy_110
+    def test_postgresql_hstore_subtypes(self):
+        eq_ignore_whitespace(
+            autogenerate.render._repr_type(
+                HSTORE(), self.autogen_context),
+            "postgresql.HSTORE(text_type=sa.Text())"
+        )
+
+        eq_ignore_whitespace(
+            autogenerate.render._repr_type(
+                HSTORE(text_type=String()), self.autogen_context),
+            "postgresql.HSTORE(text_type=sa.String())"
+        )
+
+        eq_ignore_whitespace(
+            autogenerate.render._repr_type(
+                HSTORE(text_type=BYTEA()), self.autogen_context),
+            "postgresql.HSTORE(text_type=postgresql.BYTEA())"
+        )
+
+        assert 'from sqlalchemy.dialects import postgresql' in \
+            self.autogen_context.imports
+
     @config.requirements.sqlalchemy_110
     def test_generic_array_type(self):