From: Mike Bayer Date: Fri, 26 Jan 2018 15:02:16 +0000 (-0500) Subject: Add HSTORE to render_type_w_subtype X-Git-Tag: rel_0_9_8~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4755d5c50e8a415edc4f288b3da5b77ac803dd0;p=thirdparty%2Fsqlalchemy%2Falembic.git Add HSTORE to render_type_w_subtype 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 --- diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py index 7f582b39..a2a7dbcc 100644 --- a/alembic/ddl/postgresql.py +++ b/alembic/ddl/postgresql.py @@ -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 index 00000000..f753e7fe --- /dev/null +++ b/docs/build/unreleased/480.rst @@ -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. diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index ae74c086..cbf0f2f0 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -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):