diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-01-12 13:49:16 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-01-12 13:49:16 -0500 |
commit | b2fb21f01e725b88dfd4d6be33e3892c088001ec (patch) | |
tree | 35350d2e0638f66f6f16e4723fb1c0d8b42d7665 | |
parent | 948ffd26d4bbf8cbdde42a4618a2efa5bdddde12 (diff) | |
parent | a9c10cb7a21dd87c51c9abd886331175d0c10418 (diff) | |
download | alembic-b2fb21f01e725b88dfd4d6be33e3892c088001ec.tar.gz |
Merge https://bitbucket.org/dtheodor/alembic/branch/master into pr37
-rw-r--r-- | alembic/ddl/postgresql.py | 7 | ||||
-rw-r--r-- | tests/test_postgresql.py | 70 |
2 files changed, 72 insertions, 5 deletions
diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py index 0877c95..ac3a5f4 100644 --- a/alembic/ddl/postgresql.py +++ b/alembic/ddl/postgresql.py @@ -4,7 +4,7 @@ from .. import compat from .base import compiles, alter_table, format_table_name, RenameTable from .impl import DefaultImpl from sqlalchemy.dialects.postgresql import INTEGER, BIGINT -from sqlalchemy import text +from sqlalchemy import text, Numeric import logging log = logging.getLogger(__name__) @@ -35,7 +35,10 @@ class PostgresqlImpl(DefaultImpl): if metadata_column.server_default is not None and \ isinstance(metadata_column.server_default.arg, compat.string_types) and \ - not re.match(r"^'.+'$", rendered_metadata_default): + not re.match(r"^'.+'$", rendered_metadata_default) and \ + not isinstance(inspector_column.type, Numeric): + # don't single quote if the column type is float/numeric, + # otherwise a comparison such as SELECT 5 = '5.0' will fail rendered_metadata_default = "'%s'" % rendered_metadata_default return not self.connection.scalar( diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 908eec6..e70d05a 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -1,6 +1,6 @@ from sqlalchemy import DateTime, MetaData, Table, Column, text, Integer, \ - String, Interval, Sequence, Numeric, BigInteger + String, Interval, Sequence, Numeric, BigInteger, Float, Numeric from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.engine.reflection import Inspector from alembic.operations import Operations @@ -193,8 +193,11 @@ class PostgresqlDefaultCompareTest(TestBase): def tearDown(self): self.metadata.drop_all() - def _compare_default_roundtrip(self, type_, orig_default, alternate=None): - diff_expected = alternate is not None + def _compare_default_roundtrip( + self, type_, orig_default, alternate=None, diff_expected=None): + diff_expected = diff_expected \ + if diff_expected is not None \ + else alternate is not None if alternate is None: alternate = orig_default @@ -274,6 +277,67 @@ class PostgresqlDefaultCompareTest(TestBase): text("5"), "7" ) + def test_compare_float_str(self): + self._compare_default_roundtrip( + Float(), + "5.2", + ) + + def test_compare_float_text(self): + self._compare_default_roundtrip( + Float(), + text("5.2"), + ) + + def test_compare_float_no_diff1(self): + self._compare_default_roundtrip( + Float(), + text("5.2"), "5.2", + diff_expected=False + ) + + def test_compare_float_no_diff2(self): + self._compare_default_roundtrip( + Float(), + "5.2", text("5.2"), + diff_expected=False + ) + + def test_compare_float_no_diff3(self): + self._compare_default_roundtrip( + Float(), + text("5"), text("5.0"), + diff_expected=False + ) + + def test_compare_float_no_diff4(self): + self._compare_default_roundtrip( + Float(), + "5", "5.0", + diff_expected=False + ) + + def test_compare_float_no_diff5(self): + self._compare_default_roundtrip( + Float(), + text("5"), "5.0", + diff_expected=False + ) + + def test_compare_float_no_diff6(self): + self._compare_default_roundtrip( + Float(), + "5", text("5.0"), + diff_expected=False + ) + + def test_compare_numeric_no_diff(self): + self._compare_default_roundtrip( + Numeric(), + text("5"), "5.0", + diff_expected=False + ) + def test_compare_character_str(self): self._compare_default_roundtrip( String(), |