Skip to content

Commit ceffad0

Browse files
author
Aaron Browne
committed
Merge pull request #4 from chop-dbhi/issue-3
Default Oracle VARCHAR2 to CHAR 255 length
2 parents e450589 + a27cd99 commit ceffad0

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

dmsa/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
__version_info__ = {
99
'major': 0,
1010
'minor': 4,
11-
'micro': 3,
11+
'micro': 4,
1212
'releaselevel': 'alpha',
1313
'serial': serial,
1414
'sha': sha

dmsa/ddl.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sqlalchemy.schema import (CreateTable, AddConstraint, CreateIndex,
77
DropTable, DropConstraint, DropIndex)
88
from sqlalchemy.schema import (ForeignKeyConstraint, CheckConstraint,
9-
UniqueConstraint)
9+
UniqueConstraint, PrimaryKeyConstraint)
1010
from dmsa import __version__
1111
from dmsa.settings import get_url
1212
from dmsa.makers import make_model
@@ -24,7 +24,17 @@ def _compile_integer_oracle(type_, compiler, **kw):
2424
return 'NUMBER(10)'
2525

2626

27-
# Coerce String type to produce VARCHAR(255) on MySQL backend.
27+
# Coerce String type without length to produce VARCHAR2(255) on Oracle.
28+
@compiles(String, 'oracle')
29+
def _compile_string_oracle(type_, compiler, **kw):
30+
31+
if not type_.length:
32+
type_.length = 255
33+
visit_attr = 'visit_{0}'.format(type_.__visit_name__)
34+
return getattr(compiler, visit_attr)(type_, **kw)
35+
36+
37+
# Coerce String type without length to produce VARCHAR(255) on MySQL.
2838
@compiles(String, 'mysql')
2939
def _compile_string_mysql(type_, compiler, **kw):
3040

@@ -187,8 +197,9 @@ def constraint_ddl(tables, engine, drop=False):
187197
for table in tables:
188198
for constraint in table.constraints:
189199

190-
# Avoid auto-generated but empty primary key constraints.
191-
if list(constraint.columns):
200+
# Avoid duplicating primary key constraint definitions (they are
201+
# included in CREATE TABLE statements).
202+
if not isinstance(constraint, PrimaryKeyConstraint):
192203

193204
if not drop:
194205
ddl = AddConstraint(constraint)

0 commit comments

Comments
 (0)