Changeset 4880

Show
Ignore:
Timestamp:
07/02/08 08:16:10 (6 months ago)
Author:
chrisz
Message:

"tg-admin sql status" for SQLAlchemy wrongly complained about columns not being Unicode.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/command/sacommand.py

    r3617 r4880  
    33from turbogears.util import get_model 
    44try: 
    5     from sqlalchemy import MetaData, exceptions, Table, String 
     5    from sqlalchemy import MetaData, exceptions, Table 
     6    from sqlalchemy import String, Unicode, Text, UnicodeText 
    67    from turbogears.database import metadata, get_engine 
    78except ImportError: 
     
    9697def compare_column(pyc, dbc): 
    9798    rc = [] 
     99    pyt, dbt = pyc.type, dbc.type 
     100 
     101    # Table reflection cannot recognize Unicode, so check only for String 
     102    if isinstance(pyt, Unicode): 
     103        pyt = String(pyt.length) 
     104    elif isinstance(pyt, UnicodeText): 
     105        pyt = Text(pyt.length) 
     106 
    98107    # Check type 
    99     if not isinstance(dbc.type, pyc.type.__class__): 
    100         rc.append('Change type to ' + pyc.type.__class__.__name__) 
     108    if not isinstance(dbt, pyt.__class__): 
     109        rc.append('Change type to ' + pyt.__class__.__name__) 
    101110 
    102111    # Check length (for strings) 
    103112    else: 
    104         if isinstance(pyc.type, String): 
    105             if pyc.type.length != dbc.type.length: 
    106                 rc.append('Change length to ' + str(pyc.type.length)) 
     113        if isinstance(pyt, String): 
     114            if pyt.length != dbt.length: 
     115                rc.append('Change length to ' + str(pyt.length)) 
    107116 
    108117    # Check primary key 
     
    110119        rc.append(pyc.primary_key and 'Make primary key' or 'Remove primary key') 
    111120 
    112     # Check foreign keys 
    113     # TBD 
     121    # TODO: Check foreign keys 
    114122 
    115     # Check default - disabled for now (didn't work on SQLite) 
    116     #if dbc.default != pyc.default: 
    117     #    rc.append('Change default to ' + str(pyc.default.arg)) 
     123    # Check default 
     124    if dbc.default is not None and dbc.default != pyc.default: 
     125        rc.append('Change default to ' + str(pyc.default.arg)) 
    118126 
    119     # Check index - disabled for now (didn't work on SQLite) 
    120     #if dbc.index != pyc.index: 
    121     #    rc.append(pyc.index and 'Add index' or 'Remove index') 
     127    # Check index 
     128    if dbc.index is not None and dbc.index != pyc.index: 
     129        rc.append(pyc.index and 'Add index' or 'Remove index') 
    122130 
    123131    return rc