6
6
from sqlalchemy .schema import (CreateTable , AddConstraint , CreateIndex ,
7
7
DropTable , DropConstraint , DropIndex )
8
8
from sqlalchemy .schema import (ForeignKeyConstraint , CheckConstraint ,
9
- UniqueConstraint )
9
+ UniqueConstraint , PrimaryKeyConstraint )
10
10
from dmsa import __version__
11
11
from dmsa .settings import get_url
12
12
from dmsa .makers import make_model
@@ -24,7 +24,17 @@ def _compile_integer_oracle(type_, compiler, **kw):
24
24
return 'NUMBER(10)'
25
25
26
26
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.
28
38
@compiles (String , 'mysql' )
29
39
def _compile_string_mysql (type_ , compiler , ** kw ):
30
40
@@ -187,8 +197,9 @@ def constraint_ddl(tables, engine, drop=False):
187
197
for table in tables :
188
198
for constraint in table .constraints :
189
199
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 ):
192
203
193
204
if not drop :
194
205
ddl = AddConstraint (constraint )
0 commit comments