Skip to content

Commit

Permalink
handle oracle type differences
Browse files Browse the repository at this point in the history
  • Loading branch information
pbecotte committed Nov 22, 2019
1 parent 17a39d6 commit 2edf464
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
20 changes: 19 additions & 1 deletion alembic/ddl/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OracleImpl(DefaultImpl):
command_terminator = ""
type_synonyms = DefaultImpl.type_synonyms + [
{"VARCHAR", "VARCHAR2"},
{"BIGINT", "NUMBER"},
{"BIGINT", "INTEGER", "SMALLINT", "DECIMAL", "NUMERIC"},
]

def __init__(self, *arg, **kw):
Expand All @@ -42,6 +42,24 @@ def emit_begin(self):
def emit_commit(self):
self._exec("COMMIT")

@staticmethod
def _column_keywords_match(inspector_match, metadata_match):
if DefaultImpl._column_keywords_match(inspector_match, metadata_match):
return True

# We don't want to report a change on integers not matching the default
# scale. number(19) should equal number(19,0) but not number(19,2)
if inspector_match.group(1) != "number":
return False

inspector_keywords = inspector_match.group(2).strip("()").split(",")
metadata_keywords = metadata_match.group(2).strip("()").split(",")
return (
inspector_keywords[0] == metadata_keywords[0]
and inspector_keywords[1].strip() == "0"
and len(metadata_keywords) == 1
)


@compiles(AddColumn, "oracle")
def visit_add_column(element, compiler, **kw):
Expand Down
27 changes: 12 additions & 15 deletions tests/test_autogen_diffs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys

from sqlalchemy import BOOLEAN
from sqlalchemy import BIGINT
from sqlalchemy import Boolean
from sqlalchemy import BigInteger
from sqlalchemy import CHAR
from sqlalchemy import CheckConstraint
Expand Down Expand Up @@ -700,7 +699,7 @@ def test_numeric_noprecision(self):
def test_integer(self):
t1 = Integer()
t2 = SmallInteger()
t3 = BIGINT()
t3 = BigInteger()
t4 = String()
t5 = INTEGER()
t6 = BigInteger()
Expand All @@ -724,21 +723,20 @@ def _get_db_schema(cls):
m,
Column("id", INTEGER(), primary_key=True),
Column("char", CHAR()),
Column("varchar", VARCHAR()),
Column("varchar", VARCHAR(32)),
Column("txt", Text()),
Column("float", FLOAT()),
Column("number", Numeric()),
Column("dec", DECIMAL()),
Column("timestamp", TIMESTAMP()),
Column("datetime", DateTime()),
Column("flag", BOOLEAN()),
Column("bigint", BIGINT()),
Column("flag", Boolean()),
Column("bigint", BigInteger()),
Column("smallint", SmallInteger()),
Column("date", DATE()),
Column("time", TIME()),
Column("string", String()),
Column("string", String(32)),
Column("largebin", LargeBinary()),
Column("unicode", Unicode()),
Column("unicode", Unicode(32)),
Column("enum", Enum("one", "two", "three")),
)
return m
Expand All @@ -751,21 +749,20 @@ def _get_model_schema(cls):
m,
Column("id", INTEGER(), primary_key=True),
Column("char", CHAR()),
Column("varchar", VARCHAR()),
Column("varchar", VARCHAR(32)),
Column("txt", Text()),
Column("float", FLOAT()),
Column("number", Numeric()),
Column("dec", DECIMAL()),
Column("timestamp", TIMESTAMP()),
Column("datetime", DateTime()),
Column("flag", BOOLEAN()),
Column("bigint", BIGINT()),
Column("flag", Boolean()),
Column("bigint", BigInteger()),
Column("smallint", SmallInteger()),
Column("date", DATE()),
Column("time", TIME()),
Column("string", String()),
Column("string", String(32)),
Column("largebin", LargeBinary()),
Column("unicode", Unicode()),
Column("unicode", Unicode(32)),
Column("enum", Enum("one", "two", "three")),
)
return m
Expand Down

0 comments on commit 2edf464

Please sign in to comment.